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

Function addUrlChangeEvent

Zhihu-Enhanced.user.js:1446–1464  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1444
1445// 自定义 urlchange 事件(用来监听 URL 变化)
1446function addUrlChangeEvent() {
1447 history.pushState = ( f => function pushState(){
1448 var ret = f.apply(this, arguments);
1449 window.dispatchEvent(new Event('pushstate'));
1450 window.dispatchEvent(new Event('urlchange'));
1451 return ret;
1452 })(history.pushState);
1453
1454 history.replaceState = ( f => function replaceState(){
1455 var ret = f.apply(this, arguments);
1456 window.dispatchEvent(new Event('replacestate'));
1457 window.dispatchEvent(new Event('urlchange'));
1458 return ret;
1459 })(history.replaceState);
1460
1461 window.addEventListener('popstate',()=>{
1462 window.dispatchEvent(new Event('urlchange'))
1463 });
1464}
1465
1466
1467function getXpath(xpath, contextNode, doc = document) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected