-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGreenAllPages.user.js
358 lines (316 loc) · 14.8 KB
/
GreenAllPages.user.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// ==UserScript==
// @name Green page background
// @namespace http://www.TianshengTan.com
// @description This script should work for all pages without CSS. version 1.0, and it also set change font for all elements.
// @match http://*/*
// @match https://*/*
// @run-at document-start
// ==/UserScript==
// green current page, or insert other CSS element to DOM directly
// This is used to be done in custom.css, but it is not supported from chrome 32/33
// document-start works? I remembered it didn't work in the past
// installation guide: drag this file to chrome://extensions page directly
// document.bgColor = '#f4eed9';
// var defaultColor = "#68BB7D"; // 8A9ACA
// Low blue light
var defaultColor = "#50A038";
var zhihuHighContrastColor = "#68BB60";
var style = document.createElement('style');
style.type = 'text/css';
var mainFont = "Open Sans";
var cssBg = false;
function ExcludeFullStyle() {
if (document.URL.indexOf("https://microsoft.visualstudio.com") === 0 ||
document.URL.indexOf("https://www.codewars.com") === 0 ||
document.URL.indexOf("https://play.rust-lang.org") === 0)
{
return true;
}
return false;
}
function ExcludeFont() {
return false;
}
if (!ExcludeFullStyle()) {
if (document.URL.indexOf("https://stackoverflow.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body #content{background-color: " + defaultColor + "!important;} body .tagged-interesting{background-color: " + defaultColor + "!important;}";
}
else if (document.URL.indexOf("https://vi.stackexchange.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body #content{background-color: " + defaultColor +
"!important;} body .container{background-color: " + defaultColor +
"!important;}";
}
else if (document.URL.indexOf("https://mail.google.com") === 0) {
style.innerHTML = "html, body .Bu{background-color: " + defaultColor +
"!important;line-height: 1.2em;font-size:28px;font-family: verdana,serif;} " +
"body .hP{background-color: yellow} h3{background-color: gray}" +
"body .a3s{font: 28px " + mainFont + ",Microsoft YaHei, sans-serif!important;";
}
else if (document.URL.indexOf("https://www.evernote.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.GAOIOH2DIGB{background: #9ACA9A;}";
}
else if (document.URL.indexOf("https://github.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.comment{background-color: " + defaultColor + "!important}";
// mainFont = "Consolas";
}
else if (document.URL.indexOf("https://en.wikipedia.org") === 0 || document.URL.indexOf("https://simple.wikipedia.org") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.mw-content-ltr{background-color: " + defaultColor + "!important;} body div.toc{background-color: " + defaultColor + "!important;} ";
}
else if (document.URL.indexOf("https://zhuanlan.zhihu.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.editable{background-color: " + defaultColor + "!important;}";
mainFont = "Consolas";
}
else if (document.URL.indexOf("https://www.zhihu.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor +
"!important;} body div.Card{background-color: " + defaultColor +
"!important;} body div.ContentItem-actions{background-color: " +
zhihuHighContrastColor + "!important;}" +
" body div.PageHeader{background-color: " + zhihuHighContrastColor +
"!important;} body .Sticky{background-color: " + zhihuHighContrastColor +
"!important;} body div.QuestionHeader{background-color: " + zhihuHighContrastColor +
"!important;} body div.QuestionHeader-footer{background-color: " + zhihuHighContrastColor + "!important;}";
}
else if (document.URL.indexOf("https://gitter.im") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.chat-container{background-color: " + defaultColor + "!important;} body div.burstStart{background-color: " + defaultColor + "!important;} ";
}
else if (document.URL.indexOf("https://microsoft.sharepoint.com") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body div.WACInteractiveView{background-color: " + defaultColor + "!important;}";
cssBg = true;
}
else if (document.URL.indexOf("https://www.safaribooksonline.com") === 0 ||
document.URL.indexOf("https://learning.oreilly.com/library/view") === 0) {
style.innerHTML = "html, body {background-color: " + defaultColor
+ "!important;} body #g{color: blue!important; font-weight: normal!important} #sbo-rt-content pre{backgrond-color: "
+ defaultColor + "!important; font-weight: normal!important} div.annotator-adder{opacity:0.2} div.annotator-outer{opacity:0.2}";
window.setTimeout(()=>{document.querySelector('.t-topbar').remove();}, 500);
document.addEventListener('keydown', (event)=>{
const keyName = event.key;
if (keyName === 'a') {
let nextLink = document.getElementsByClassName('next nav-link');
if (nextLink && nextLink.length > 0) {
nextLink[0].click();
}
}
});
document.addEventListener('mouseup', ()=>{
let sel = window.getSelection();
let note = sel.toString().trim();
// don't hight single word which is for translation!
if (sel.type === "Range" && note.includes(' ')) {
if (!document.smart_notes) {
document.smart_notes = [];
}
document.smart_notes.push(note);
window.setTimeout(()=>{
let hlLink = document.getElementsByClassName('add-highlight');
if (hlLink && hlLink.length == 1) {
hlLink[0].children[0].click();
window.getSelection().empty(); // cancel selection for highlight
}
}, 100);
}
});
}
else if (window.location.href.startsWith('http://infocenter.arm.com/help/index.jsp?'))
{
// redirect arm doc to advanced page to avoid the ugly frame
let currURL = window.location.href;
let newURL = currURL.replace('http://infocenter.arm.com/help/index.jsp', 'http://infocenter.arm.com/help/advanced/help.jsp');
window.location.href = newURL;
}
else if (window.location.href.startsWith('http://infocenter.arm.com/help/advanced/help.jsp?'))
{
let retryCount = 1000; // give 100 * 100 = 10 seconds as total load time
+function deleteSuper(){
let a = document.getElementsByClassName('content');
if (a && a.length == 1 && a[0].contentDocument && a[0].contentDocument.body) {
let b = a[0].contentDocument.body.children;
if (b && b.length > 2) {
let c = b[1].contentDocument;
if (c && c.styleSheets && c.styleSheets.length > 1 && c.styleSheets[0].rules.length == 2) {
c.styleSheets[0].deleteRule(1);
retryCount = 0;
}
}
}
if (--retryCount > 0) {
window.setTimeout(deleteSuper, 100);
}
}();
}
else if (document.URL.indexOf('https://weibo.com/u/3913659795') === 0) {
let weiboInFocus = true; // no fresh at begining
window.onblur = function(){weiboInFocus = false;};
window.onfocus = function(){weiboInFocus = true;document.getElementsByClassName('W_input')[1].focus();};
+function refreshWeibo(){
window.setTimeout(refreshWeibo, 300 * 1000);
if (!weiboInFocus){window.location.reload();};
}();
}
else if (document.URL.indexOf('http://dict.youdao.com') === 0) {
defaultColor = '#D8D5DF';
let adNodeRemoved = false;
let adsNodeRemoved = false;
let authTransRemoved = false;
let resultNavRemoved = false;
let originalSoundRemoved = false;
let authorityNodeRemoved = false;
let adjustedDictOrder =false;
let removeCounter = 0;
if (document.URL.indexOf('http://dict.youdao.com/wordbook/') !== 0) {
function removeGivenNode(queryStr) {
let adNode = document.querySelector(queryStr);
if (adNode) {
adNode.remove();
}
return adNode !== null;
}
+function removeExtraNodes() {
let addToWordList = document.querySelector('#wordbook');
if (addToWordList) {
adNodeRemoved = adNodeRemoved || removeGivenNode('#topImgAd');
adsNodeRemoved = adsNodeRemoved || removeGivenNode('#ads');
authTransRemoved = authTransRemoved || removeGivenNode('#authTrans');
resultNavRemoved = resultNavRemoved || removeGivenNode('#result_navigator');
originalSoundRemoved = originalSoundRemoved || removeGivenNode('#originalSound');
authorityNodeRemoved = authorityNodeRemoved || removeGivenNode('#authority');
let phrsListTabNode = document.querySelector('#phrsListTab');
if (phrsListTabNode) {
let examplesNode = document.querySelector('#examples');
if (examplesNode) {
phrsListTabNode.parentNode.insertBefore(examplesNode, phrsListTabNode.nextSibling);
}
let eTransformNode = document.querySelector('#eTransform');
if (eTransformNode) {
if (examplesNode) {
examplesNode = document.querySelector('#examples');
phrsListTabNode.parentNode.insertBefore(eTransformNode, examplesNode.nextSibling);
} else {
phrsListTabNode.parentNode.insertBefore(eTransformNode, phrsListTabNode.nextSibling);
}
adjustedDictOrder = true;
}
}
}
if (!(adNodeRemoved && adsNodeRemoved && authTransRemoved && resultNavRemoved && originalSoundRemoved &&
authorityNodeRemoved && adjustedDictOrder) &&
removeCounter++ < 100) {
window.setTimeout(removeExtraNodes, 100);
}
}();
}
}
if (!style.innerHTML){
style.innerHTML = "html, body {background-color: " + defaultColor + "!important;} body #g{color: blue!important; font-weight: normal!important} body #f{color: " + defaultColor + "!important; font-weight: normal!important}";
}
// temporary code for special site
// reload with fresh URL everytime to avoid err paramater encoded in URL
// https://www.eventbrite.com/e/20181-tickets-41719562334
// test URL: https://www.eventbrite.com/e/41931888407
const REG_EVENT_URL = 'https://www.eventbrite.com/e/20181-tickets-41719562334';
if (document.URL.startsWith(REG_EVENT_URL)) {
const RELOAD_INTERVAL = 60000; //ms
document.addEventListener('DOMContentLoaded', function regChime(){
if ((document.getElementsByClassName('ticket_table_select').length == 0) ||
typeof(freeCheckout) !== 'function') {
// no available seats to register, reload?
// alert("No seats, will reload and check");
window.setTimeout(function(){document.location = REG_EVENT_URL;}, RELOAD_INTERVAL);
}
else {
// select option to reserve, needs customization???
document.getElementsByClassName('ticket_table_select')[0].children[1].selected = true;
// start to checkout
freeCheckout();
// alert('Register success?'); // comment out this if result page is actively monitered.
// reload if see errors
(function ReloadOnError(){
var errMsg = document.getElementById('ticket_error_message');
if (errMsg && errMsg['style'].display != 'none') {/* register error? */ document.location = REG_EVENT_URL;}
else {window.setTimeout(ReloadOnError, RELOAD_INTERVAL);}})();
}
});
}
else if (document.URL.startsWith('https://www.eventbrite.com/register')) {
document.addEventListener('DOMContentLoaded', function confirmReg(){
if (typeof(freeCheckout) === "function") {freeCheckout();}
else {window.setTimeout(confirmReg, 100000);}
});
}
if(document.URL.indexOf("https://reviews.llvm.org") === 0 ||
document.URL.indexOf("wincode") === 7 ||
document.URL.indexOf("http://llvm.org/doxygen/") === 0 ||
document.URL.indexOf("https://github.com/") === 0) {
mainFont = "Consolas";
}
document.getElementsByTagName("head")[0].appendChild( style );
(function() {var css = [
"@namespace html url(http://www.w3.org/1999/xhtml);",
"*",
"{",
" font-family: \"" + mainFont + "\", \"Microsoft YaHei\", sans-serif!important;",
cssBg ? "background-color: " + defaultColor + "!important;" : "",
"}",
"",
"h1, h2, h3, h4, h5, h6, h1 *, h2 *, h3 *, h4 *, h5 *, h6 *",
"{",
" font-family: \"" + mainFont + "\", \"Roboto\", sans-serif;",
" text-rendering: optimizeLegibility;",
cssBg ? "background-color: " + defaultColor + "!important;" : "",
"}",
"",
"h1, h1 *",
"{",
" letter-spacing: -2px;",
"}",
"",
"h2, h2 *",
"{",
" letter-spacing: -1px;",
"}"
].join("\n");
if (ExcludeFont()) {
// don't do anything
}
else if (typeof GM_addStyle != "undefined") {
GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
addStyle(css);
} else {
var node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
heads[0].appendChild(node);
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node);
}
}
})();
}
if (document.URL.startsWith('https://microsoft.visualstudio.com/DefaultCollection/_git/os/commit')) {
document.addEventListener('DOMContentLoaded',
function addCFLink(){
let titleNode = document.getElementsByClassName('inline')[0];
if (!titleNode) {
setTimeout(addCFLink, 300);
return;
}
let titleText = titleNode.innerText;
if (titleText && titleText.startsWith("Merged PR")) {
let prNum = parseInt(titleText.substr(10));
if (Number.isInteger(prNum)){
let newTitle = document.createElement('a');
let linkURL = "codeflow:open?server=https://microsoft.visualstudio.com/DefaultCollection/&project=8d47e068-03c8-4cdc-aa9b-fc6929290322&repo=7bc5fd9f-6098-479a-a87e-1533d288d438&pullRequest=" + prNum;
newTitle.innerText = titleText;
newTitle.href=linkURL;
titleNode.replaceWith(newTitle);
}
}
}
);
}