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

Function menu_forcedToEnable

DarkMode.user.js:222–258  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

220
221 // 强制当前网站启用护眼模式
222 function menu_forcedToEnable(type) {
223 switch(type) {
224 case 'check':
225 if(check()) return true
226 return false
227 break;
228 case 'add':
229 add();
230 break;
231 case 'del':
232 del();
233 break;
234 }
235
236 function check() { // 存在返回真,不存在返回假
237 let websiteList = menu_value('menu_forcedToEnable'); // 读取网站列表
238 if (websiteList.indexOf(location.host) === -1) return false // 不存在返回假
239 return true
240 }
241
242 function add() {
243 if (check()) return
244 let websiteList = menu_value('menu_forcedToEnable'); // 读取网站列表
245 websiteList.push(location.host); // 追加网站域名
246 GM_setValue('menu_forcedToEnable', websiteList); // 写入配置
247 location.reload(); // 刷新网页
248 }
249
250 function del() {
251 if (!check()) return
252 let websiteList = menu_value('menu_forcedToEnable'), // 读取网站列表
253 index = websiteList.indexOf(location.host);
254 websiteList.splice(index, 1); // 删除网站域名
255 GM_setValue('menu_forcedToEnable', websiteList); // 写入配置
256 location.reload(); // 刷新网页
257 }
258 }
259
260
261 // 启用/禁用护眼模式 (当前网站)

Callers 1

registerMenuCommandFunction · 0.70

Calls 3

checkFunction · 0.70
addFunction · 0.70
delFunction · 0.70

Tested by

no test coverage detected