GitHub 文件图标替换

用更漂亮的图标替换 GitHub 文件图标

目前为 2024-12-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         GitHub Files Icon Replacement
// @name:vi      Thay thế biểu tượng tệp GitHub
// @name:zh-cn   GitHub 文件图标替换
// @name:zh-tw   GitHub 文件圖標替換
// @name:ru      Замена иконок файлов GitHub
// @namespace    http://tampermonkey.net/
// @version      2024.12.23.3
// @description  Replace GitHub file icons with material icons
// @description:vi  Thay thế icon file trên GitHub bằng icon material 
// @description:zh-cn  用更漂亮的图标替换 GitHub 文件图标
// @description:zh-tw  用更漂亮的圖標替換 GitHub 文件圖標
// @description:ru  Замена иконок файлов GitHub на более красивые
// @author       Yuusei
// @match        https://github.com/*
// @icon         https://github.githubassets.com/favicon.ico
// @grant        none
// @run-at       document-start
// @license      GPL-3.0-only
// @compatible   chrome
// @compatible   firefox
// @compatible   edge
// ==/UserScript==

(function () {
	'use strict';

	function replaceIcons() {
		const fileElements = document.querySelectorAll('.react-directory-row-name-cell-large-screen');

		fileElements.forEach(element => {
			const filenameElement = element.querySelector('.react-directory-filename-cell');
			if (filenameElement) {
				const filename = filenameElement.textContent;
				let iconName = '';

				const iconMap = {
					'.ts': 'typescript',
					'.json': 'json',
					'.yml': 'yaml',
					'.yaml': 'yaml',
					'.js': 'javascript',
					'.html': 'html',
					'.css': 'css',
					'.py': 'python',
					'.php': 'php',
					'.md': 'markdown',
					'.lua': 'lua',
					'.npm': 'npm',
					'.lock': 'npm',
					'.svg': 'svg',
					'.xml': 'xml',
					'.txt': 'document',
					'.vue': 'vue',
					'.angular': 'angular',
					'.gitignore': 'git',
					'.git': 'git',
					'.jsx': 'react',
					'.tsx': 'react_ts',
					'.scss': 'sass',
					'.sass': 'sass',
					'.less': 'less',
					'.sh': 'shell',
					'.bash': 'shell',
					'.zsh': 'shell',
					'.fish': 'shell',
					'.c': 'c',
					'.cpp': 'cpp',
					'.cs': 'csharp',
					'.go': 'go',
					'.rs': 'rust',
					'.rb': 'ruby',
					'.java': 'java',
					'.kt': 'kotlin',
					'.swift': 'swift',
					'.dart': 'dart',
					'.sql': 'database',
					'.db': 'database',
					'.env': 'tune',
					'.docker': 'docker',
					'.dockerfile': 'docker',
					'.exe': 'exe',
					'.png': 'image',
					'.jpg': 'image',
					'.jpeg': 'image',
					'.gif': 'image',
					'.ico': 'image',
					'.webp': 'image',
					'.bmp': 'image',
					'.tiff': 'image',
					'.mp3': 'audio',
					'.wav': 'audio',
					'.mp4': 'video',
					'.mov': 'video',
					'.avi': 'video',
					'.ini': 'settings',
					'.config': 'settings',
					'.toml': 'settings',
					'.gradle': 'gradle',
					'.jar': 'java',
					'.class': 'java',
					'.properties': 'settings',
					'.r': 'r',
					'.rmd': 'r',
					'.scala': 'scala',
					'.groovy': 'groovy',
					'.pl': 'perl',
					'.pm': 'perl',
					'.h': 'c',
					'.hpp': 'cpp',
					'.hxx': 'cpp',
					'.m': 'objectivec',
					'.mm': 'objectivec',
					'.swift': 'swift',
					'.f': 'fortran',
					'.f90': 'fortran',
					'.f95': 'fortran',
					'.mat': 'matlab',
					'.coffee': 'coffeescript',
					'.litcoffee': 'coffeescript',
					'.elm': 'elm',
					'.ex': 'elixir',
					'.exs': 'elixir',
					'.erl': 'erlang',
					'.hrl': 'erlang',
					'.clj': 'clojure',
					'.cljs': 'clojure',
					'.fs': 'fsharp',
					'.fsx': 'fsharp',
					'.hs': 'haskell',
					'.lhs': 'haskell',
					'.ml': 'ocaml',
					'.mli': 'ocaml',
					'.pp': 'puppet',
					'.tf': 'terraform',
					'.tfvars': 'terraform',
					'.sol': 'solidity',
					'.proto': 'protobuf',
					'.graphql': 'graphql',
					'.haml': 'haml',
					'.slim': 'slim',
					'.erb': 'erb',
					'.jade': 'pug',
					'.pug': 'pug',
					'.styl': 'stylus',
					'.nix': 'nix',
					'.vim': 'vim',
					'.bat': 'console',
					'.cmd': 'console',
					'.dll': 'dll',
					'.so': 'lib',
					'.a': 'lib',
					'.dylib': 'lib',
					'.zip': 'zip',
					'.rar': 'zip',
					'.7z': 'zip',
					'.tar': 'zip',
					'.gz': 'zip',
					'.bz2': 'zip',
					'.xz': 'zip',
					'.pdf': 'pdf',
					'.doc': 'word',
					'.docx': 'word',
					'.ppt': 'powerpoint',
					'.pptx': 'powerpoint',
					'.odt': 'document',
					'.fig': 'figma',
					'.xd': 'xd',
					'.ai': 'illustrator',
					'.psd': 'photoshop',
					'.blend': 'blender',
					'.fbx': '3d',
					'.obj': '3d',
					'.stl': '3d',
					'.3ds': '3d',
					'.max': '3d',
					'.maya': '3d',
					'.shader': 'shader',
					'.glsl': 'shader',
					'.vert': 'shader',
					'.frag': 'shader',
					'.wasm': 'assembly',
					'.wat': 'assembly',
					'.asm': 'assembly',
					'.s': 'assembly',
					'.ko': 'linux',
					'.deb': 'debian',
					'.rpm': 'redhat',
					'.apk': 'android',
					'.ipa': 'apple',
					'.dmg': 'apple',
					'.pkg': 'apple',
					'.app': 'apple',
					'.pas': 'pascal',
					'.cobol': 'cobol',
					'.ada': 'ada',
					'.lisp': 'lisp',
					'.scm': 'scheme',
					'.rkt': 'racket',
					'.prolog': 'prolog',
					'.forth': 'forth',
					'.apl': 'apl',
					'.basic': 'basic',
					'.d': 'd',
					'.nim': 'nim',
					'.crystal': 'crystal',
					'.julia': 'julia',
					'.io': 'io',
					'.tcl': 'tcl',
					'.zig': 'zig',
					'.v': 'v',
					'.odin': 'odin',
					'.haxe': 'haxe',
					'.idl': 'idl',
					'.hack': 'hack',
					'.pike': 'pike',
					'.eiffel': 'eiffel',
					'.smalltalk': 'smalltalk',
					'.modula': 'modula',
					'.algol': 'algol'
				};

				const specialFiles = {
					'package.json': 'nodejs',
					'README.md': 'markdown',
					'LICENSE': 'certificate',
					'.prettierignore': 'prettier',
					'.prettierrc': 'prettier',
					'.eslintignore': 'eslint',
					'.eslintrc.cjs': 'eslint',
					'.eslintrc.js': 'eslint',
					'.eslintrc.json': 'eslint',
					'.eslintrc.yml': 'eslint',
					'docker-compose.yml': 'docker',
					'Dockerfile': 'docker',
					'.dockerignore': 'docker',
					'.env.local': 'tune',
					'.env.development': 'tune',
					'.env.production': 'tune',
					'.env.test': 'tune',
					'.env.staging': 'tune',
					'tsconfig.json': 'typescript',
					'webpack.config.js': 'webpack',
					'babel.config.js': 'babel',
					'jest.config.js': 'jest',
					'angular.json': 'angular',
					'next.config.js': 'next',
					'nuxt.config.js': 'nuxt',
					'vite.config.js': 'vite',
					'rollup.config.js': 'rollup',
					'svelte.config.js': 'svelte',
					'tailwind.config.js': 'tailwind',
					'postcss.config.js': 'postcss',
					'composer.json': 'composer',
					'composer.lock': 'composer',
					'Gemfile': 'ruby',
					'Gemfile.lock': 'ruby',
					'requirements.txt': 'python',
					'poetry.lock': 'python',
					'pyproject.toml': 'python',
					'Cargo.toml': 'rust',
					'Cargo.lock': 'rust',
					'go.mod': 'go',
					'go.sum': 'go',
					'mix.exs': 'elixir',
					'rebar.config': 'erlang',
					'stack.yaml': 'haskell',
					'cabal.project': 'haskell',
					'dune-project': 'ocaml',
					'opam': 'ocaml',
					'Rakefile': 'ruby',
					'Makefile': 'makefile',
					'CMakeLists.txt': 'cmake',
					'build.gradle': 'gradle',
					'pom.xml': 'maven',
					'build.sbt': 'sbt',
					'mix.lock': 'elixir',
					'elm.json': 'elm',
					'browserslist': 'browserslist',
					'.babelrc': 'babel',
					'.travis.yml': 'travis',
					'circle.yml': 'circleci',
					'jenkins.yml': 'jenkins',
					'kubernetes.yml': 'kubernetes',
					'nginx.conf': 'nginx',
					'apache.conf': 'apache',
					'.gitattributes': 'git',
					'.gitmodules': 'git',
					'.gitlab-ci.yml': 'gitlab',
					'bitbucket-pipelines.yml': 'bitbucket',
					'azure-pipelines.yml': 'azure',
					'Jenkinsfile': 'jenkins',
					'sonar-project.properties': 'sonarqube',
					'phpunit.xml': 'phpunit',
					'karma.conf.js': 'karma',
					'cypress.json': 'cypress',
					'playwright.config.js': 'playwright',
					'selenium.config.js': 'selenium',
					'docker-compose.override.yml': 'docker',
					'docker-compose.prod.yml': 'docker',
					'docker-compose.dev.yml': 'docker',
					'Procfile': 'heroku',
					'vercel.json': 'vercel',
					'netlify.toml': 'netlify',
					'firebase.json': 'firebase',
					'now.json': 'zeit',
					'pm2.config.js': 'pm2',
					'nodemon.json': 'nodemon',
					'lerna.json': 'lerna',
					'nx.json': 'nx',
					'rush.json': 'rush',
					'yarn.lock': 'yarn',
					'pnpm-lock.yaml': 'pnpm',
					'bun.lockb': 'bun',
					'deno.json': 'deno',
					'rome.json': 'rome',
					'prettier.config.js': 'prettier',
					'stylelint.config.js': 'stylelint',
					'commitlint.config.js': 'commitlint',
					'lint-staged.config.js': 'lint-staged',
					'husky.config.js': 'husky',
					'.huskyrc': 'husky',
					'.lintstagedrc': 'lint-staged',
					'.commitlintrc': 'commitlint',
					'.stylelintrc': 'stylelint',
					'.prettierrc.js': 'prettier',
					'.eslintrc': 'eslint',
					'.browserslistrc': 'browserslist',
					'.npmrc': 'npm',
					'.yarnrc': 'yarn',
					'.nvmrc': 'nodejs',
					'.node-version': 'nodejs',
					'.ruby-version': 'ruby',
					'.python-version': 'python',
					'.tool-versions': 'asdf',
					'.editorconfig': 'editorconfig',
					'.mailmap': 'email',
					'.gitmessage': 'git',
					'.gitkeep': 'git',
					'pascal.config': 'pascal',
					'cobol.config': 'cobol',
					'ada.config': 'ada',
					'lisp.config': 'lisp',
					'scheme.config': 'scheme',
					'racket.config': 'racket',
					'prolog.config': 'prolog',
					'forth.config': 'forth',
					'apl.config': 'apl',
					'basic.config': 'basic',
					'd.config': 'd',
					'nim.config': 'nim',
					'crystal.config': 'crystal',
					'julia.config': 'julia',
					'io.config': 'io',
					'tcl.config': 'tcl',
					'zig.config': 'zig',
					'v.config': 'v',
					'odin.config': 'odin',
					'haxe.config': 'haxe',
					'idl.config': 'idl',
					'hack.config': 'hack',
					'pike.config': 'pike',
					'eiffel.config': 'eiffel',
					'smalltalk.config': 'smalltalk',
					'modula.config': 'modula',
					'algol.config': 'algol'
				};

				iconName = specialFiles[filename] || Object.entries(iconMap).find(([ext]) => filename.toLowerCase().endsWith(ext))?.[1];

				if (iconName) {
					const oldSvg = element.querySelector('svg');
					if (oldSvg) {
						const newIcon = document.createElement('img');
						newIcon.src = `https://raw.githubusercontent.com/material-extensions/vscode-material-icon-theme/refs/heads/main/icons/${iconName}.svg`;
						newIcon.style.cssText = 'width:20px;height:20px;vertical-align:text-bottom;margin-right:4px';
						oldSvg.parentNode.replaceChild(newIcon, oldSvg);
					}
				}
			}
		});
	}

	replaceIcons();

	const observer = new MutationObserver(replaceIcons);
	observer.observe(document.body, {
		childList: true,
		subtree: true,
	});
})();

QingJ © 2025

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