-
Notifications
You must be signed in to change notification settings - Fork 0
/
nope-bookmarklet.js
92 lines (80 loc) · 4.41 KB
/
nope-bookmarklet.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
// add style
(function() {
var nopeClass = 'nope-nope-nope';
var wrapID = nopeClass + '-wrap';
var nopeHelpClass = nopeClass + '-help';
var nopeWrap = document.getElementById(wrapID);
var nopeClickHandler = function (e) {
var nope2 = document.createElement('div');
nope2.className = nopeClass;
nope2.innerText = 'NOPE';
nope2.setAttribute('style', '\
top: ' + e.pageY + 'px;\
left: ' + e.pageX + 'px;\
-webkit-transform: translate3d(-50%, -50%, 0) rotate(' + Math.floor((Math.random() * 60) - 30) + 'deg);\
');
var b = document.getElementById(wrapID);
b.appendChild(nope2);
// console.log(e.pageX, e.pageY);
return false;
};
if (!nopeWrap) {
nopeWrap = document.createElement('div');
nopeWrap.id = wrapID;
nopeWrap.innerHTML = '<div class="' + nopeHelpClass + '">[ESC] to Stop</div>';
var b = document.getElementsByTagName('body')[0];
b.appendChild(nopeWrap);
var bodyStyle = window.getComputedStyle(b, null);
var bodyPosition = bodyStyle.getPropertyValue('position');
if (['fixed', 'absolute', 'relative'].indexOf(bodyPosition) < 0) {
b.style.setProperty('position', 'relative');
}
var style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.innerText = [
,'#' + wrapID + '{'
,' cursor: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAhCAYAAADH97ugAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzV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ooDKSfaSkX9BH6iOYZU4ks45AP4hN7oBQmOEc0JJacGpQqEilaqKkWFAsHOTPRsuQ5eG4es9LTW7njezu6b2ZV0XQ94aCHCKrCEsQlhCEzdHMgeSNjmCWGL8IygYHxA+EXoEX4Tru9DFCRsEHYILwkRW0QxEH8D2VTkSNTChOeEeLvd3s5kMvuSJB0y+JvHaO4FQYWtc+MzEiBKeE/4WCgUvrC5Fblc7ojm9ggfCI9FvkQRSYQVbFe42Wy+tht0Op04Ill3iyjoojTe//VGo6H2+/1tuwGP0fY9gp2Cf+Ym4kNfIyzXarW4k1GlUnmFyNcsQpmLSIYDudVqORJhTrbl2Nyqk4CAhzQIimxFRBqSUItEIkMXIg3Q/RBx8o2YjGTcdTLKZrNd2I5F1UFEdA2iqaqqjhHFYrEhbP+JKoMkKKq83yzpN9xzNXBI+E/UXRKOCV1s4VwR6YjoL684lUqd2Q0o0ktEM0BEml/VTUA0TiaTd84pkUh0YTNAH/BLNAbRhIpozz6ZTqd7sLk3kbnafD5/JyKo0YxamJAuN6xQEF6F4CUiHSu9va6tgoAQphDBSERi1DNe9bJRQGeQb2D8v6YoyhALCeOKX5pRLQzVjmQ42cRNGZ1R6o37JmRVHr5DuM5XZpwRR/uHcEH4wWf0lD528S5QnLazWCy+q1arb61jTFav1z8L6h8LqU04YaItHHbCKfv9NvJ9wBcx4atR3kMehOGnmb4fwrkveS+USINCtAfwb/qWofUrlme5XD5cMNEYvm/ziCX4E6/NQKlUOlgEAxZ9Bd8DlncQz94M3terCzg7DWXrO+GUyWQMcgaf4xKLih6CHptRFTroNaN6u9U7PxGZdY5z90aAAQC2iSnW9m4k2AAAAABJRU5ErkJggg==), crosshair;'
,' z-index:9999;'
,' position:absolute;'
,' top:0;'
,' left:0;'
,' right:0;'
,' bottom:0;'
,'} #' + wrapID + '.nope-disabled {'
,' cursor:initial;'
,' pointer-events: none;'
,'} .' + nopeClass + '{'
,' position: absolute;'
,' color: #e00;'
,' font: bold 64px/1 Helvetica, Arial, sans-serif;'
,' border: 9px solid;'
,' padding: 3px 11px;'
,'}'
,'.' + nopeHelpClass + ' {'
,' position: fixed;'
,' top: 0;'
,' right: 0;'
,' background: rgba(0, 0, 0, 0.55);'
,' color: #fff;'
,' font: normal 20px/1 \'Courier New\', Courier, monospace;'
,' padding: 5px 8px;'
,'}'
,'#' + wrapID + '.nope-disabled .' + nopeHelpClass + '{'
, ' display: none;'
, '}'
].join('\n');
document.getElementsByTagName('head')[0].appendChild(style);
}
nopeWrap.onclick = nopeClickHandler;
nopeWrap.className = '';
window.onkeyup = function (e) {
if (e.which === 27) { // esc
var nw = document.getElementById(wrapID);
if (nw) {
nw.onclick = null;
window.onkeyup = null;
nw.className = 'nope-disabled';
}
}
};
})();