Last active
April 28, 2024 06:22
-
-
Save vangie/f2e644c0f0d37638f2e2b14a54d96219 to your computer and use it in GitHub Desktop.
Gru Avatar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Gru Avatar | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-04-28.02 | |
// @description Random Avatar for Gru | |
// @author You | |
// @match https://*.babeltech.net/gru | |
// @match https://*.babeltech.net/gru/* | |
// @icon https://staging.babeltech.net/images/favicon.png | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// 监听DOM变化的函数 | |
function observeDOM() { | |
const observer = new MutationObserver((mutations) => { | |
replaceGru(); | |
}); | |
// 配置observer(观察器)选项: | |
const config = { childList: true, subtree: true }; | |
// 开始对body元素及其子元素进行观察 | |
observer.observe(document.body, config); | |
} | |
const avatars = [ | |
[1726527, "“高级程序员”"], | |
[4507629, "送你一枚大🚀"], | |
[34255589,"来仨大🚀"] | |
[159840, "俺自己撸"], | |
[1388582, "专写起夜语句"], | |
[24806274, "秘密收集器"], | |
[778873, "houseboy"], | |
[28912435, "Frontend Speedster"], | |
[15364364, "家里有🐑"], | |
[12868055,"TechNomadBoy"] | |
] | |
const avatar = avatars[Math.floor(Math.random() * avatars.length)]; | |
// 替换页面加载时就存在的符合条件的图片 | |
function replaceGru() { | |
const targetSrc = `https://avatars.githubusercontent.com/u/${avatar[0]}?v=4`; | |
const name = avatar[1]; | |
document.querySelectorAll("img[src='/images/gru-avatar.png']").forEach(img => { | |
if (img.src !== targetSrc) { | |
img.src = targetSrc; | |
} | |
}); | |
document.querySelectorAll(".MuiList-root .MuiListItem-root > div > .MuiBox-root > .MuiBox-root span.MuiTypography-root").forEach(span => { | |
if (span.innerText !== name) { | |
span.innerText = name; | |
} | |
}); | |
} | |
replaceGru(); | |
observeDOM(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment