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

Function registerMenuCommand

Zhihu-Beautification.user.js:51–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50 // 注册脚本菜单
51 function registerMenuCommand() {
52 if (menu_ID.length > menu_ALL.length){ // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单
53 for (let i=0;i<menu_ID.length;i++){
54 GM_unregisterMenuCommand(menu_ID[i]);
55 }
56 }
57 for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
58 menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
59 if (menu_ALL[i][0] === 'menu_darkModeType') {
60 if (menu_ALL[i][3] > 4){ // 避免在减少 raw 数组后,用户储存的数据大于数组而报错
61 menu_ALL[i][3] = 1;
62 GM_setValue('menu_darkModeType', menu_ALL[i][3]);
63 }
64 menu_ID[i] = GM_registerMenuCommand(`${menu_num(menu_ALL[i][3])} ${menu_ALL[i][1]}`, function(){menu_toggle(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
65 } else if (menu_ALL[i][0] === 'menu_widescreenDisplay'){
66 GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){menu_setting('checkbox', menu_ALL[i][1], menu_ALL[i][2], true, [menu_ALL[i+1], menu_ALL[i+2], menu_ALL[i+3], menu_ALL[i+4], menu_ALL[i+5], menu_ALL[i+6], menu_ALL[i+7]])});
67 } else if (menu_ALL[i][0].indexOf('menu_widescreenDisplay') === -1) {
68 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]}`)});
69 }
70 }
71 menu_ID[menu_ID.length] = GM_registerMenuCommand('💬 反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/412212/feedback', {active: true,insert: true,setParent: true});});
72 }
73
74 // 切换暗黑模式
75 function menu_toggle(menu_status, Name) {

Callers 3

menu_toggleFunction · 0.70
menu_switchFunction · 0.70

Calls 4

menu_numFunction · 0.70
menu_toggleFunction · 0.70
menu_settingFunction · 0.70
menu_switchFunction · 0.70

Tested by

no test coverage detected