SCP-CN Jump Document

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

当前为 2021-03-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SCP-CN Jump Document
  3. // @namespace https://scp-wiki-cn.wikidot.com/
  4. // @version 1.00
  5. // @description SCP-CN 输入文档编号直接跳转
  6. // @author se7en
  7. // @match https://scp-wiki-cn.wikidot.com/*
  8. // @icon https://scp-wiki-cn.wikidot.com/local--favicon/favicon.gif
  9. // @grant none
  10. // @require https://code.jquery.com/jquery-latest.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. let search_input = $("#search-top-box-input");
  15. search_input.val("");
  16. search_input.attr("placeholder", "搜索网站");
  17. let add_html =
  18. '<div style="position: absolute;top: 100px;right: 11px;width: 250px;text-align: right;">' +
  19. '<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;">' +
  20. '<input type="button" value="跳转" id="jump-button"' +
  21. '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;">' +
  22. '</div>';
  23.  
  24. $("#header").append(add_html);
  25. $("#jump-input").keypress(function (even) { if (even.which == 13) jumpDocument(); });
  26. $("#jump-button").click(function () { jumpDocument(); });
  27. })();
  28.  
  29. function jumpDocument() {
  30. let jump_input = $("#jump-input");
  31. let jump_input_value = jump_input.val();
  32. let document = "";
  33. if (jump_input_value.search(/cn/i) != -1) document += "cn-";
  34. let document_number = /[0-9]{1,}/.exec(jump_input_value);
  35. if (document_number == null) {
  36. jump_input.val("");
  37. jump_input.attr("readonly", "readonly");
  38. let input_count = 0;
  39. let error_alert = setInterval(function () {
  40. if (input_count == 5) {
  41. jump_input.removeAttr("readonly");
  42. jump_input.focus();
  43. clearInterval(error_alert);
  44. }
  45. jump_input.val((input_count % 2 == 0) ? "输入错误!!" : " ");
  46. input_count += 1;
  47. }, 200);
  48. } else {
  49. document_number = document_number[0];
  50. let number_length = document_number.length;
  51. if (number_length < 3) for (let i = (3 - number_length); i > 0; i--) document_number = "0".concat(document_number);
  52. document += document_number;
  53. window.location.href = window.location.origin + "/scp-" + document;
  54. }
  55. }