SCP-CN Jump Document

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

目前為 2022-01-26 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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