// ==UserScript== // @name HF 镜像跳转 // @name:en HF Mirror Redirect // @namespace https://github.com/zhzLuke96/hf-links/hf-links // @version v1.0 // @description 在 Hugging Face 仓库页面添加镜像跳转按钮 // @description:en Add mirror redirect buttons on Hugging Face repository pages. // @author zhzluke96 // @match https://huggingface.co/* // @icon https://www.google.com/s2/favicons?sz=64&domain=huggingface.co // @grant none // @license MIT // @supportURL https://github.com/zhzLuke96/hf-links/hf-links/issues // @downloadURL none // ==/UserScript== (function () { "use strict"; const exit = (message, code = 0) => console.log(`[hf-links|${code}] ${message}`); /** * @type {typeof document.querySelector} */ const $ = document.querySelector.bind(document); const $header = $( "body > div > main > div.SVELTE_HYDRATER.contents > header > div > h1" ); if (!$header) { exit("没找到header"); return; } const frag = document.createDocumentFragment(); const div = document.createElement("div"); frag.appendChild(div); const build = (html) => { div.innerHTML = html; const elem = div.firstElementChild; div.innerHTML = ""; return elem; }; const Button = ({ text, icon, onClick }) => { const elem = build(`