Greasy Fork

Github 高速下载,文件加速下载(不限于Github,可根据需要修改match)

文件高速下载,可用于各种因为网络问题而下载慢的文件(不限于github),鼠标箭头悬停在下载链接0.5秒,即可显示高速下载按钮。

当前为 2023-11-07 提交的版本,查看 最新版本

// ==UserScript==
// @name        Github 高速下载,文件加速下载(不限于Github,可根据需要修改match)
// @namespace   Violentmonkey Scripts
// @match       *://github.com/*
// @description 文件高速下载,可用于各种因为网络问题而下载慢的文件(不限于github),鼠标箭头悬停在下载链接0.5秒,即可显示高速下载按钮。
// @grant       none
// @version     1.1
// @license MIT
// @author      -
// @description 2023/11/5 10:21:51
// ==/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() {
    // 创建一个DIV元素
    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中
    div.appendChild(link);

    // 设置DIV的样式
    div.style.position = 'absolute';
    const thisobj = this
    // 监听DIV的mouseout事件
    link.addEventListener('mouseout', function() {
      console.log("inactive")
      thisobj.hide()
    });
    link.addEventListener('mouseover', function(){
        thisobj.active = true
        console.log("active")
    })
    // 将DIV添加到文档的body中
    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)=>{
  let target = e.target
  while(target && (target.tagName != "A" && target.tagName != "BODY")){
    target = target.parentElement
  }

  if(target && target.tagName == 'A' && target.id != "download_tip"){
          const href = target.getAttribute("href");
          if(href && href.trim() != ""){
            active_link_ele = target
            const target_url = get_href_url(location.href, href)
              console.log(target_url, e.pageX, e.pageY)
              const rect = target.getClientRects()[0]
              download_tip.show(target_url, e.pageX, rect.top + window.scrollY, rect.height, target)
          }
   }
})
})()