AtCoder Bookmarks

try to take over the world!

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

  1. // ==UserScript==
  2. // @name AtCoder Bookmarks
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://atcoder.jp/contests/*/tasks/*
  8. // @match https://atcoder-bookmarks.oxyshower.xyz
  9. // @match http://localhost:3000/
  10. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  11. // @grant GM.setValue
  12. // @grant GM.getValue
  13. // @grant GM_listValues
  14. // @grant GM.deleteValue
  15. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. const URL = location.href;
  22. if (URL.match("https://atcoder-bookmarks.oxyshower.xyz")) {
  23. let id = 0;
  24. let datalist = [];
  25. for (const key of GM_listValues()) {
  26. let username = "",
  27. problemname = "",
  28. problemurl,
  29. idx = 8;
  30. while (key[idx] != "$") username += key[idx++];
  31. idx++;
  32. while (key[idx] != "$") problemname += key[idx++];
  33. idx++;
  34. problemurl = key.substr(idx);
  35. datalist[id++] = {
  36. userName: username,
  37. problemName: problemname,
  38. problemUrl: problemurl,
  39. };
  40. }
  41. localStorage.removeItem("atcoder");
  42. // objectは保存できない -> 文字列で保存
  43. localStorage.setItem("atcoder", JSON.stringify(datalist));
  44. // console.log(JSON.stringify(datalist));
  45. } else {
  46. const userName = document
  47. .getElementsByClassName("dropdown-toggle")[1]
  48. .textContent.slice(10, -17);
  49. const problemUrl = location.href;
  50. const problemName = document
  51. .getElementsByClassName("h2")[0]
  52. .textContent.slice(4, -9);
  53. const value =
  54. "atcoder" + "$" + userName + "$" + problemName + "$" + problemUrl;
  55.  
  56. let html = '<button type="button" tag="HEAD" class="Bookmark">☆</button>';
  57. const newStyle = document.createElement("style");
  58. newStyle.type = "text/css";
  59. newStyle.innerText =
  60. "* { border: none; outline: none; * background: transparent;}";
  61. document.getElementsByTagName("HEAD").item(0).appendChild(newStyle);
  62. $(".h2").append(html);
  63.  
  64. let onoff = "off";
  65. for (const key of GM_listValues()) {
  66. if (key == value) {
  67. onoff = "on";
  68. $(".Bookmark").text("★");
  69. }
  70. }
  71. $(".Bookmark").click(function () {
  72. switch (onoff) {
  73. case "off":
  74. onoff = "on";
  75. $(".Bookmark").text("★");
  76. GM.setValue(value);
  77. break;
  78. case "on":
  79. onoff = "off";
  80. $(".Bookmark").text("☆");
  81. GM.deleteValue(value);
  82. break;
  83. }
  84. });
  85. }
  86. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址