scripts.js - dotfiles - leot's dotfiles
(HTM) hg clone https://bitbucket.org/iamleot/dotfiles
(DIR) Log
(DIR) Files
(DIR) Refs
---
scripts.js
---
1 /*
2 * Fix "lazy" loaded image.
3 */
4 (function() {
5
6 document.querySelectorAll("img[data-thumb]").forEach(function(e) {
7 e.src = e.getAttribute("data-thumb");
8 });
9
10 document.querySelectorAll("img[data-src]").forEach(function(e) {
11 e.src = e.getAttribute("data-src");
12 });
13
14 document.querySelectorAll("img[data-original]").forEach(function(e) {
15 e.src = e.getAttribute("data-original");
16 });
17
18 })();
19
20 /*
21 * Add `p' and `n' accesskey-s (previous/next via `Mod1 + p'/`Mod1 + n')
22 */
23 (function() {
24
25 previous_selectors = [
26 'a[rel="prev"]',
27 'a[aria-label="Pagina precedente"]', // google.it
28 'a[aria-label="Previous page"]', // google.com
29 ];
30 previous_res = [
31 /<</,
32 /«/,
33 /←/,
34 ];
35
36 next_selectors = [
37 'a[rel="next"]',
38 'a[aria-label="Pagina successiva"]', // google.it
39 'a[aria-label="Next page"]', // google.com
40 ];
41 next_res = [
42 />>/,
43 /»/,
44 /→/,
45 ];
46
47 has_prev = false;
48 has_next = false;
49
50 if (document.querySelector('*[accesskey="p"]')) {
51 has_prev = true;
52 }
53 if (document.querySelector('*[accesskey="n"]')) {
54 has_next = true;
55 }
56
57 if (!has_prev) {
58 for (p of previous_selectors) {
59 if (e = document.querySelector(p)) {
60 e.accessKey = "p";
61 has_prev = true;
62 break;
63 }
64 }
65 }
66 if (!has_next) {
67 for (n of next_selectors) {
68 if (e = document.querySelector(n)) {
69 e.accessKey = "n";
70 has_next = true;
71 break;
72 }
73 }
74 }
75
76 for (i = document.links.length - 1; !has_prev && i >= 0; i--) {
77 for (p of previous_res) {
78 if (document.links[i].text &&
79 document.links[i].text.match(p)) {
80 document.links[i].accessKey = "p";
81 has_prev = true;
82 break;
83 }
84 }
85 }
86 for (i = document.links.length - 1; !has_next && i >= 0; i--) {
87 for (n of next_res) {
88 if (document.links[i].text &&
89 document.links[i].text.match(n)) {
90 document.links[i].accessKey = "n";
91 has_next = true;
92 break;
93 }
94 }
95 }
96
97 })();
98
99
100 function userscript_ft()
101 {
102 document.querySelectorAll(".cookie-banner").forEach(function(e) {
103 e.remove();
104 });
105 }
106
107 function userscript_economist()
108 {
109 document.querySelectorAll("div.fe-blogs__top-ad-wrapper").forEach(function(e) {
110 e.remove();
111 });
112 }
113
114 function userscript_github()
115 {
116 [".signup-prompt-bg"].forEach(function(c) {
117 document.querySelectorAll(c).forEach(function(e) {
118 e.remove();
119 });
120 });
121 }
122
123 function userscript_internazionale()
124 {
125 [".ads_content_top", ".content_adv", ".hentry--banner", ".lazyload_ad", ".wrapAd"].forEach(function(c) {
126 document.querySelectorAll(c).forEach(function(e) {
127 e.remove();
128 });
129 });
130 ['img[src*="scorecardresearch.com"]'].forEach(function(c) {
131 document.querySelectorAll(c).forEach(function(e) {
132 e.remove();
133 });
134 });
135
136 }
137
138 function userscript_medium()
139 {
140 ["div.metabar", "div.u-bottom0"].forEach(function(c) {
141 document.querySelectorAll(c).forEach(function(e) {
142 e.remove();
143 });
144 });
145 }
146
147 function userscript_nvd()
148 {
149 ["style#antiClickjack"].forEach(function(c) {
150 document.querySelectorAll(c).forEach(function(e) {
151 e.remove();
152 });
153 });
154 [".vuln-change-history-container"].forEach(function(c) {
155 document.querySelectorAll(c).forEach(function(e) {
156 e.style["display"] = "block";
157 });
158 });
159 }
160
161 function userscript_nytimes()
162 {
163 ["#top-wrapper", "#bottom-wrapper"].forEach(function(c) {
164 document.querySelectorAll(c).forEach(function(e) {
165 e.remove();
166 });
167 });
168 }
169
170 function userscript_ondarock()
171 {
172 e = document.querySelector("#bottom-banner");
173 if (e) {
174 e.remove();
175 }
176 }
177
178 function userscript_stackoverflow()
179 {
180 ["#js-gdpr-consent-banner", ".js-dismissable-hero"].forEach(function(c) {
181 document.querySelectorAll(c).forEach(function(e) {
182 e.remove();
183 });
184 });
185 }
186
187 function userscript_technologyreview_download()
188 {
189 a = document.querySelector("article");
190 if (a) {
191 document.body.replaceWith(a);
192 }
193 }
194
195 function userscript_technologyreview()
196 {
197 e = document.querySelector("div.meter");
198 if (e) {
199 e.remove();
200 }
201 }
202
203 function userscript_theatlantic()
204 {
205 document.querySelectorAll("img[data-src]").forEach(function(e) {
206 e.src = e.getAttribute("data-src");
207 e.style["opacity"] = 100;
208 });
209 }
210
211 function userscript_theverge()
212 {
213 e = document.querySelector("div#privacy-consent");
214 if (e) {
215 e.remove();
216 }
217 }
218
219 function userscript_twitter()
220 {
221 if (window.location.href.search('://twitter.com/') != -1) {
222 window.location.href = window.location.href.replace('://twitter.com/', '://mobile.twitter.com/');
223 }
224
225 ["#brand_bar", ".toast", "#footer"].forEach(function(c) {
226 document.querySelectorAll(c).forEach(function(e) {
227 e.remove();
228 });
229 });
230
231 a = document.querySelector("#container");
232 if (a) {
233 a.style.width = "640px";
234 a.style.marginTop = "20px";
235 a.style.borderWidth = "1px";
236 }
237 }
238
239 function userscript_wsj_amp()
240 {
241 [".login-section-container", ".wsj-ad", "amp-geo", "amp-consent"].forEach(function(c) {
242 document.querySelectorAll(c).forEach(function(e) {
243 e.remove();
244 });
245 });
246 }