SCP-CN Jump Document

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

Versione datata 26/01/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();