// ==UserScript== // @name GitHub镜像 // @name:en GitHub Mirror // @description GitHub镜像,加速访问GitHub,支持Clone、Release、Raw、Zip加速。 // @description:en GitHub mirror. Accelerate access to GitHub. Support Clone, Release, RAW and ZIP acceleration. // @namespace https://github.com/HaleShaw // @version 1.0.0 // @author HaleShaw // @copyright 2021+, HaleShaw (https://github.com/HaleShaw) // @license AGPL-3.0-or-later // @homepage https://github.com/HaleShaw/TM-GitHubMirror // @supportURL https://github.com/HaleShaw/TM-GitHubMirror/issues // @contributionURL https://www.jianwudao.com/ // @icon https://github.githubassets.com/favicon.ico // @require https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js // @include *://github.com/* // @include *://github* // @compatible Chrome // @run-at document-end // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @downloadURL none // ==/UserScript== // ==OpenUserJS== // @author HaleShaw // @collaborator HaleShaw // ==/OpenUserJS== (function () { ('use strict'); const style = ` /* The menu container */ .menuContainer { width: 600px; } .menuBlock { padding: 4px 0; color: #990000; } .menuLeftIcon{ margin-right:5px; } .menuButtonLabel{ margin-right: 2rem; } .menuButtonCheck{ vertical-align: text-bottom; margin: 0 3px; } .clone { padding-left: 0 !important; width: calc(100% - 21px) !important; } `; const mirrors = [ { id: 0, name: 'CnpmJS', url: 'https://github.com.cnpmjs.org', description: 'cnpmjs.org' }, { id: 1, name: 'FastGit', url: 'https://hub.fastgit.org', description: 'KevinZonda' }, { id: 2, name: 'FastGit', url: 'https://download.fastgit.org', description: 'KevinZonda' }, { id: 3, name: 'wuyanzheshui', url: 'https://github.wuyanzheshui.workers.dev', description: 'wuyanzheshui,每日10万次调用上限' }, { id: 4, name: 'RC1844', url: 'https://github.rc1844.workers.dev', description: 'RC1844,每日10万次调用上限' }, { id: 5, name: 'jsDelivr', url: 'https://cdn.jsdelivr.net/gh', description: '项目当前分支总文件大小不可超过50MB' }, { id: 6, name: 'IAPK', url: 'https://github.iapk.cc', description: 'IAPK工具箱,Github下载器' }, { id: 7, name: 'Ecalose', url: 'https://gh.haval.gq', description: 'Ecalose,每日10万次调用上限' }, { id: 8, name: 'IAPK', url: 'https://iapk.cc/github?url=https://github.com', description: 'IAPK工具箱,Github下载器' } ]; //添加对应索引即可使用 const cloneSet = [0, 1, 3]; const browseSet = [0, 1, 3, 4, 6, 7]; const downloadSet = [2, 3, 4, 7, 8]; const rawSet = [3, 4, 7, 8]; const messages = { en: { menuButton: { name: 'CloneMirror', title: 'Open List', header: 'Quickly clone and Mirror sites', block: 'Please do not login in the mirror site. I will not be responsible for any loss caused by this.' } }, zh: { menuButton: { name: '克隆与镜像', title: '打开列表', header: '快速克隆与镜像站点', block: '请不要在镜像网站登录账号,若因此造成任何损失本人概不负责' } } }; const icons = { closeIcon: ` `, copyIcon: ` `, commandIcon: ` `, linkIcon: ` ` }; const clonePrefix = 'git clone '; const depthPrefix = '--depth=1 '; let message; let settingHtml; main(); function main() { GM_addStyle(style); logInfo(GM_info.script.name, GM_info.script.version); initSetting(); message = getMessage(true, true); settingHtml = getSettingHtml(); let info = getMenuButtonPrefix() + getCloneList() + getBrowseList() + getMenuButtonSuffix(); $('h1.flex-wrap.break-word.text-normal').append(info); } /** * Initialize setting. */ function initSetting() { let lang = GM_getValue('lang'); let clone = GM_getValue('clone'); let depth = GM_getValue('depth'); if (lang == undefined) { GM_setValue('lang', 'zh'); } if (clone == undefined) { GM_setValue('clone', true); } if (depth == undefined) { GM_setValue('depth', true); } } function getMenuButtonPrefix() { return `
`; } /** * Get the clone command prefix. */ function getClonePrefix() { let prefix = ''; let clone = GM_getValue('clone'); let depth = GM_getValue('depth'); if (clone) { prefix += 'git clone '; } if (depth) { prefix += '--depth=1 '; } return prefix; } /** * Get the clone button html string. * @param {String} url url. * @param {tip} tip tip. */ function getCloneHtml(url, tip) { return `