// ==UserScript== // @name Github 高速下载,文件加速下载(不限于Github,可根据需要修改match) // @namespace Violentmonkey Scripts // @match *://github.com/* // @description 文件高速下载,可用于各种因为网络问题而下载慢的文件(不限于github),鼠标箭头悬停在下载链接0.5秒,即可显示高速下载按钮。 // @grant none // @version 1.0 // @author - // @license MIT // @description 2023/11/5 10:21:51 // @downloadURL none // ==/UserScript== (function(){ function get_href_url(url, href_str) { const u = new URL(url) if (href_str.match(/^https?:\/\//i)) { return href_str } else if (href_str.startsWith('/')) { return u.origin + href_str } else { return u.origin + (u.pathname == "/" ? "" : u.pathname) + "/" + href_str } } let active_link_ele = null function DownloadTip() { var div = document.createElement('div'); div.style.position = 'absolute'; // div.style.backgroundColor = '#333'; div.style.fontSize = '12px'; // div.style.transform = "0.5" var link = document.createElement('a'); link.textContent = '高速下载'; link.id = "download_tip" link.setAttribute("target","_blank") div.appendChild(link); div.style.position = 'absolute'; const thisobj = this link.addEventListener('mouseout', function() { console.log("inactive") thisobj.hide() }); link.addEventListener('mouseover', function(){ thisobj.active = true console.log("active") }) document.body.appendChild(div); this.show = function(url, x, y, height, ele){ setTimeout(function(){ if(ele != active_link_ele){ return } const listener = function(){ console.log("ele out") ele.removeEventListener("mouseout", listener) setTimeout(function(){ console.log("active", thisobj.active) if(!thisobj.active && active_link_ele == ele){ thisobj.hide() } },400) } ele.addEventListener("mouseout", listener) div.style.display = 'block'; div.style.left = x + 'px'; div.style.top = parseInt(y) - height + 'px'; link.href = "https://doget.nocsdn.com/?url=" + encodeURIComponent(url) this.is_show = true }, 500) } this.is_show = false this.active = false this.hide = function(){ div.style.display = 'none'; this.is_show = false this.active = false } } const download_tip = new DownloadTip() addEventListener("mouseover", (e)=>{ if(e.target && e.target.tagName == 'A' && e.target.id != "download_tip"){ const href = e.target.getAttribute("href"); if(href && href.trim() != ""){ active_link_ele = e.target const target_url = get_href_url(location.href, href) console.log(target_url, e.pageX, e.pageY) const rect = e.target.getClientRects()[0] download_tip.show(target_url, e.pageX, rect.top + window.scrollY, rect.height, e.target) } } }) })()