Picarto Username Changer

Change your name, at least temporarily!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
});