SCP-CN Jump Document

SCP-CN 输入文档编号直接跳转

Verze ze dne 26. 01. 2022. Zobrazit nejnovější verzi.

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         SCP-CN Jump Document
// @namespace    https://scp-wiki-cn.wikidot.com/
// @version      1.05
// @description  SCP-CN 输入文档编号直接跳转
// @author       se7en
// @match        http*://scp-wiki-cn.wikidot.com/*
// @icon         https://scp-wiki-cn.wikidot.com/local--favicon/favicon.gif
// @license      GPL-3.0 License
// @grant        none
// ==/UserScript==

(function() {
    let body = document.getElementById("html-body");

    // 添加按钮
    let button = document.createElement('button');
    button.setAttribute("onclick", "jumpInputShow()");
    button.id = "jump-button";
    button.innerHTML = "跳转";
    button.style.position = "absolute";
    button.style.top = "0";
    button.style.right = "0";
    button.style.border = "1px #000000 solid";
    button.style.cssText += "border-color: #000 #000 #fff #fff; border-radius: 0 0 0 7px; color: #ffffff; z-index: 9999; font-size: 1.27em; background-color: #000000;";
    body.appendChild(button);

    // 添加input
    let input = document.createElement('input');
    input.setAttribute("onblur", "jumpInputHide()");
    input.setAttribute("onkeydown", "jumpAction(event)");
    input.id = "jump-input";
    input.type = "text";
    input.style.position = "absolute";
    input.style.top = "0";
    input.style.right = "0";
    input.style.cssText += "width: 7em; display: none; color: #66bab7; background-color: #000000; text-align: center;";
    body.appendChild(input);

    // 添加JS
    let script = document.createElement('script');
    script.innerHTML = `
        function jumpInputShow() { let input = document.getElementById("jump-input"); input.style.display = "block"; input.focus(); let button = document.getElementById("jump-button"); button.style.display = "none"; }
        function jumpInputHide() { let input = document.getElementById("jump-input"); input.style.display = "none"; input.value = ""; let button = document.getElementById("jump-button"); button.style.display = "block"; }
        function jumpAction(e) {
            if (e.keyCode == 13) {
            let input = document.getElementById("jump-input"); let jump_input_value = input.value; let doc = "";
            if (jump_input_value..length == 0) return false;
            if (jump_input_value.search(/cn/i) != -1) doc += "cn-";
            let document_number = /[0-9]{1,}/.exec(jump_input_value);
            if (document_number == null) {
            input.value = ""; input.readonly = true; let input_count = 0;
                let error_alert = setInterval(function () {
                    if (input_count == 3) { input.readonly = false; input.value = ""; input.focus(); clearInterval(error_alert); }
                    input.value = (input_count % 2 == 0) ? "输入错误!!" : " "; input_count += 1;
                }, 135);
            } else {
                document_number = document_number[0]; let number_length = document_number.length;
                if (number_length < 3) for (let i = (3 - number_length); i > 0; i--) document_number = "0".concat(document_number);
                doc += document_number; window.location.href = window.location.origin + "/scp-" + doc;
            }
          }
        }`;
    body.appendChild(script);
})();