mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 07:27:22 -06:00
WebUI: switch to lightweight clipboard library
The new library [1] will opt to the modern Clipboard API [2] when it is available. It will fallback to the old method otherwise. The new library is also smaller and without any bloat. Note that the line `module.exports` is required to be removed/commented out. This is the only patch required. [1] https://github.com/feross/clipboard-copy [2] https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API PR #22792.
This commit is contained in:
@@ -1785,26 +1785,29 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||
}
|
||||
});
|
||||
|
||||
new ClipboardJS(".copyToClipboard", {
|
||||
text: (trigger) => {
|
||||
switch (trigger.id) {
|
||||
case "copyName":
|
||||
return copyNameFN();
|
||||
case "copyInfohash1":
|
||||
return copyInfohashFN(1);
|
||||
case "copyInfohash2":
|
||||
return copyInfohashFN(2);
|
||||
case "copyMagnetLink":
|
||||
return copyMagnetLinkFN();
|
||||
case "copyID":
|
||||
return copyIdFN();
|
||||
case "copyComment":
|
||||
return copyCommentFN();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
for (const element of document.getElementsByClassName("copyToClipboard")) {
|
||||
const setupClickEvent = (textFunc) => element.addEventListener("click", async (event) => await clipboardCopy(textFunc()));
|
||||
switch (element.id) {
|
||||
case "copyName":
|
||||
setupClickEvent(copyNameFN);
|
||||
break;
|
||||
case "copyInfohash1":
|
||||
setupClickEvent(() => copyInfohashFN(1));
|
||||
break;
|
||||
case "copyInfohash2":
|
||||
setupClickEvent(() => copyInfohashFN(2));
|
||||
break;
|
||||
case "copyMagnetLink":
|
||||
setupClickEvent(copyMagnetLinkFN);
|
||||
break;
|
||||
case "copyID":
|
||||
setupClickEvent(copyIdFN);
|
||||
break;
|
||||
case "copyComment":
|
||||
setupClickEvent(copyCommentFN);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addEventListener("visibilitychange", (event) => {
|
||||
if (document.hidden)
|
||||
|
||||
Reference in New Issue
Block a user