GitHub Files Icon Replacement

Replace GitHub file icons with material icons

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

  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.24.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 none
  18. // @run-at document-start
  19. // @license GPL-3.0-only
  20. // @compatible chrome
  21. // @compatible firefox
  22. // @compatible edge
  23. // ==/UserScript==
  24.  
  25. (function () {
  26. 'use strict';
  27.  
  28. function replaceIcons() {
  29. const fileElements = document.querySelectorAll('.react-directory-row-name-cell-large-screen');
  30.  
  31. fileElements.forEach(element => {
  32. const filenameElement = element.querySelector('.react-directory-filename-cell');
  33. if (filenameElement) {
  34. const filename = filenameElement.textContent;
  35. let iconName = '';
  36.  
  37. const iconMap = {
  38. '.ts': 'typescript',
  39. '.json': 'json',
  40. '.yml': 'yaml',
  41. '.yaml': 'yaml',
  42. '.js': 'javascript',
  43. '.html': 'html',
  44. '.css': 'css',
  45. '.py': 'python',
  46. '.php': 'php',
  47. '.md': 'markdown',
  48. '.lua': 'lua',
  49. '.npm': 'npm',
  50. '.lock': 'npm',
  51. '.svg': 'svg',
  52. '.xml': 'xml',
  53. '.txt': 'document',
  54. '.vue': 'vue',
  55. '.angular': 'angular',
  56. '.gitignore': 'git',
  57. '.git': 'git',
  58. '.jsx': 'react',
  59. '.tsx': 'react_ts',
  60. '.scss': 'sass',
  61. '.sass': 'sass',
  62. '.less': 'less',
  63. '.fish': 'shell',
  64. '.c': 'c',
  65. '.cpp': 'cpp',
  66. '.cs': 'csharp',
  67. '.go': 'go',
  68. '.rs': 'rust',
  69. '.rb': 'ruby',
  70. '.java': 'java',
  71. '.kt': 'kotlin',
  72. '.kts': 'kotlin',
  73. '.swift': 'swift',
  74. '.dart': 'dart',
  75. '.sql': 'database',
  76. '.db': 'database',
  77. '.env': 'tune',
  78. '.docker': 'docker',
  79. '.dockerfile': 'docker',
  80. '.exe': 'exe',
  81. '.png': 'image',
  82. '.jpg': 'image',
  83. '.jpeg': 'image',
  84. '.gif': 'image',
  85. '.ico': 'image',
  86. '.webp': 'image',
  87. '.bmp': 'image',
  88. '.tiff': 'image',
  89. '.mp3': 'audio',
  90. '.wav': 'audio',
  91. '.mp4': 'video',
  92. '.mov': 'video',
  93. '.avi': 'video',
  94. '.ini': 'settings',
  95. '.config': 'settings',
  96. '.toml': 'settings',
  97. '.gradle': 'gradle',
  98. '.jar': 'java',
  99. '.class': 'java',
  100. '.properties': 'settings',
  101. '.r': 'r',
  102. '.rmd': 'r',
  103. '.scala': 'scala',
  104. '.groovy': 'groovy',
  105. '.pl': 'perl',
  106. '.pm': 'perl',
  107. '.h': 'c',
  108. '.hpp': 'cpp',
  109. '.hxx': 'cpp',
  110. '.m': 'objectivec',
  111. '.mm': 'objectivec',
  112. '.swift': 'swift',
  113. '.f': 'fortran',
  114. '.f90': 'fortran',
  115. '.f95': 'fortran',
  116. '.mat': 'matlab',
  117. '.coffee': 'coffeescript',
  118. '.litcoffee': 'coffeescript',
  119. '.elm': 'elm',
  120. '.ex': 'elixir',
  121. '.exs': 'elixir',
  122. '.erl': 'erlang',
  123. '.hrl': 'erlang',
  124. '.clj': 'clojure',
  125. '.cljs': 'clojure',
  126. '.fs': 'fsharp',
  127. '.fsx': 'fsharp',
  128. '.hs': 'haskell',
  129. '.lhs': 'haskell',
  130. '.ml': 'ocaml',
  131. '.mli': 'ocaml',
  132. '.pp': 'puppet',
  133. '.tf': 'terraform',
  134. '.tfvars': 'terraform',
  135. '.sol': 'solidity',
  136. '.proto': 'protobuf',
  137. '.graphql': 'graphql',
  138. '.haml': 'haml',
  139. '.slim': 'slim',
  140. '.erb': 'erb',
  141. '.jade': 'pug',
  142. '.pug': 'pug',
  143. '.styl': 'stylus',
  144. '.nix': 'nix',
  145. '.vim': 'vim',
  146. '.bat': 'console',
  147. '.cmd': 'console',
  148. '.dll': 'dll',
  149. '.so': 'lib',
  150. '.a': 'lib',
  151. '.dylib': 'lib',
  152. '.zip': 'zip',
  153. '.rar': 'zip',
  154. '.7z': 'zip',
  155. '.tar': 'zip',
  156. '.gz': 'zip',
  157. '.bz2': 'zip',
  158. '.xz': 'zip',
  159. '.pdf': 'pdf',
  160. '.doc': 'word',
  161. '.docx': 'word',
  162. '.ppt': 'powerpoint',
  163. '.pptx': 'powerpoint',
  164. '.odt': 'document',
  165. '.fig': 'figma',
  166. '.xd': 'xd',
  167. '.ai': 'illustrator',
  168. '.psd': 'photoshop',
  169. '.blend': 'blender',
  170. '.fbx': '3d',
  171. '.obj': '3d',
  172. '.stl': '3d',
  173. '.3ds': '3d',
  174. '.max': '3d',
  175. '.maya': '3d',
  176. '.shader': 'shader',
  177. '.glsl': 'shader',
  178. '.vert': 'shader',
  179. '.frag': 'shader',
  180. '.wasm': 'assembly',
  181. '.wat': 'assembly',
  182. '.asm': 'assembly',
  183. '.s': 'assembly',
  184. '.ko': 'linux',
  185. '.deb': 'debian',
  186. '.rpm': 'redhat',
  187. '.apk': 'android',
  188. '.ipa': 'apple',
  189. '.dmg': 'apple',
  190. '.pkg': 'apple',
  191. '.app': 'apple',
  192. '.pas': 'pascal',
  193. '.cobol': 'cobol',
  194. '.ada': 'ada',
  195. '.lisp': 'lisp',
  196. '.scm': 'scheme',
  197. '.rkt': 'racket',
  198. '.prolog': 'prolog',
  199. '.forth': 'forth',
  200. '.apl': 'apl',
  201. '.basic': 'basic',
  202. '.d': 'd',
  203. '.nim': 'nim',
  204. '.crystal': 'crystal',
  205. '.julia': 'julia',
  206. '.io': 'io',
  207. '.tcl': 'tcl',
  208. '.zig': 'zig',
  209. '.v': 'v',
  210. '.odin': 'odin',
  211. '.haxe': 'haxe',
  212. '.idl': 'idl',
  213. '.hack': 'hack',
  214. '.pike': 'pike',
  215. '.eiffel': 'eiffel',
  216. '.smalltalk': 'smalltalk',
  217. '.modula': 'modula',
  218. '.algol': 'algol',
  219. '.bf': 'brainfuck',
  220. '.awk': 'awk',
  221. '.sed': 'sed',
  222. '.perl6': 'perl6',
  223. '.raku': 'perl6',
  224. '.jl': 'julia',
  225. '.cr': 'crystal',
  226. '.factor': 'factor',
  227. '.idr': 'idris',
  228. '.agda': 'agda',
  229. '.lean': 'lean',
  230. '.curry': 'curry',
  231. '.mercury': 'mercury',
  232. '.clean': 'clean',
  233. '.oz': 'oz',
  234. '.sml': 'sml',
  235. '.vhdl': 'vhdl',
  236. '.verilog': 'verilog',
  237. '.ceylon': 'ceylon',
  238. '.red': 'red',
  239. '.rebol': 'rebol',
  240. '.io': 'io',
  241. '.j': 'j',
  242. '.k': 'k',
  243. '.q': 'q',
  244. '.pure': 'pure',
  245. '.ur': 'ur',
  246. '.fstar': 'fstar',
  247. '.coq': 'coq',
  248. '.isabelle': 'isabelle',
  249. '.hol': 'hol',
  250. '.mizar': 'mizar',
  251. '.twelf': 'twelf',
  252. '.maude': 'maude',
  253. '.alloy': 'alloy',
  254. '.tla': 'tla',
  255. '.z3': 'z3',
  256. '.smt': 'smt',
  257. '.why3': 'why3',
  258. '.acl2': 'acl2',
  259. '.pvs': 'pvs',
  260. '.nuprl': 'nuprl',
  261. '.lego': 'lego',
  262. '.ats': 'ats',
  263. '.idris2': 'idris2',
  264. '.dhall': 'dhall',
  265. '.unison': 'unison',
  266. '.koka': 'koka',
  267. '.grain': 'grain',
  268. '.gleam': 'gleam',
  269. '.roc': 'roc',
  270. '.vale': 'vale',
  271. '.lobster': 'lobster',
  272. '.wren': 'wren',
  273. '.gravity': 'gravity',
  274. '.virgil': 'virgil',
  275. '.gluon': 'gluon',
  276. '.felix': 'felix',
  277. '.clay': 'clay',
  278. '.kitten': 'kitten',
  279. '.pony': 'pony',
  280. '.reason': 'reason',
  281. '.purescript': 'purescript',
  282. '.elm': 'elm',
  283. '.imba': 'imba',
  284. '.mint': 'mint',
  285. '.grain': 'grain',
  286. '.beef': 'beef',
  287. '.zig': 'zig',
  288. '.vlang': 'vlang',
  289. '.odin': 'odin',
  290. '.carbon': 'carbon',
  291. '.mojo': 'mojo',
  292. '.val': 'val',
  293. '.hare': 'hare',
  294. '.ante': 'ante',
  295. '.kind': 'kind',
  296. '.dafny': 'dafny',
  297. '.bosque': 'bosque',
  298. '.keli': 'keli',
  299. '.gno': 'gno',
  300. '.jakt': 'jakt',
  301. '.hylo': 'hylo',
  302. '.inko': 'inko',
  303. '.nickel': 'nickel',
  304. '.pikelet': 'pikelet',
  305. '.sixten': 'sixten',
  306. '.skip': 'skip',
  307. '.spiral': 'spiral',
  308. '.verse': 'verse',
  309. '.wyvern': 'wyvern',
  310. '.zephyr': 'zephyr'
  311. };
  312.  
  313. const specialFiles = {
  314. 'package.json': 'nodejs',
  315. 'README.md': 'markdown',
  316. 'LICENSE': 'certificate',
  317. '.prettierignore': 'prettier',
  318. '.prettierrc': 'prettier',
  319. '.eslintignore': 'eslint',
  320. '.eslintrc.cjs': 'eslint',
  321. '.eslintrc.js': 'eslint',
  322. '.eslintrc.json': 'eslint',
  323. '.eslintrc.yml': 'eslint',
  324. 'docker-compose.yml': 'docker',
  325. 'Dockerfile': 'docker',
  326. '.dockerignore': 'docker',
  327. '.env.local': 'tune',
  328. '.env.development': 'tune',
  329. '.env.production': 'tune',
  330. '.env.test': 'tune',
  331. '.env.staging': 'tune',
  332. 'tsconfig.json': 'typescript',
  333. 'webpack.config.js': 'webpack',
  334. 'babel.config.js': 'babel',
  335. 'jest.config.js': 'jest',
  336. 'angular.json': 'angular',
  337. 'next.config.js': 'next',
  338. 'nuxt.config.js': 'nuxt',
  339. 'vite.config.js': 'vite',
  340. 'rollup.config.js': 'rollup',
  341. 'svelte.config.js': 'svelte',
  342. 'tailwind.config.js': 'tailwind',
  343. 'postcss.config.js': 'postcss',
  344. 'composer.json': 'composer',
  345. 'composer.lock': 'composer',
  346. 'Gemfile': 'ruby',
  347. 'Gemfile.lock': 'ruby',
  348. 'requirements.txt': 'python',
  349. 'poetry.lock': 'python',
  350. 'pyproject.toml': 'python',
  351. 'Cargo.toml': 'rust',
  352. 'Cargo.lock': 'rust',
  353. 'go.mod': 'go',
  354. 'go.sum': 'go',
  355. 'mix.exs': 'elixir',
  356. 'rebar.config': 'erlang',
  357. 'stack.yaml': 'haskell',
  358. 'cabal.project': 'haskell',
  359. 'dune-project': 'ocaml',
  360. 'opam': 'ocaml',
  361. 'Rakefile': 'ruby',
  362. 'Makefile': 'makefile',
  363. 'CMakeLists.txt': 'cmake',
  364. 'build.gradle': 'gradle',
  365. 'pom.xml': 'maven',
  366. 'build.sbt': 'sbt',
  367. 'mix.lock': 'elixir',
  368. 'elm.json': 'elm',
  369. 'browserslist': 'browserslist',
  370. '.babelrc': 'babel',
  371. '.travis.yml': 'travis',
  372. 'circle.yml': 'circleci',
  373. 'jenkins.yml': 'jenkins',
  374. 'kubernetes.yml': 'kubernetes',
  375. 'nginx.conf': 'nginx',
  376. 'apache.conf': 'apache',
  377. '.gitattributes': 'git',
  378. '.gitmodules': 'git',
  379. '.gitlab-ci.yml': 'gitlab',
  380. 'bitbucket-pipelines.yml': 'bitbucket',
  381. 'azure-pipelines.yml': 'azure',
  382. 'Jenkinsfile': 'jenkins',
  383. 'sonar-project.properties': 'sonarqube',
  384. 'phpunit.xml': 'phpunit',
  385. 'karma.conf.js': 'karma',
  386. 'cypress.json': 'cypress',
  387. 'playwright.config.js': 'playwright',
  388. 'selenium.config.js': 'selenium',
  389. 'docker-compose.override.yml': 'docker',
  390. 'docker-compose.prod.yml': 'docker',
  391. 'docker-compose.dev.yml': 'docker',
  392. 'Procfile': 'heroku',
  393. 'vercel.json': 'vercel',
  394. 'netlify.toml': 'netlify',
  395. 'firebase.json': 'firebase',
  396. 'now.json': 'zeit',
  397. 'pm2.config.js': 'pm2',
  398. 'nodemon.json': 'nodemon',
  399. 'lerna.json': 'lerna',
  400. 'nx.json': 'nx',
  401. 'rush.json': 'rush',
  402. 'yarn.lock': 'yarn',
  403. 'pnpm-lock.yaml': 'pnpm',
  404. 'bun.lockb': 'bun',
  405. 'deno.json': 'deno',
  406. 'rome.json': 'rome',
  407. 'prettier.config.js': 'prettier',
  408. 'stylelint.config.js': 'stylelint',
  409. 'commitlint.config.js': 'commitlint',
  410. 'lint-staged.config.js': 'lint-staged',
  411. 'husky.config.js': 'husky',
  412. '.huskyrc': 'husky',
  413. '.lintstagedrc': 'lint-staged',
  414. '.commitlintrc': 'commitlint',
  415. '.stylelintrc': 'stylelint',
  416. '.prettierrc.js': 'prettier',
  417. '.eslintrc': 'eslint',
  418. '.browserslistrc': 'browserslist',
  419. '.npmrc': 'npm',
  420. '.yarnrc': 'yarn',
  421. '.nvmrc': 'nodejs',
  422. '.node-version': 'nodejs',
  423. '.ruby-version': 'ruby',
  424. '.python-version': 'python',
  425. '.tool-versions': 'asdf',
  426. '.editorconfig': 'editorconfig',
  427. '.mailmap': 'email',
  428. '.gitmessage': 'git',
  429. '.gitkeep': 'git',
  430. 'brainfuck.config': 'brainfuck',
  431. 'awk.config': 'awk',
  432. 'sed.config': 'sed',
  433. 'perl6.config': 'perl6',
  434. 'raku.config': 'perl6',
  435. 'julia.config': 'julia',
  436. 'crystal.config': 'crystal',
  437. 'factor.config': 'factor',
  438. 'idris.config': 'idris',
  439. 'agda.config': 'agda',
  440. 'lean.config': 'lean',
  441. 'curry.config': 'curry',
  442. 'mercury.config': 'mercury',
  443. 'clean.config': 'clean',
  444. 'oz.config': 'oz',
  445. 'sml.config': 'sml',
  446. 'vhdl.config': 'vhdl',
  447. 'verilog.config': 'verilog',
  448. 'ceylon.config': 'ceylon',
  449. 'red.config': 'red',
  450. 'rebol.config': 'rebol',
  451. 'io.config': 'io',
  452. 'j.config': 'j',
  453. 'k.config': 'k',
  454. 'q.config': 'q',
  455. 'pure.config': 'pure',
  456. 'ur.config': 'ur',
  457. 'fstar.config': 'fstar',
  458. 'coq.config': 'coq',
  459. 'isabelle.config': 'isabelle',
  460. 'hol.config': 'hol',
  461. 'mizar.config': 'mizar',
  462. 'twelf.config': 'twelf',
  463. 'maude.config': 'maude',
  464. 'alloy.config': 'alloy',
  465. 'tla.config': 'tla',
  466. 'z3.config': 'z3',
  467. 'smt.config': 'smt',
  468. 'why3.config': 'why3',
  469. 'acl2.config': 'acl2',
  470. 'pvs.config': 'pvs',
  471. 'nuprl.config': 'nuprl',
  472. 'lego.config': 'lego',
  473. 'ats.config': 'ats',
  474. 'idris2.config': 'idris2',
  475. 'dhall.config': 'dhall',
  476. 'unison.config': 'unison',
  477. 'koka.config': 'koka',
  478. 'grain.config': 'grain',
  479. 'gleam.config': 'gleam',
  480. 'roc.config': 'roc',
  481. 'vale.config': 'vale',
  482. 'lobster.config': 'lobster',
  483. 'wren.config': 'wren',
  484. 'gravity.config': 'gravity',
  485. 'virgil.config': 'virgil',
  486. 'gluon.config': 'gluon',
  487. 'felix.config': 'felix',
  488. 'clay.config': 'clay',
  489. 'kitten.config': 'kitten',
  490. 'pony.config': 'pony',
  491. 'reason.config': 'reason',
  492. 'purescript.config': 'purescript',
  493. 'elm.config': 'elm',
  494. 'imba.config': 'imba',
  495. 'mint.config': 'mint',
  496. 'grain.config': 'grain',
  497. 'beef.config': 'beef',
  498. 'zig.config': 'zig',
  499. 'vlang.config': 'vlang',
  500. 'odin.config': 'odin',
  501. 'carbon.config': 'carbon',
  502. 'mojo.config': 'mojo',
  503. 'val.config': 'val',
  504. 'hare.config': 'hare',
  505. 'ante.config': 'ante',
  506. 'kind.config': 'kind',
  507. 'dafny.config': 'dafny',
  508. 'bosque.config': 'bosque',
  509. 'keli.config': 'keli',
  510. 'gno.config': 'gno',
  511. 'jakt.config': 'jakt',
  512. 'hylo.config': 'hylo',
  513. 'inko.config': 'inko',
  514. 'nickel.config': 'nickel',
  515. 'pikelet.config': 'pikelet',
  516. 'sixten.config': 'sixten',
  517. 'skip.config': 'skip',
  518. 'spiral.config': 'spiral',
  519. 'verse.config': 'verse',
  520. 'wyvern.config': 'wyvern',
  521. 'zephyr.config': 'zephyr'
  522. };
  523.  
  524. iconName = specialFiles[filename] || Object.entries(iconMap).find(([ext]) => filename.toLowerCase().endsWith(ext))?.[1];
  525.  
  526. if (iconName) {
  527. const oldSvg = element.querySelector('svg');
  528. if (oldSvg) {
  529. const newIcon = document.createElement('img');
  530. newIcon.src = `https://raw.githubusercontent.com/material-extensions/vscode-material-icon-theme/refs/heads/main/icons/${iconName}.svg`;
  531. newIcon.style.cssText = 'width:20px;height:20px;vertical-align:text-bottom;margin-right:4px';
  532. oldSvg.parentNode.replaceChild(newIcon, oldSvg);
  533. }
  534. }
  535. }
  536. });
  537. }
  538.  
  539. replaceIcons();
  540.  
  541. const observer = new MutationObserver(replaceIcons);
  542. observer.observe(document.body, {
  543. childList: true,
  544. subtree: true,
  545. });
  546. })();