Greasy Fork is available in English.

LeetCode Focus Mode

just focus!

2020/10/31のページです。最新版はこちら

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
  1. // ==UserScript==
  2. // @name LeetCode Focus Mode
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description just focus!
  6. // @author litt1e-p
  7. // @homepage https://github.com/litt1e-p/tampermonkey/leetcode-focus-mode
  8. // @match https://leetcode-cn.com/problemset/*
  9. // @match https://leetcode-cn.com/problems/*
  10. // @match https://leetcode-cn.com/contest/*/problems/*
  11. // @match https://leetcode.com/problemset/*
  12. // @match https://leetcode.com/problems/*
  13. // @match https://leetcode.com/contest/*/problems/*
  14. // @grant none
  15. // @run-at document-end
  16. // ==/UserScript==
  17. (function(){
  18. function insertStyle() {
  19. const style = document.createElement('style');
  20. style.innerHTML = `
  21. .lc-nav-func-btn {
  22. width: 100px;
  23. height: 44px;
  24. background: #fff;
  25. border: 1px solid #ddd;
  26. color: #666;
  27. font-size: 16px;
  28. z-index: 999999;
  29. position: absolute;
  30. right: 0;
  31. top: 0px;
  32. }
  33. `
  34. document.body.appendChild(style);
  35. }
  36. function insertBtn() {
  37. var el = document.createElement('button');
  38. el.setAttribute('class', 'lc-nav-func-btn');
  39. el.addEventListener('click', btnEvent)
  40. document.body.appendChild(el);
  41. }
  42. function toggleBtn(active = true) {
  43. var el = document.querySelector('.lc-nav-func-btn');
  44. if (!el) return;
  45. el.innerText = active ? 'hide' : 'show';
  46. }
  47. function els () {
  48. var usNav = '#navbar-root';
  49. var cat = '.category-group-base';
  50. var sid = '.blog-sidebar';
  51. var cnNav = '#noj-navbar';
  52. var flo = '.floating-layer-container';
  53. var els = [usNav, cnNav, cat, sid, flo];
  54. var rs = [];
  55. for (var i = 0, l = els.length; i < l; i++) {
  56. const el = document.querySelector(els[i]);
  57. if (el) rs.push(el);
  58. }
  59. return rs;
  60. }
  61. function toggleEls(show = true) {
  62. var ls = els();
  63. for (let i = 0, l = ls.length; i < l; i++) {
  64. ls[i].style.display = (show ? 'block' : 'none');
  65. }
  66. }
  67. function btnEvent(e) {
  68. var el = e.target;
  69. var s = el.innerText === 'show';
  70. toggleState(s);
  71. syncState(s);
  72. }
  73. function toggleState(s) {
  74. setTimeout(() => {
  75. toggleBtn(s);
  76. toggleEls(s);
  77. }, 20);
  78. }
  79. function syncState(show = false) {
  80. window.localStorage.setItem('lc-focus-show#', show ? 1 : 0)
  81. }
  82. function savedState() {
  83. return window.localStorage.getItem('lc-focus-show#')
  84. }
  85. function initState() {
  86. let s = savedState();
  87. if (s === null) return;
  88. toggleState(+s);
  89. }
  90. function main() {
  91. insertStyle();
  92. insertBtn();
  93. toggleBtn();
  94. initState();
  95. }
  96. main();
  97. })();