Greasy Fork is available in English.

网页里面简单的侦听网址变化

网页侦听网址变化

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/474123/1242468/%E7%BD%91%E9%A1%B5%E9%87%8C%E9%9D%A2%E7%AE%80%E5%8D%95%E7%9A%84%E4%BE%A6%E5%90%AC%E7%BD%91%E5%9D%80%E5%8F%98%E5%8C%96.js

// ==UserScript==
// @name         网页里面简单的侦听网址变化
// @namespace    https://leochan.me
// @version      1.0.0
// @description  网页侦听网址变化
// @author       Leo
// @license      GPLv2
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leochan.me
// @grant        unsafeWindow
// ==/UserScript==
 
function webPageWatchUrl(watchCallback){
    watchCallback();
    var originalPushState = history.pushState;
    history.pushState = function() {
        originalPushState.apply(history, arguments);
        watchCallback();
    };
    var originalReplaceState = history.replaceState;
    history.replaceState = function() {
        originalReplaceState.apply(history, arguments);
        watchCallback();
    };
    window.addEventListener('popstate', () => {
        watchCallback();
    });
}