-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathsimpleAllowCopy.js
139 lines (130 loc) · 3.53 KB
/
simpleAllowCopy.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { BADGES } from "./helpers/badge.js";
export default {
icon: `<i class="fa-regular fa-copy fa-lg"></i>`,
name: {
en: "Enable/Disable allow copy",
vi: "Bật/Tắt cho phép sao chép",
},
description: {
en: `Allow Copy on every websites<br/>
<p style="color:yellow">NOTES:</p>
<ul>
<li>Need to enable autorun first</li>
<li>Click this button to TURN ON cheat to allow copy/right-click for current website.</li>
<li>Click again to TURN OFF.</li>
</ul>`,
vi: `Cho phép sao chép trong mọi trang web<br/>
<p style="color:yellow">CHÚ Ý:</p>
<ul>
<li>Cần bật tự động chạy trước</li>
<li>Khi vào trang web muốn copy/chuột phải, click 1 lần chức năng để BẬT.</li>
<li>Khi copy/chuột phải xong có thể click lần nữa để TẮT.</li>
</ul>`,
},
badges: [BADGES.hot],
changeLogs: {
"2024-07-24": "hotfix",
},
contentScript: {
onDocumentStart_: function () {
unlocker.init();
window.ufs_simpleAllowCopy = true;
},
onClick_: function () {
let isMainFrame = window === window.top;
if (!window.ufs_simpleAllowCopy) {
if (isMainFrame)
alert("Vui lòng mở chức năng trước, rồi tải lại trang web.");
} else if (unlocker.enabled()) {
unlocker.disable();
if (isMainFrame)
alert("Đã TẮT cho phép sao chép.\nSimple allow copy DISABLED.");
} else {
unlocker.enable();
if (isMainFrame)
alert("Đã BẬT cho phép sao chép.\nSimple allow copy ENABLED.");
}
},
},
};
// modified from https://chrome.google.com/webstore/detail/simple-allow-copy/aefehdhdciieocakfobpaaolhipkcpgc
const unlocker = (() => {
const logger = {
log(...args) {
return console.log(...args);
},
error(...args) {
return console.error(...args);
},
};
let enabled = false;
let inited = false;
function init() {
if (inited) return;
inited = true;
const copyEvents = [
"copy",
"cut",
"contextmenu",
"selectstart",
"mousedown",
"mouseup",
"mousemove",
"keydown",
"keypress",
"keyup",
];
const rejectOtherHandlers = (e) => {
if (enabled) {
e.stopPropagation();
if (e.stopImmediatePropagation) e.stopImmediatePropagation();
}
};
copyEvents.forEach((evt) => {
document.documentElement.addEventListener(evt, rejectOtherHandlers, {
capture: true,
});
});
}
const CSS_ELEM_ID = "allow-copy_style";
const addCss = () => {
try {
const doc = window.document;
removeCss();
const style = doc.createElement("STYLE");
style.id = CSS_ELEM_ID;
style.innerHTML =
`html, body, *, *::before, *::after, html body * {\n` +
" -webkit-user-select: initial !important; \n" +
" user-select: initial !important; \n" +
"} ";
doc.documentElement.append(style);
} catch (error) {
logger.error("[simple allow copy] cannot add css", error);
}
};
const removeCss = () => {
try {
const style = window.document.getElementById(CSS_ELEM_ID);
if (style) {
style.remove();
}
} catch (error) {
logger.error("[simple allow copy] cannot remove css", error);
}
};
const enable = () => {
enabled = true;
addCss();
};
const disable = () => {
enabled = false;
removeCss();
};
return {
init,
enable,
disable,
enabled: () => enabled,
};
})();