11// ==UserScript==
22// @name Github 增强 - 高速下载
3- // @version 1.4.4
3+ // @version 1.4.5
44// @author X.I.U
55// @description 高速下载 Git Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66// @match *://github.com/*
102102 setTimeout ( addRawDownLink , 2000 ) ; // 添加 Raw 下载链接(☁),延迟 2 秒执行,避免被 pjax 刷掉
103103 } ) ;
104104
105+ pushHistory ( ) ;
106+ window . addEventListener ( 'popstate' , function ( e ) {
107+ addRawDownLink_ ( ) ; // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)鼠标事件
108+ } , false ) ;
109+ function pushHistory ( ) {
110+ let state = { title : 'title' , url : '#' } ;
111+ window . history . pushState ( state , '' , '' ) ;
112+ }
113+
105114
106115 // Release
107116 function addRelease ( ) {
214223
215224 // 添加 Raw 下载链接(☁)
216225 function addRawDownLink ( ) {
217- // 如果不是项目文件页面,就返回
226+ // 如果不是项目文件页面,就返回,如果网页有 Raw 下载链接(☁)就返回
218227 let files = document . querySelectorAll ( 'div.Box-row svg.octicon.octicon-file' ) ; if ( files . length === 0 ) return ;
219228 let files1 = document . querySelectorAll ( 'a.fileDownLink' ) ; if ( files1 . length > 0 ) return ;
220229
244253 Name = cntElm_a . innerText ,
245254 href = cntElm_a . attributes . href . nodeValue . replace ( 'https://github.com' , '' ) ;
246255 let href2 = href . replace ( '/blob/' , '/' ) , url , url_name , url_tip = '' ;
247- switch ( menu_raw_fast )
248- {
256+ switch ( menu_raw_fast ) {
249257 case 1 :
250258 url = raw_url [ 1 ] [ 0 ] + '/gh' + href . replace ( '/blob/' , '@' ) ;
251259 url_name = raw_url [ 1 ] [ 1 ] ;
278286 fileElm . remove ( )
279287 } )
280288 }
289+
290+
291+ // 在浏览器返回/前进时重新添加 Raw 下载链接(☁)鼠标事件
292+ function addRawDownLink_ ( ) {
293+ // 如果不是项目文件页面,就返回,如果网页没有 Raw 下载链接(☁)就返回
294+ let files = document . querySelectorAll ( 'div.Box-row svg.octicon.octicon-file' ) ; if ( files . length === 0 ) return ;
295+ let files1 = document . querySelectorAll ( 'a.fileDownLink' ) ; if ( files1 . length === 0 ) return ;
296+
297+ // 鼠标指向则显示
298+ var mouseOverHandler = function ( evt ) {
299+ let elem = evt . currentTarget ,
300+ aElm_new = elem . querySelectorAll ( '.fileDownLink' ) ,
301+ aElm_now = elem . querySelectorAll ( 'svg.octicon.octicon-file.color-icon-tertiary' ) ;
302+ aElm_new . forEach ( el => { el . style . cssText = 'display: inline' } ) ;
303+ aElm_now . forEach ( el => { el . style . cssText = 'display: none' } ) ;
304+ } ;
305+
306+ // 鼠标离开则隐藏
307+ var mouseOutHandler = function ( evt ) {
308+ let elem = evt . currentTarget ,
309+ aElm_new = elem . querySelectorAll ( '.fileDownLink' ) ,
310+ aElm_now = elem . querySelectorAll ( 'svg.octicon.octicon-file.color-icon-tertiary' ) ;
311+ aElm_new . forEach ( el => { el . style . cssText = 'display: none' } ) ;
312+ aElm_now . forEach ( el => { el . style . cssText = 'display: inline' } ) ;
313+ } ;
314+
315+ // 循环添加
316+ files . forEach ( function ( fileElm , i ) {
317+ let trElm = fileElm . parentNode . parentNode ;
318+ // 绑定鼠标事件
319+ trElm . onmouseover = mouseOverHandler ;
320+ trElm . onmouseout = mouseOutHandler ;
321+ } ) ;
322+ }
281323} ) ( ) ;
0 commit comments