forked from dodying/UserJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths.user.js
56 lines (56 loc) · 1.77 KB
/
s.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
/* eslint-env browser */
// ==UserScript==
// @name []https
// @description
// @include http://*
// @include https://*
// @version 1.0.7
// @author dodying
// @namespace https://github.com/dodying/UserJs
// @supportURL https://github.com/dodying/UserJs/issues
// @icon https://gitee.com/dodying/userJs/raw/master/Logo.png
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_getValue
// @grant GM_setValue
// @connect *
// @noframes
// @run-at document-start
// ==/UserScript==
(function total() {
const blacklist = GM_getValue('blacklist', []);
const { host } = window.location;
if (blacklist.includes(host)) {
let id;
id = GM_registerMenuCommand(`S: Effect ${host}`, () => {
const blacklist = GM_getValue('blacklist', []);
if (blacklist.includes(host)) {
blacklist.splice(blacklist.indexOf(host), 1);
GM_setValue('blacklist', blacklist);
GM_unregisterMenuCommand(id);
total();
}
}, 's');
} else {
if (window.location.protocol === 'http:') {
const url = window.location.href.replace(/^http:/, 'https:');
GM_xmlhttpRequest({
url,
method: 'HEAD',
timeout: 5 * 1000,
onload(res) {
if (new URL(res.finalUrl).protocol === 'https:' && res.status === 200) window.location.href = res.finalUrl;
},
});
}
GM_registerMenuCommand(`S: DO NOT Effect ${host}`, () => {
const blacklist = GM_getValue('blacklist', []);
if (!(blacklist.includes(host))) {
blacklist.push(host);
GM_setValue('blacklist', blacklist);
window.location.href = window.location.href.replace(/^https:/, 'http:');
}
}, 's');
}
}());