MCPcopy Create free account
hub / github.com/XIU2/UserScript / addRawDownLink

Function addRawDownLink

GithubEnhanced-High-Speed-Download.user.js:375–417  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

373
374 // Raw 单文件快捷下载(☁)
375 function addRawDownLink() {
376 if (!GM_getValue('menu_rawDownLink')) return
377 // 如果不是项目文件页面,就返回,如果网页有 Raw 下载链接(☁)就返回
378 let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file, .react-directory-filename-column>svg.color-fg-muted');if(files.length === 0) return;if (location.pathname.indexOf('/tags') > -1) return
379 let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length > 0) return;
380
381 // 鼠标指向则显示
382 var mouseOverHandler = function(evt) {
383 let elem = evt.currentTarget,
384 aElm_new = elem.querySelectorAll('.fileDownLink'),
385 aElm_now = elem.querySelectorAll('svg.octicon.octicon-file, svg.color-fg-muted');
386 aElm_new.forEach(el=>{el.style.cssText = 'display: inline'});
387 aElm_now.forEach(el=>{el.style.cssText = 'display: none'});
388 };
389
390 // 鼠标离开则隐藏
391 var mouseOutHandler = function(evt) {
392 let elem = evt.currentTarget,
393 aElm_new = elem.querySelectorAll('.fileDownLink'),
394 aElm_now = elem.querySelectorAll('svg.octicon.octicon-file, svg.color-fg-muted');
395 aElm_new.forEach(el=>{el.style.cssText = 'display: none'});
396 aElm_now.forEach(el=>{el.style.cssText = 'display: inline'});
397 };
398
399 // 循环添加
400 files.forEach(function(fileElm) {
401 let trElm = fileElm.parentNode.parentNode,
402 cntElm_a = trElm.querySelector('[role="rowheader"] > .css-truncate.css-truncate-target.d-block.width-fit > a, .react-directory-truncate>a'),
403 Name = cntElm_a.innerText,
404 href = cntElm_a.getAttribute('href'),
405 href2 = href.replace('/blob/','/'), url = '';
406 if ((raw_url[menu_rawFast][0].indexOf('/gh') + 3 === raw_url[menu_rawFast][0].length) && raw_url[menu_rawFast][0].indexOf('cdn.staticaly.com') === -1) {
407 url = raw_url[menu_rawFast][0] + href.replace('/blob/','@');
408 } else {
409 url = raw_url[menu_rawFast][0] + href2;
410 }
411
412 fileElm.insertAdjacentHTML('afterend', `<a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${raw_url[menu_rawFast][1]}」&#10;&#10;[Alt + 左键点击] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${raw_url[menu_rawFast][2]}&#10;&#10;提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) 即可切换。">${svg[0]}</a>`);
413 // 绑定鼠标事件
414 trElm.onmouseover = mouseOverHandler;
415 trElm.onmouseout = mouseOutHandler;
416 });
417 }
418
419
420 // 移除 Raw 单文件快捷下载(☁)

Callers 1

menu_toggle_raw_fastFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected