SCP-CN Jump Document

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

  1. // ==UserScript==
  2. // @name SCP-CN Jump Document
  3. // @namespace https://scp-wiki-cn.wikidot.com/
  4. // @version 2.0.2
  5. // @description SCP-CN 输入文档编号直接跳转
  6. // @author se7en
  7. // @match http*://scp-wiki-cn.wikidot.com/*
  8. // @icon https://scp-wiki-cn.wikidot.com/local--favicon/favicon.gif
  9. // @license GPL-3.0 License
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-latest.js
  12. // ==/UserScript==
  13.  
  14. function addButton() {
  15. let body = $("#html-body"); // document.getElementById("html-body");
  16.  
  17. // 添加悬浮按钮
  18. let float_button = document.createElement("div");
  19. float_button.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
  20. float_button.style.backgroundImage = "url('https://pic.imgdb.cn/item/667431f4d9c307b7e93c5691.png')";
  21. float_button.style.backgroundSize = "cover";
  22. float_button.style.cssText +=
  23. "position: fixed; bottom: 21px; right: 11px; cursor: pointer;" +
  24. "width: 35px; height: 35px; line-height: 35px; transform: translate(.5px, 0); opacity: 1;" +
  25. "border: 1px #fff solid; border-radius: 25px; color: white; text-align: center;";
  26. float_button.onclick = function () {
  27. let ui_div = document.getElementById("input-ui");
  28. ui_div.style.display = "block";
  29. document.getElementById("jump-target").value = "SCP-000";
  30. }
  31. body.append(float_button);
  32.  
  33. // 添加悬浮div
  34. let float_div = document.createElement("div");
  35. float_div.id = "input-ui";
  36. float_div.innerHTML =
  37. "<input type='text' id='jump-target' readonly>" +
  38. "<div id='input-ui-button'>" +
  39. "<ul><li onclick='inputUiCn()'>CN</li><li onclick='inputUiJ()'>J</li><li onclick='inputUiBackspace()'><-</li></ul>" +
  40. "<ul><li onclick='inputUiNumber(1)'>1</li><li onclick='inputUiNumber(2)'>2</li><li onclick='inputUiNumber(3)'>3</li></ul>" +
  41. "<ul><li onclick='inputUiNumber(4)'>4</li><li onclick='inputUiNumber(5)'>5</li><li onclick='inputUiNumber(6)'>6</li></ul>" +
  42. "<ul><li onclick='inputUiNumber(7)'>7</li><li onclick='inputUiNumber(8)'>8</li><li onclick='inputUiNumber(9)'>9</li></ul>" +
  43. "<ul><li onclick='inputUiClose()'>X</li><li onclick='inputUiNumber(0)'>0</li><li onclick='inputUiGo()'>GO</li></ul>" +
  44. "</div>";
  45. float_div.style.cssText +=
  46. "display: none; position: fixed; bottom: 20px; right: 10px;" +
  47. "width: 163px; height: 280px; transform: translate(.5px, 0); opacity: 1;" +
  48. "border: 1px #fff solid; border-radius: 4px;" +
  49. "background: #91989f; color: white; box-shadow: 2px 2px 5px #555; text-align: center;";
  50. body.append(float_div);
  51.  
  52. // 添加script
  53. let script = document.createElement('script');
  54. script.innerHTML = `
  55. function inputUiClose() { document.getElementById("input-ui").style.display = "none"; }
  56. function regInputValue(value) {
  57. let reg_result = /(SCP\-)?(CN-)?([0-9]{3,})?(\-J)?/i.exec(value);
  58. return {
  59. scp: reg_result[1],
  60. cn: reg_result[2] != null ? reg_result[2] : "",
  61. number: reg_result[3] != null ? reg_result[3] : "",
  62. joke: reg_result[4] != null ? reg_result[4] : ""
  63. };
  64. }
  65. function inputUiNumber(number) {
  66. let input = document.getElementById("jump-target");
  67. let input_value = input.value;
  68. let reg_input = regInputValue(input_value);
  69. let old_number = (reg_input["number"] != "") ? String(parseInt(reg_input["number"])) : "";
  70. let new_value = old_number + number;
  71. if (new_value.length < 3) new_value = new_value.padStart(3, "0");
  72. input.value = reg_input["scp"] + reg_input["cn"] + new_value + reg_input["joke"];
  73. }
  74. function inputUiBackspace() {
  75. let input = document.getElementById("jump-target");
  76. let input_value = input.value;
  77. let reg_input = regInputValue(input_value);
  78. console.log(reg_input);
  79. if (reg_input["number"] != "") {
  80. let new_value = reg_input["number"].substring(0, reg_input["number"].length - 1);
  81. if (new_value.length < 3) new_value = new_value.padStart(3, "0");
  82. input.value = reg_input["scp"] + reg_input["cn"] + new_value + reg_input["joke"];
  83. }
  84. }
  85. function inputUiCn() {
  86. let input = document.getElementById("jump-target");
  87. let input_value = input.value;
  88. let reg_input = regInputValue(input_value);
  89. let cn_str = (reg_input["cn"] != "") ? "" : "CN-";
  90. input.value = reg_input["scp"] + cn_str + reg_input["number"] + reg_input["joke"];
  91. }
  92. function inputUiJ() {
  93. let input = document.getElementById("jump-target");
  94. let input_value = input.value;
  95. let reg_input = regInputValue(input_value);
  96. let joke_str = (reg_input["joke"] != "") ? "" : "-J";
  97. input.value = reg_input["scp"] + reg_input["cn"] + reg_input["number"] + joke_str;
  98. }
  99. function inputUiGo() {
  100. let input = document.getElementById("jump-target");
  101. let input_value = input.value;
  102. window.location.href = "https://" + window.location.host + "/" + input_value.toLowerCase();
  103. }`;
  104. body.append(script);
  105.  
  106. // 添加style
  107. let style = document.createElement('style');
  108. style.innerHTML =
  109. "#jump-target { background: #3c2f41; text-align: right; padding: 0px 5px; border-radius: 10px; margin: 12px 7px; width: 85%; height: 30px; border: 1px #fff solid; font-size: 11pt; color: #f8c3cd; outline: none; }" +
  110. "#input-ui #input-ui-button ul { padding: 0px; margin: 0px; margin-left: 17px; }" +
  111. "#input-ui #input-ui-button ul li { list-style: none; background: #574c57; font-weight: bold; border-radius: 10px; margin: 4px 4px 4px 4px; width: 35px; height: 35px; line-height: 36px; float: left; box-shadow: 1px 1px 5px #333; cursor: pointer; }";
  112. body.append(style);
  113. }
  114.  
  115. (function () {
  116. addButton();
  117. })();