SetUserName

set username

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         SetUserName
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  set username
// @author       Minilong
// @match        https://*.tswjs.org/log/view/*
// @exclude      https://*.tswjs.org/log/view/xxx
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    app();
})();

// 创建元素插入
function app() {
    const root = document.createElement('div');
    setElement(root);
    root.innerHTML = `
    <a>修改测试号码</a>
  `
  const viewTitle = document.querySelector('.view-title');
    viewTitle.insertBefore(root, viewTitle.firstChild);
}

// 设置元素
function setElement(element) {
    let userName, url;
    Object.assign(element.style, getRootStyle());
    element.setAttribute('class', 'button r');
    element.addEventListener("click", function(){
        userName = saveUserName();
        if(!userName) return;
        url = getTargetURL(userName);
        redirectToMyLog(url);
    })
}

// 获取根元素样式
function getRootStyle() {
    return {
        cursor: 'pointer',
    }
}

// 设置用户名
function saveUserName() {
    const userName = prompt('输入测试号码', '');
    if(!userName) return;
    localStorage.setItem("tUserName",userName);
    return userName;
}

// 获取目标url
function getTargetURL(username) {
    const curURL = `${window.location.origin}/log/view/${username}`
  return curURL
}

// 重定向到目标url
function redirectToMyLog(url) {
    window.location.replace(url)
}