GitHub 實用工具

GitHub 實用工具,包括文件圖標替換和自動填充倉庫名

  1. // ==UserScript==
  2. // @name GitHub Utils
  3. // @name:vi Tiện ích GitHub
  4. // @name:zh-cn GitHub 实用工具
  5. // @name:zh-tw GitHub 實用工具
  6. // @name:ru Утилиты GitHub
  7. // @namespace http://tampermonkey.net/
  8. // @version 2024.12.30.1
  9. // @description GitHub utilities including file icons replacement and auto-fill repo name
  10. // @description:vi Tiện ích GitHub bao gồm thay thế biểu tượng tệp và tự động điền tên repo
  11. // @description:zh-cn GitHub 实用工具,包括文件图标替换和自动填充仓库名
  12. // @description:zh-tw GitHub 實用工具,包括文件圖標替換和自動填充倉庫名
  13. // @description:ru Утилиты GitHub, включая замену иконок файлов и автозаполнение имени репозитория
  14. // @author Yuusei
  15. // @match https://github.com/*
  16. // @icon https://github.githubassets.com/favicon.ico
  17. // @grant GM_addStyle
  18. // @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js
  19. // @run-at document-start
  20. // @license GPL-3.0-only
  21. // @compatible chrome
  22. // @compatible firefox
  23. // @compatible edge
  24. // @compatible safari
  25. // ==/UserScript==
  26. (function ($) {
  27. 'use strict';
  28. // Add custom styles
  29. GM_addStyle(`
  30. .material-icon {
  31. width: 20px;
  32. height: 20px;
  33. vertical-align: text-bottom;
  34. margin-right: 4px;
  35. transition: transform 0.2s ease;
  36. }
  37. .material-icon:hover {
  38. transform: scale(1.2);
  39. }
  40. @media (max-width: 768px) {
  41. .material-icon {
  42. width: 16px;
  43. height: 16px;
  44. margin-right: 2px;
  45. }
  46. }
  47. `);
  48. const iconMap = {
  49. // Development
  50. '.ts': 'typescript',
  51. '.tsx': 'react_ts',
  52. '.js': 'javascript',
  53. '.jsx': 'react',
  54. '.py': 'python',
  55. '.java': 'java',
  56. '.cpp': 'cpp',
  57. '.c': 'c',
  58. '.cs': 'csharp',
  59. '.go': 'go',
  60. '.rb': 'ruby',
  61. '.php': 'php',
  62. '.rs': 'rust',
  63. '.swift': 'swift',
  64. '.kt': 'kotlin',
  65. '.scala': 'scala',
  66. '.dart': 'dart',
  67. '.lua': 'lua',
  68. '.r': 'r',
  69. '.sh': 'console',
  70. '.ps1': 'powershell',
  71. '.bat': 'console',
  72. '.cmd': 'console',
  73. '.wasm': 'assembly',
  74. '.code-workspace': 'vscode',
  75. '.sln': 'visualstudio',
  76. // Web
  77. '.html': 'html',
  78. '.htm': 'html',
  79. '.css': 'css',
  80. '.scss': 'sass',
  81. '.sass': 'sass',
  82. '.less': 'less',
  83. '.styl': 'stylus',
  84. '.vue': 'vue',
  85. '.svelte': 'svelte',
  86. '.angular': 'angular',
  87. // Data & Config
  88. '.json': 'json',
  89. '.yml': 'yaml',
  90. '.yaml': 'yaml',
  91. '.xml': 'xml',
  92. '.toml': 'settings',
  93. '.ini': 'settings',
  94. '.env': 'tune',
  95. '.conf': 'settings',
  96. '.sql': 'database',
  97. '.db': 'database',
  98. '.sqlite': 'database',
  99. '.graphql': 'graphql',
  100. '.proto': 'protobuf',
  101. // Documentation
  102. '.md': 'markdown',
  103. '.mdx': 'markdown',
  104. '.txt': 'document',
  105. '.pdf': 'pdf',
  106. '.doc': 'word',
  107. '.docx': 'word',
  108. '.odt': 'document',
  109. '.rtf': 'document',
  110. // Images
  111. '.svg': 'svg',
  112. '.png': 'image',
  113. '.jpg': 'image',
  114. '.jpeg': 'image',
  115. '.gif': 'image',
  116. '.ico': 'image',
  117. '.webp': 'image',
  118. '.bmp': 'image',
  119. // Media
  120. '.mp3': 'audio',
  121. '.wav': 'audio',
  122. '.ogg': 'audio',
  123. '.mp4': 'video',
  124. '.webm': 'video',
  125. '.avi': 'video',
  126. '.mov': 'video',
  127. // Archives
  128. '.zip': 'zip',
  129. '.rar': 'zip',
  130. '.7z': 'zip',
  131. '.tar': 'zip',
  132. '.gz': 'zip',
  133. '.bz2': 'zip',
  134. // System
  135. '.exe': 'exe',
  136. '.dll': 'dll',
  137. '.so': 'lib',
  138. '.dylib': 'lib',
  139. '.sys': 'windows',
  140. '.reg': 'windows',
  141. // Design
  142. '.fig': 'figma',
  143. '.sketch': 'sketch',
  144. '.ai': 'illustrator',
  145. '.psd': 'photoshop',
  146. '.xd': 'xd',
  147. // 3D & Game
  148. '.unity': 'unity',
  149. '.blend': 'blender',
  150. '.fbx': '3d',
  151. '.obj': '3d',
  152. '.gltf': '3d',
  153. '.uasset': 'unreal',
  154. '.upk': 'unreal',
  155. // Mobile
  156. '.apk': 'android',
  157. '.ipa': 'apple',
  158. '.xcodeproj': 'xcode',
  159. '.pbxproj': 'xcode',
  160. // Container & Cloud
  161. Dockerfile: 'docker',
  162. '.dockerignore': 'docker',
  163. '.tf': 'terraform',
  164. '.tfvars': 'terraform',
  165. '.vagrant': 'vagrant',
  166. '.helm': 'kubernetes',
  167. };
  168. const specialFiles = {
  169. // Package managers
  170. 'package.json': 'nodejs',
  171. 'package-lock.json': 'nodejs',
  172. 'yarn.lock': 'yarn',
  173. 'pnpm-lock.yaml': 'pnpm',
  174. 'bun.lockb': 'bun',
  175. 'composer.json': 'composer',
  176. 'composer.lock': 'composer',
  177. Gemfile: 'ruby',
  178. 'Gemfile.lock': 'ruby',
  179. 'requirements.txt': 'python',
  180. 'poetry.lock': 'python',
  181. 'Cargo.toml': 'rust',
  182. 'Cargo.lock': 'rust',
  183. // Config files
  184. 'tsconfig.json': 'typescript',
  185. '.eslintrc': 'eslint',
  186. '.prettierrc': 'prettier',
  187. '.editorconfig': 'editorconfig',
  188. 'webpack.config.js': 'webpack',
  189. 'vite.config.js': 'vite',
  190. 'rollup.config.js': 'rollup',
  191. 'babel.config.js': 'babel',
  192. 'jest.config.js': 'jest',
  193. 'karma.conf.js': 'karma',
  194. 'cypress.config.js': 'cypress',
  195. 'playwright.config.js': 'playwright',
  196. // Documentation
  197. 'README.md': 'markdown',
  198. LICENSE: 'certificate',
  199. 'CHANGELOG.md': 'markdown',
  200. 'CONTRIBUTING.md': 'markdown',
  201. // Git
  202. '.gitignore': 'git',
  203. '.gitattributes': 'git',
  204. '.gitmodules': 'git',
  205. '.gitmessage': 'git',
  206. '.gitkeep': 'git',
  207. // CI/CD
  208. '.travis.yml': 'travis',
  209. '.gitlab-ci.yml': 'gitlab',
  210. Jenkinsfile: 'jenkins',
  211. 'azure-pipelines.yml': 'azure',
  212. 'bitbucket-pipelines.yml': 'bitbucket',
  213. // Docker
  214. Dockerfile: 'docker',
  215. 'docker-compose.yml': 'docker',
  216. 'docker-compose.yaml': 'docker',
  217. 'docker-compose.override.yml': 'docker',
  218. // Framework configs
  219. 'angular.json': 'angular',
  220. 'next.config.js': 'next',
  221. 'nuxt.config.js': 'nuxt',
  222. 'svelte.config.js': 'svelte',
  223. 'capacitor.config.json': 'capacitor',
  224. 'ionic.config.json': 'ionic',
  225. // Build tools
  226. Makefile: 'makefile',
  227. 'CMakeLists.txt': 'cmake',
  228. 'build.gradle': 'gradle',
  229. 'pom.xml': 'maven',
  230. 'build.sbt': 'sbt',
  231. // Environment
  232. '.env': 'tune',
  233. '.env.local': 'tune',
  234. '.env.development': 'tune',
  235. '.env.production': 'tune',
  236. '.env.test': 'tune',
  237. // Version managers
  238. '.nvmrc': 'nodejs',
  239. '.node-version': 'nodejs',
  240. '.ruby-version': 'ruby',
  241. '.python-version': 'python',
  242. '.java-version': 'java',
  243. };
  244. function replaceIcons() {
  245. $('.react-directory-row-name-cell-large-screen, .react-directory-row-name-cell-small-screen').each(function () {
  246. const $filenameElement = $(this).find('.react-directory-filename-cell');
  247. if ($filenameElement.length) {
  248. const filename = $filenameElement.text();
  249. let iconName = specialFiles[filename];
  250. if (!iconName) {
  251. const extension = Object.keys(iconMap).find(ext => filename.toLowerCase().endsWith(ext));
  252. iconName = extension ? iconMap[extension] : null;
  253. }
  254. if (iconName) {
  255. const $oldSvg = $(this).find('svg');
  256. if ($oldSvg.length) {
  257. const $newIcon = $('<img>', {
  258. src: `https://raw.githubusercontent.com/material-extensions/vscode-material-icon-theme/refs/heads/main/icons/${iconName}.svg`,
  259. class: 'material-icon',
  260. alt: iconName,
  261. });
  262. $oldSvg.replaceWith($newIcon);
  263. }
  264. }
  265. }
  266. });
  267. }
  268. // Auto fill repo name functionality
  269. function setupAutoFill() {
  270. const observer = new MutationObserver(mutations => {
  271. mutations.forEach(mutation => {
  272. if (mutation.addedNodes.length) {
  273. const dialog = document.querySelector('#repo-delete-menu-dialog');
  274. if (dialog) {
  275. const repoName = document.querySelector('.text-bold.f3.mt-2')?.textContent.trim();
  276. if (repoName) {
  277. const input = document.querySelector('#verification_field');
  278. if (input) {
  279. input.value = repoName;
  280. input.dispatchEvent(
  281. new Event('input', {
  282. bubbles: true,
  283. cancelable: true,
  284. })
  285. );
  286. }
  287.  
  288. const deleteBtn = document.querySelector('#repo-delete-proceed-button');
  289. if (deleteBtn) {
  290. deleteBtn.disabled = false;
  291. }
  292. }
  293. }
  294. }
  295. });
  296. });
  297.  
  298. observer.observe(document.body, {
  299. childList: true,
  300. subtree: true,
  301. });
  302. }
  303. // Initial setup
  304. $(document).ready(() => {
  305. replaceIcons();
  306. setupAutoFill();
  307. });
  308. // Watch for DOM changes for icon replacement
  309. const iconObserver = new MutationObserver(replaceIcons);
  310. iconObserver.observe(document.body, {
  311. childList: true,
  312. subtree: true,
  313. });
  314. })(jQuery);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址