MCPcopy Create free account
hub / github.com/XIU2/UserScript / registerMenuCommand

Function registerMenuCommand

DarkMode.user.js:55–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53
54 // 注册脚本菜单
55 function registerMenuCommand() {
56 if (menu_ID.length != []){
57 for (let i=0;i<menu_ID.length;i++){
58 GM_unregisterMenuCommand(menu_ID[i]);
59 }
60 }
61 for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
62 menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
63 if (menu_ALL[i][0] === 'menu_disable')
64 { // 启用/禁用护眼模式 (当前网站)
65 if (menu_disable('check')) { // 当前网站是否已存在禁用列表中
66 menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][2]}`, function(){menu_disable('del')});
67 return
68 } else {
69 if (GM_getValue('menu_darkModeAuto') && !window.matchMedia('(prefers-color-scheme: dark)').matches) {
70 menu_ID[i] = GM_registerMenuCommand(`❌ 当前浏览器为白天模式 (点击关闭 [护眼模式跟随浏览器])`, function(){GM_setValue('menu_darkModeAuto', false);location.reload();});
71 return
72 }
73 menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][1]}`, function(){menu_disable('add')});
74 }
75 }
76 else if (menu_ALL[i][0] === 'menu_darkModeType')
77 { // 点击切换模式
78 if (menu_ALL[i][3] > 3) { // 避免在减少 raw 数组后,用户储存的数据大于数组而报错
79 menu_ALL[i][3] = 1;
80 GM_setValue(menu_ALL[i][0], menu_ALL[i][3]);
81 }
82 let menu_newMode = getAutoSwitch();
83 menu_ID[i] = GM_registerMenuCommand(`${menu_num(menu_newMode)} ${menu_ALL[i][1]}`, function(){menu_toggle(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
84 }
85 else if (menu_ALL[i][0] === 'menu_customMode')
86 { // 自定义当前模式
87 GM_setValue(menu_ALL[i][0], menu_ALL[i][3]);
88 menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){menu_customMode()});
89 }
90 else if (menu_ALL[i][0] === 'menu_customTime')
91 { // 自定义昼夜时间
92 GM_setValue(menu_ALL[i][0], menu_ALL[i][3]);
93 menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){menu_customTime()});
94 }
95 else if (menu_ALL[i][0] === 'menu_customMode1' || menu_ALL[i][0] === 'menu_customMode2' || menu_ALL[i][0] === 'menu_customMode3' || menu_ALL[i][0] === 'menu_customMode3_exclude')
96 { // 当前模式值
97 GM_setValue(menu_ALL[i][0], menu_ALL[i][3]);
98 }
99 else if (menu_ALL[i][0] === 'menu_autoSwitch')
100 { // 晚上自动切换模式
101 menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){menu_customAutoSwitch()});
102 }
103 else if (menu_ALL[i][0] === 'menu_forcedToEnable')
104 { // 强制当前网站启用护眼模式
105 if (menu_value('menu_autoRecognition')) { // 自动排除自带暗黑模式的网页 (beta)
106 if (menu_forcedToEnable('check')) { // 当前网站是否已存在列表中
107 menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][1]}`, function(){menu_forcedToEnable('del')});
108 } else {
109 menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][2]}`, function(){menu_forcedToEnable('add')});
110 }
111 }
112 }

Callers 6

DarkMode.user.jsFile · 0.70
menu_customAutoSwitchFunction · 0.70
menu_customModeFunction · 0.70
menu_customTimeFunction · 0.70
menu_toggleFunction · 0.70
menu_switchFunction · 0.70

Calls 10

getAutoSwitchFunction · 0.85
menu_customModeFunction · 0.85
menu_customTimeFunction · 0.85
menu_customAutoSwitchFunction · 0.85
menu_disableFunction · 0.70
menu_numFunction · 0.70
menu_toggleFunction · 0.70
menu_valueFunction · 0.70
menu_forcedToEnableFunction · 0.70
menu_switchFunction · 0.70

Tested by

no test coverage detected