-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclipboard.js
More file actions
31 lines (24 loc) · 870 Bytes
/
clipboard.js
File metadata and controls
31 lines (24 loc) · 870 Bytes
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
window.userscript_util = window.userscript_util || {};
window.userscript_util.clipboard = {};
window.userscript_util.clipboard.bindClipboardAction = (sel, index) => {
if (!sel) {
if( index !== undefined ) {
sel = `#copy-button${index}`;
}else{
sel = `#copy-button`;
}
}
const clipboard = new Clipboard(sel);
clipboard.on("success", function (e) {
// console.info("Action:", e.action);
// console.info("Text:", e.text);
// console.info("Trigger:", e.trigger);
e.clearSelection();
document.querySelector(sel).style.backgroundColor = "#d9534f";
document.querySelector(sel).style.borderColor = "#d43f3a";
});
clipboard.on("error", function (e) {
console.error("Action:", e.action);
console.error("Trigger:", e.trigger);
});
};