// ==UserScript== // @name GitHub Fast // @namespace http://tampermonkey.net/ // @version 1.1 // @description 自动将 github.com 重定向到国内反代域名,并自动汉化页面 // @author You // @match *://github.com/* // @match *://www.github.com/* // @match *://raw.githubusercontent.com/* // @match *://gist.github.com/* // @match *://gh.072103.xyz/* // @match *://raw.gh.072103.xyz/* // @match *://gist.gh.072103.xyz/* // @grant GM_addStyle // @run-at document-start // ==/UserScript== (function() { 'use strict'; let currentUrl = window.location.href; let newUrl = currentUrl .replace('github.com', 'gh.072103.xyz') .replace('raw.githubusercontent.com', 'raw.gh.072103.xyz') .replace('gist.github.com', 'gist.gh.072103.xyz'); if (newUrl !== currentUrl) { window.location.replace(newUrl); return; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', translatePage); } else { translatePage(); } const observer = new MutationObserver(function(mutations) { translatePage(); }); window.addEventListener('load', function() { observer.observe(document.body, { childList: true, subtree: true }); }); const translations = { 'Pull requests': '拉取请求', 'Issues': '议题', 'Marketplace': '应用市场', 'Explore': '探索', 'Sponsors': '赞助', 'Settings': '设置', 'Sign out': '退出登录', 'Sign in': '登录', 'Sign up': '注册', 'Code': '代码', 'Actions': '操作', 'Projects': '项目', 'Wiki': '维基', 'Security': '安全', 'Insights': '统计', 'Settings': '设置', 'Fork': '复刻', 'Star': '星标', 'Watch': '关注', 'Unwatch': '取消关注', 'Unstar': '取消星标', 'Edit': '编辑', 'Delete': '删除', 'Create new file': '新建文件', 'Upload files': '上传文件', 'Find file': '查找文件', 'Clone': '克隆', 'Download ZIP': '下载 ZIP', 'Open with GitHub Desktop': '使用 GitHub Desktop 打开', 'Open in Visual Studio': '在 Visual Studio 中打开', 'Commits': '提交', 'Branches': '分支', 'Tags': '标签', 'Contributors': '贡献者', 'Compare': '比较', 'Commit': '提交', 'Commit changes': '提交更改', 'Cancel': '取消', 'Public': '公开', 'Private': '私有', 'Description': '描述', 'Website': '网站', 'Topics': '主题', 'License': '许可证', 'Releases': '发布', 'Packages': '包', 'Used by': '使用者', 'Contributors': '贡献者', 'Languages': '语言', 'README': '自述文件', 'Activity': '活动', 'Star this repository': '星标此仓库', 'Starred': '已加星标', 'Fork your own copy': '复刻你自己的副本', 'Code review': '代码审查', 'Integrations': '集成', 'GitHub Pages': 'GitHub 页面', 'Environments': '环境', 'Community': '社区', 'Notifications': '通知', 'About': '关于', 'Releases': '发布版本', 'Sponsor': '赞助', 'Used by': '使用者', 'Create repository': '创建仓库', 'Import repository': '导入仓库', 'New': '新建', 'View all': '查看全部', 'Search': '搜索', 'Search or jump to...': '搜索或跳转到...', 'Repository': '仓库', 'Organization': '组织', 'Repositories': '仓库', 'People': '用户', 'Teams': '团队', 'Billing': '账单', 'Security': '安全', 'Help': '帮助', 'Contact': '联系', 'API': '接口', 'Training': '培训', 'Blog': '博客', 'Status': '状态', 'Terms': '条款', 'Privacy': '隐私', 'Docs': '文档' }; function translatePage() { const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { const parent = node.parentElement; if (parent && (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE' || parent.tagName === 'CODE' || parent.tagName === 'PRE')) { return NodeFilter.FILTER_REJECT; } return NodeFilter.FILTER_ACCEPT; } } ); const textNodes = []; while (walker.nextNode()) { textNodes.push(walker.currentNode); } textNodes.forEach(node => { let text = node.textContent.trim(); if (text && translations[text]) { node.textContent = node.textContent.replace(text, translations[text]); } }); const elementsWithAttrs = document.querySelectorAll('[placeholder], [title], [aria-label]'); elementsWithAttrs.forEach(elem => { ['placeholder', 'title', 'aria-label'].forEach(attr => { const value = elem.getAttribute(attr); if (value && translations[value]) { elem.setAttribute(attr, translations[value]); } }); }); } GM_addStyle(` body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", "Microsoft YaHei", "微软雅黑", sans-serif !important; } `); })();