()
| 487 | |
| 488 | // 自定义 urlchange 事件(用来监听 URL 变化),针对非 Tampermonkey 油猴管理器 |
| 489 | function addUrlChangeEvent() { |
| 490 | history.pushState = ( f => function pushState(){ |
| 491 | var ret = f.apply(this, arguments); |
| 492 | window.dispatchEvent(new Event('pushstate')); |
| 493 | window.dispatchEvent(new Event('urlchange')); |
| 494 | return ret; |
| 495 | })(history.pushState); |
| 496 | |
| 497 | history.replaceState = ( f => function replaceState(){ |
| 498 | var ret = f.apply(this, arguments); |
| 499 | window.dispatchEvent(new Event('replacestate')); |
| 500 | window.dispatchEvent(new Event('urlchange')); |
| 501 | return ret; |
| 502 | })(history.replaceState); |
| 503 | |
| 504 | window.addEventListener('popstate',()=>{ // 点击浏览器的前进/后退按钮时触发 urlchange 事件 |
| 505 | window.dispatchEvent(new Event('urlchange')) |
| 506 | }); |
| 507 | } |
| 508 | })(); |
no outgoing calls
no test coverage detected