-
Notifications
You must be signed in to change notification settings - Fork 1
/
kill-at-idle.js
34 lines (31 loc) · 939 Bytes
/
kill-at-idle.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
function absolve(elt) {
elt.oncontextmenu = null;
elt.onselectstart = null;
elt.onmousedown = null;
elt.oncut = null;
elt.oncopy = null;
elt.onpaste = null;
if (elt.nodeName === 'A' && window.location === top.location)
elt.removeAttribute('target');
}
function absolveAll(elt) {
absolve(elt);
var descendents = elt.getElementsByTagName('*');
for (var i = 0; i < descendents.length; i++)
absolve(descendents[i]);
}
function absolveDocument() {
absolve(window);
absolve(document);
absolveAll(document.documentElement);
document.addEventListener('DOMNodeInserted', function(ev) {
if (ev.srcElement.nodeType === 1)
absolveAll(ev.srcElement);
});
}
if (document.documentElement instanceof HTMLHtmlElement) {
chrome.extension.sendRequest({url: location.href}, function(enabled) {
if (enabled)
absolveDocument();
});
}