forked from kamilakis/qbitload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleftclicksend.js
More file actions
62 lines (56 loc) · 1.86 KB
/
leftclicksend.js
File metadata and controls
62 lines (56 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(async ()=> {
const { leftClickSend } = await browser.storage.local.get('leftClickSend');
if (leftClickSend) {
let lastClickX = 0;
let lastClickY = 0;
document.addEventListener("click", (e) => {
lastClickX = e.clientX;
lastClickY = e.clientY;
const magnet = e.target.closest('a[href^="magnet:"]');
if (magnet) {
e.preventDefault();
e.stopPropagation();
browser.storage.local.set({ magnetLink: magnet.href });
}
});
function showToast(message, x, y, bgColor = "#222") {
const existing = document.getElementById("qb-toast");
if (existing) existing.remove();
const toast = document.createElement("div");
toast.id = "qb-toast";
toast.textContent = message;
Object.assign(toast.style, {
position: "fixed",
left: `${x + 15}px`,
top: `${y + 15}px`,
backgroundColor: bgColor,
color: "#fff",
padding: "6px 10px",
borderRadius: "5px",
fontSize: "12px",
zIndex: 9999,
pointerEvents: "none",
opacity: 0,
transition: "opacity 0.3s ease",
boxShadow: "0 2px 8px rgba(0,0,0,0.3)",
userSelect: "none",
});
document.body.appendChild(toast);
getComputedStyle(toast).opacity;
toast.style.opacity = 1;
setTimeout(() => {
toast.style.opacity = 0;
setTimeout(() => toast.remove(), 300);
}, 1000);
}
browser.runtime.onMessage.addListener((message) => {
if (message.action === "torrentAdded") {
if (message.success) {
showToast("✓ Sent to qBittorrent", lastClickX, lastClickY, "#222");
} else {
showToast("✗ Failed: " + (message.error || "Unknown error"), lastClickX, lastClickY, "#c62828");
}
}
});
}
})();