Skip to content

Commit 6c58e83

Browse files
committed
优化 Raw 快捷下载(☁)按钮位置(解决文件名过长导致按钮不显示的问题)
1 parent fad5eee commit 6c58e83

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Github 增强 - 高速下载
3-
// @version 1.1.7
3+
// @version 1.1.8
44
// @author X.I.U
55
// @description 为 Github 的 Clone、Release、Raw、Code(ZIP) 添加高速下载
66
// @match https://github.com/*/*
@@ -210,24 +210,29 @@
210210

211211
// 鼠标指向则显示
212212
var mouseOverHandler = function(evt){
213-
var elem = evt.currentTarget,
214-
aElm = elem.querySelectorAll('.fileDownLink');
215-
aElm.forEach(el=>el.style.visibility = 'visible');
213+
var elem = evt.currentTarget,
214+
aElm_new = elem.querySelectorAll('.fileDownLink'),
215+
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light');
216+
aElm_new.forEach(el=>el.style.cssText = 'display: inline');
217+
aElm_now.forEach(el=>el.style.cssText = 'display: none');
216218
};
217219

218220
// 鼠标离开则隐藏
219221
var mouseOutHandler = function(evt){
220222
var elem = evt.currentTarget,
221-
aElm = elem.querySelectorAll('.fileDownLink');
222-
aElm.forEach(el=>el.style.visibility = 'hidden');
223+
aElm_new = elem.querySelectorAll('.fileDownLink'),
224+
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light');
225+
aElm_new.forEach(el=>el.style.cssText = 'display: none');
226+
aElm_now.forEach(el=>el.style.cssText = 'display: inline');
223227
};
224228

225229
// 循环添加
226230
files.each(function(i,fileElm){
227231
var trElm = fileElm.parentNode.parentNode,
228-
cntElm = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
229-
Name = cntElm.innerText,
230-
href = cntElm.attributes['href'].nodeValue.replace('https://github.com','');
232+
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
233+
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.text-gray-light'),
234+
Name = cntElm_a.innerText,
235+
href = cntElm_a.attributes['href'].nodeValue.replace('https://github.com','');
231236
var href2 = href.replace('/blob/','/'), url, url_name, url_tip = "";
232237
switch(menu_raw_fast)
233238
{
@@ -250,8 +255,8 @@
250255
url_name = download_url5_name;
251256
break;
252257
}
253-
var html1 = ` <a href="${url}" download="${Name}" target="_blank" class="fileDownLink" style="visibility: hidden;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${menu_raw_fast} ] 加速源 (☁) - 点击切换。">${raw_svg}</a>`;
254-
$(cntElm).after(html1);
258+
var html1 = ` <a href="${url}" download="${Name}" target="_blank" class="fileDownLink" style="display: none;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${menu_raw_fast} ] 加速源 (☁) - 点击切换。">${raw_svg}</a>`;
259+
$(cntElm_svg).after(html1);
255260
// 绑定鼠标事件
256261
trElm.onmouseover=mouseOverHandler;
257262
trElm.onmouseout=mouseOutHandler;

0 commit comments

Comments
 (0)