Picarto Username Changer

Change your name, at least temporarily!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Picarto Username Changer
// @namespace    Wolvan_PicartoTV_Username_Modifier
// @version      1.0
// @description  Change your name, at least temporarily!
// @author       Wolvan
// @match        *://*.picarto.tv/*
// @grant        none
// ==/UserScript==

// Get Picarto's jQuery instance, no need to polute it with our own
var $ = window.jQuery;

// A function to inject CSS into the site
function changeName(name) {
    $.post("/process/channel", {
        setusername: name
    }).done(function (resp) {
        switch (resp) {
            case "ok":
                location.reload();
                break;
            case "userNameRegEx":
                window.displayNotificationMsg(10);
                break;
            case "userNameExists":
                window.displayNotificationMsg(13);
                break;
            case "userNameTooLong":
                window.displayNotificationMsg(11);
                break;
        }
    });
}

$("body").keydown(function(e) {
    if (e.which === 81 && e.ctrlKey) {
        var name = prompt("Please choose a username");
        if (name) changeName(name);
    }
});