Cocos Github UserName

Github UserName for Cocos

Від 14.03.2022. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Cocos Github UserName
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @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';
    function getUserNameMap() {
        return new Promise(function(resolve, reject) {
                GM_xmlhttpRequest({
                method: "GET",
                url: 'https://download.cocos.org/CocosTest/lqn/userName.json',
                responseType: 'json',
                onload: function(data) {
                    resolve(data.response);
                }
            });
        })
    }
    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');
    }
})();