()
| 1444 | |
| 1445 | // 自定义 urlchange 事件(用来监听 URL 变化) |
| 1446 | function 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 | |
| 1467 | function getXpath(xpath, contextNode, doc = document) { |
no outgoing calls
no test coverage detected