11// ==UserScript==
22// @name Github 增强 - 高速下载
3- // @version 1.5.5
3+ // @version 1.5.6
44// @author X.I.U
55// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66// @match *://github.com/*
1919// @homepageURL https://github.com/XIU2/UserScript
2020// ==/UserScript==
2121
22- 'use strict' ;
2322( function ( ) {
23+ 'use strict' ;
2424 var backColor = '#ffffff' ;
2525 var fontColor = '#888888' ;
2626 if ( document . getElementsByTagName ( 'html' ) [ 0 ] . getAttribute ( 'data-color-mode' ) === 'dark' ) { // 黑暗模式判断
151151 setTimeout ( addRawDownLink , 2000 ) ; // 添加 Raw 下载链接(☁),延迟 2 秒执行,避免被 pjax 刷掉
152152 } ) ;
153153
154- pushHistory ( ) ;
154+ addLocationchange ( ) ;
155+ window . addEventListener ( 'locationchange' , function ( ) {
156+ addRawDownLink_ ( ) ; // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)事件
157+ } )
158+
159+ /*pushHistory();
155160 window.addEventListener('popstate', function(e) {
156- addRawDownLink_ ( ) ; // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)鼠标事件
161+ addRawDownLink_(); // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)事件
157162 }, false);
158163 function pushHistory() {
159164 let state = {title: 'title',url: '#'};
160165 window.history.pushState(state, '', '');
161- }
166+ }*/
162167
168+ /*let oldUrl = location.href,
169+ timer = setInterval(function(){
170+ if (oldUrl != location.href) {
171+ oldUrl = location.href;
172+ addRawDownLink_(); // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)事件
173+ }
174+ }, 1000);*/
163175
164176 // Release
165177 function addRelease ( ) {
410422 trElm . onmouseout = mouseOutHandler ;
411423 } ) ;
412424 }
425+
426+
427+ // 自定义 locationchange 事件(用来监听 URL 变化,针对的是 Github 这种因为使用 pjax 而无法依靠 hashchange 监听的网页)
428+ function addLocationchange ( ) {
429+ history . pushState = ( f => function pushState ( ) {
430+ var ret = f . apply ( this , arguments ) ;
431+ window . dispatchEvent ( new Event ( 'pushstate' ) ) ;
432+ window . dispatchEvent ( new Event ( 'locationchange' ) ) ;
433+ return ret ;
434+ } ) ( history . pushState ) ;
435+
436+ history . replaceState = ( f => function replaceState ( ) {
437+ var ret = f . apply ( this , arguments ) ;
438+ window . dispatchEvent ( new Event ( 'replacestate' ) ) ;
439+ window . dispatchEvent ( new Event ( 'locationchange' ) ) ;
440+ return ret ;
441+ } ) ( history . replaceState ) ;
442+
443+ window . addEventListener ( 'popstate' , ( ) => {
444+ window . dispatchEvent ( new Event ( 'locationchange' ) )
445+ } ) ;
446+ }
413447} ) ( ) ;
0 commit comments