自用

目前為 2022-01-04 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/438011/1005018/%E5%BA%93.js

// ==UserScript==
// @name         库
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  自用
// @author       Mr Liu
// @match        *
// @grant        none
// @require      https://cdn.bootcss.com/jquery/3.6.0/jquery.min.js
// ==/UserScript==

function Input(ele,val){//键盘输入函数  可调用
    ele.value = val;
    let event = new Event('input', { bubbles: true });
    let tracker = ele._valueTracker;
    if (tracker) {
        tracker.setValue('');
    }
    ele.dispatchEvent(event);
}
function ysjt(fun){//元素监听
    const url=window.location.href
    const targetNode = $('.ant-layout')[0];//content监听的元素id
    //options:监听的属性
    const options = { attributes: true, childList: true,subtree:true,attributeOldValue:true};
    //回调事件
    const mutationObserver = new MutationObserver(()=>{
        if(window.location.href!=url){
            fun()//要执行的
        }
    });
    mutationObserver.observe(targetNode, options)
}
function mdjt(fun){//锚点监听  检测url变化
    window.onpopstate = function (event) {
        fun();
    }
}