SCP-CN 输入文档编号直接跳转
当前为
// ==UserScript==
// @name SCP-CN Jump Document
// @namespace https://scp-wiki-cn.wikidot.com/
// @version 1.00
// @description SCP-CN 输入文档编号直接跳转
// @author se7en
// @match https://scp-wiki-cn.wikidot.com/*
// @icon https://scp-wiki-cn.wikidot.com/local--favicon/favicon.gif
// @grant none
// @require https://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
let search_input = $("#search-top-box-input");
search_input.val("");
search_input.attr("placeholder", "搜索网站");
let add_html =
'<div style="position: absolute;top: 100px;right: 11px;width: 250px;text-align: right;">' +
'<input type="text" size="15" placeholder="请输入文档编号" id="jump-input" style="border: solid 1px #999;border-radius: 5px;color: #999;background-color: #300;margin-right: 3px;">' +
'<input type="button" value="跳转" id="jump-button"' +
'style="border: solid 1px #999;border-radius: 5px;padding: 2px 5px;font-size: 90%;font-weight: bold;color: #ccc;background-color: #633;background: linear-gradient(to bottom,#966,#633,#300);box-shadow: 0 1px 3px rgb(0 0 0 / 50%);cursor: pointer;">' +
'</div>';
$("#header").append(add_html);
$("#jump-input").keypress(function (even) { if (even.which == 13) jumpDocument(); });
$("#jump-button").click(function () { jumpDocument(); });
})();
function jumpDocument() {
let jump_input = $("#jump-input");
let jump_input_value = jump_input.val();
let document = "";
if (jump_input_value.search(/cn/i) != -1) document += "cn-";
let document_number = /[0-9]{1,}/.exec(jump_input_value);
if (document_number == null) {
jump_input.val("");
jump_input.attr("readonly", "readonly");
let input_count = 0;
let error_alert = setInterval(function () {
if (input_count == 5) {
jump_input.removeAttr("readonly");
jump_input.focus();
clearInterval(error_alert);
}
jump_input.val((input_count % 2 == 0) ? "输入错误!!" : " ");
input_count += 1;
}, 200);
} 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);
document += document_number;
window.location.href = window.location.origin + "/scp-" + document;
}
}