GitHub Files Icon Replacement

Replace GitHub file icons with Material icons

当前为 2024-12-25 提交的版本,查看 最新版本

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