-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathgreasyfork.user.js
More file actions
102 lines (95 loc) · 3.02 KB
/
greasyfork.user.js
File metadata and controls
102 lines (95 loc) · 3.02 KB
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
// ==UserScript==
// @name tampermonkey-scripts
// @namespace https://github.com/anghunk/UserScript
// @version 0.0.1
// @description Tampermonkey Scripts
// @author anghunk
// @match http://*/*
// @match https://*/*
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_openInTab
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_notification
// @grant GM_info
// @icon https://www.google.com/s2/favicons?sz=32&domain_url=chrome.com
// @grant none
// @license Apache-2.0 license
// ==/UserScript==
(function () {
'use strict';
var menu_ALL = [
['menu_demo1', '功能名称', '功能名称', true],
];
var menu_ID = [];
for (let i = 0; i < menu_ALL.length; i++) { // 如果读取到的值为 null 就写入默认值
if (GM_getValue(menu_ALL[i][0]) == null) {
GM_setValue(menu_ALL[i][0], menu_ALL[i][3])
};
}
registerMenuCommand();
// 注册脚本菜单
function registerMenuCommand() {
if (menu_ID.length > menu_ALL.length) { // 如果菜单 ID 数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单
for (let i = 0; i < menu_ID.length; i++) {
GM_unregisterMenuCommand(menu_ID[i]);
}
}
for (let i = 0; i < menu_ALL.length; i++) { // 循环注册脚本菜单
menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❌'} ${menu_ALL[i][1]}`, function () {
menu_switch(`${menu_ALL[i][3]}`, `${menu_ALL[i][0]}`, `${menu_ALL[i][2]}`)
});
}
menu_ID[menu_ID.length] = GM_registerMenuCommand('💬 建议与反馈!', function () {
window.GM_openInTab("https://github.com/anghunk/UserScript", {
active: true,
insert: true,
setParent: true
});
});
}
// 菜单开关
function menu_switch(menu_status, Name, Tips) {
if (menu_status == 'true') {
GM_setValue(`${Name}`, false);
GM_notification({
text: `已关闭 [${Tips}] 功能\n(点击刷新网页后生效)`,
timeout: 3500,
onclick: function () {
location.reload();
}
});
} else {
GM_setValue(`${Name}`, true);
GM_notification({
text: `已开启 [${Tips}] 功能\n(点击刷新网页后生效)`,
timeout: 3500,
onclick: function () {
location.reload();
}
});
}
registerMenuCommand(); // 重新注册脚本菜单
};
// 返回菜单值
function menu_value(menuName) {
for (let menu of menu_ALL) {
if (menu[0] == menuName) {
return menu[3]
}
}
}
function demo1() {
if (!menu_value('menu_demo1')) return;
// 替换
if (location.href === "http://localhost:8080/") return
let script = document.createElement('script')
script.src = 'http://127.0.0.1:5500/index.js'
document.body.appendChild(script)
// 替换
}
demo1();
})();