GKD网页审查工具规则复制增强

在GKD网页审查工具复制规则后,弹出提示框,让用户修改规则名称和描述

目前為 2024-03-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GKD网页审查工具规则复制增强
// @namespace    https://blog.adproqwq.xyz
// @version      0.2.1
// @description  在GKD网页审查工具复制规则后,弹出提示框,让用户修改规则名称和描述
// @author       Adpro
// @match        https://i.gkd.li/snapshot/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @require      https://greasyfork.org/scripts/411512-gm-createmenu/code/GM_createMenu.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js
// @require      https://fastly.jsdelivr.net/npm/[email protected]/dist/layui.min.js
// @resource     css https://fastly.jsdelivr.net/npm/[email protected]/dist/css/layui.min.css
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';
  GM_addStyle(GM_getResourceText('css'));

  var mode = 0;
  const layer = layui.layer;

  GM_createMenu.add([
    {
      name: "app模式(默认)",
      callback: function(){
        mode = 0;
        layer.msg('设置成功');
      }
    },
    {
      name: "groups模式",
      callback: function(){
        mode = 1;
        layer.msg('设置成功');
      },
    },
    {
      name: "rules模式",
      callback: function(){
        mode = 2;
        layer.msg('设置成功');
      },
    }
  ]);
  GM_createMenu.create();

  function modifyRule(){
    let isSelectorCopyButtonExist = document.querySelector('[title=\"复制规则\"]');
    if(isSelectorCopyButtonExist !== null){
      isSelectorCopyButtonExist.onclick = () => {
        navigator.clipboard.readText().then((a)=>{
          let rule = JSON5.parse(a);
          layer.prompt({
            title: '请输入规则名:',
            placeholder: rule.groups[0].name
          },(value, index)=>{
            if(value != '') rule.groups[0].name = value;
            layer.close(index);
            layer.prompt({
              title: '请输入规则描述:',
              placeholder: '如果没有描述请保持空白'
            },(value, index)=>{
              if(value == '') delete rule.groups[0].desc;
              else rule.groups[0].desc = value;
              layer.close(index);
              copyRule(rule, mode);
            });
          });
        });
      };
    }
  }

  function copyRule(rule, mode){
    if(mode == 0){
      navigator.clipboard.writeText(JSON5.stringify(rule,null,2)).then(()=>{
        layer.msg('注入修改成功');
      });
    }
    else if(mode == 1){
      navigator.clipboard.writeText(JSON5.stringify(rule.groups[0],null,2)).then(()=>{
        layer.msg('注入修改成功');
      });
    }
    else if(mode == 2){
      navigator.clipboard.writeText(JSON5.stringify(rule.groups[0].rules[0],null,2)).then(()=>{
        layer.msg('注入修改成功');
      });
    }
  }
  
  let body = document.body;
  let config = {
    childList: true
  };
  let callback = (mutationsList)=>{
    mutationsList.forEach(() => {
      modifyRule();
    });
  };
  
  let observer = new MutationObserver(callback);
  observer.observe(body,config);

})();