Github UserName for Cocos
当前为
// ==UserScript==
// @name Cocos Github UserName
// @namespace http://tampermonkey.net/
// @version 0.1.2
// @description Github UserName for Cocos
// @author YuanYuan
// @match https://github.com/cocos/*
// @icon https://forum.cocos.org/uploads/default/original/3X/7/a/7ac704385ca592fd41be29b0dff29dd20884c58d.png
// @grant GM_xmlhttpRequest
// @grant GM_download
// ==/UserScript==
(function() {
'use strict';
const customUsrName = {
'Ywenwen9': '雯雯',
'star-e': '周正龙'
};
function getUserNameMap() {
return new Promise(function(resolve, reject) {
const nameMap = localStorage.getItem('cocos-username');
if (nameMap) {
return resolve(Object.assign(JSON.parse(nameMap), customUsrName));
}
GM_xmlhttpRequest({
method: "GET",
url: 'https://download.cocos.org/CocosTest/lqn/userName.json',
responseType: 'json',
onload: function(data) {
localStorage.setItem('cocos-username', JSON.stringify(data.response));
resolve(Object.assign(data.response, customUsrName));
}
});
})
}
let promise = getUserNameMap();
function onLoad() {
console.log('enter Github UserName');
promise.then((userNameMap) => {
const $ids = document.querySelectorAll(`a[data-octo-dimensions="link_type:self"]`);
$ids.forEach(($item) => {
$item.innerText = userNameMap[$item.innerText] || $item.innerText;
});
})
}
window.onload = onLoad;
window.onbeforeunload = function(event){
console.log('onbeforeunload');
}
})();