| 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 | })(); |