Github mirror homepage tranverse

在Github官网和镜像网站进行转换 Generate a button to trans between GitHub homepage and mirror

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Github mirror homepage tranverse
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  在Github官网和镜像网站进行转换 Generate a button to trans between GitHub homepage and mirror
// @author       HuanZhi
// @match        https://github.com/*
// @match        https://hub.fgit.cf/*
// @match        https://huggingface.co/*
// @match        https://hf-mirror.com/*
// @grant        unsafewindow
// @license      MIT
// @run-at       document-start
// ==/UserScript==
(function(){
    var btn = document.createElement("button");
    btn.setAttribute('style', "position:absolute; z-index:1000; right:15px; top:55px; height:28px; background-color:#3E8CD0; border:none; color:white; font-size:16px; cursor:pointer; border-radius:1em;");
    btn.setAttribute('id', "btn");
    document.body.appendChild(btn);
    btn.onmouseover = function() {
        this.style.backgroundColor="#e9686b"
    };
    btn.onmouseout = function() {
        this.style.backgroundColor="#3E8CD0"
    };
    
    var url = window.location.href;
    if (url.includes("github")) {
        btn.innerText = "当前原始网站";
        btn.onclick=JumpToGitMirror;
    } else if (url.includes("hub.fgit.cf")) {
        btn.innerText = "当前镜像网站,别登录账号";
        btn.onclick=JumpToGitOrigin;
    } else if (url.includes("huggingface")) {
        btn.innerText = "当前原始网站";
        btn.onclick=JumpToHugMirror;
    } else if (url.includes("hf-mirror")) {
        btn.innerText = "当前镜像网站,别登录账号";
        btn.onclick=JumpToHugOrigin;
    }
}
)()

function JumpToGitMirror(){
    var home_url = window.location.href.replace('https://github.com', 'https://hub.fgit.cf');
    window.open(home_url);
}

function JumpToGitOrigin(){
    var home_url = window.location.href.replace('https://hub.fgit.cf', 'https://github.com');
    window.open(home_url);
}

function JumpToHugMirror(){
    var home_url = window.location.href.replace('https://huggingface.co', 'https://hf-mirror.com');
    window.open(home_url);
}

function JumpToHugOrigin(){
    var home_url = window.location.href.replace('https://hf-mirror.com', 'https://huggingface.co');
    window.open(home_url);
}