在GKD网页审查工具复制规则后,弹出提示框,让用户修改规则名称和描述
当前为
// ==UserScript== // @name GKD网页审查工具规则复制增强 // @namespace https://blog.adproqwq.xyz // @version 0.1.1 // @description 在GKD网页审查工具复制规则后,弹出提示框,让用户修改规则名称和描述 // @author Adpro // @match https://i.gkd.li/snapshot/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @require https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js // @license MIT // ==/UserScript== (function() { 'use strict'; function modifyRule(){ let isSelectorCopyButtonExist = document.querySelector('[title=\"复制规则\"]'); if(isSelectorCopyButtonExist !== null){ isSelectorCopyButtonExist.onclick = () => { console.log('点击'); navigator.clipboard.readText().then((a)=>{ let rule = JSON5.parse(a); let ruleName = prompt('请输入规则名:'); let ruleDesc = prompt('请输入规则描述(如果没有描述请点取消):'); rule.groups[0].name = ruleName !== null && ruleName != '' ? ruleName : rule.groups[0].name; if(ruleDesc === null) delete rule.groups[0].desc; else rule.groups[0].desc = ruleDesc != '' ? ruleDesc : rule.groups[0].desc; navigator.clipboard.writeText(JSON5.stringify(rule,null,2)).then(()=>{ console.log('注入修改成功'); }); }); }; } } let body = document.body; let config = { childList: true }; let callback = (mutationsList)=>{ mutationsList.forEach(() => { modifyRule(); }); }; let observer = new MutationObserver(callback); observer.observe(body,config); })();