MCPcopy Index your code
hub / github.com/XIU2/UserScript / addUrlChangeEvent

Function addUrlChangeEvent

Autopage.user.js:2960–2978  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2958 }
2959 // 自定义 urlchange 事件(用来监听 URL 变化)
2960 function addUrlChangeEvent() {
2961 history.pushState = ( f => function pushState(){
2962 var ret = f.apply(this, arguments);
2963 window.dispatchEvent(new Event('pushstate'));
2964 window.dispatchEvent(new Event('urlchange'));
2965 return ret;
2966 })(history.pushState);
2967
2968 history.replaceState = ( f => function replaceState(){
2969 var ret = f.apply(this, arguments);
2970 window.dispatchEvent(new Event('replacestate'));
2971 window.dispatchEvent(new Event('urlchange'));
2972 return ret;
2973 })(history.replaceState);
2974
2975 window.addEventListener('popstate',()=>{
2976 window.dispatchEvent(new Event('urlchange'))
2977 });
2978 }
2979})();

Callers 1

Autopage.user.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected