Skip to content

Commit 23c6a5d

Browse files
committed
修复 通过浏览器前进/后退后,Raw 快捷下载图标不显示的问题
1 parent 8be1546 commit 23c6a5d

1 file changed

Lines changed: 46 additions & 4 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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/*
@@ -102,6 +102,15 @@
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(){
@@ -214,7 +223,7 @@
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

@@ -244,8 +253,7 @@
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];
@@ -278,4 +286,38 @@
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

Comments
 (0)