FextraLife Tweaks

Adds various tweaks to FextraLife wiki(s)

目前为 2022-03-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name FextraLife Tweaks
  3. // @description Adds various tweaks to FextraLife wiki(s)
  4. // @author Magic <magicoflolis@tuta.io>
  5. // @license MIT
  6. // @icon https://fextralife.com/wp-content/uploads/2015/07/flswords-152.png
  7. // @namespace https://github.com/magicoflolis/userscriptrepo/tree/master/FextraLifeTweaks
  8. // @homepageURL https://github.com/magicoflolis/userscriptrepo/tree/master/FextraLifeTweaks
  9. // @supportURL https://github.com/magicoflolis/userscriptrepo/issues/new
  10. // @match https://*.wiki.fextralife.com/*
  11. // @exclude https://www.wiki.fextralife.com/*
  12. // @version 1.1
  13. // @grant GM_addStyle
  14. // ==/UserScript==
  15.  
  16. // Defaults and examples are listed at the end of the user script.
  17. let Remove_Clutter = true, // Removes some clutter + wider page
  18. DisableComments = false, // Disables comments
  19. AutoScroll = true, // Automatically scrolls on page load
  20. Scroll_Amount = 202, // Scroll amount for "Top" button.
  21. btn_CSS = `
  22. #cmt-btn,
  23. #top-btn {
  24. display: none;
  25. top: 90%;
  26. font-weight: bold;
  27. width: auto;
  28. min-height: 5px;
  29. margin: 0 3px;
  30. padding: 10px 15px;
  31. text-transform: uppercase;
  32. text-align: center;
  33. position: fixed;
  34. z-index: 10000 !important;
  35. }
  36. #cmt-btn {
  37. left: 1%;
  38. }
  39. #top-btn {
  40. right: 1%;
  41. }`;
  42.  
  43. // Userscript Code
  44. (() => {
  45. try {
  46. let query = (e,all) => !all ? document.querySelector(e) : document.querySelectorAll(e),
  47. qs = async element => {
  48. while (document.querySelector(element) === null) {
  49. await new Promise(resolve => requestAnimationFrame(resolve));
  50. }
  51. return document.querySelector(element);
  52. },
  53. ael = (elm = document, event, callback) => {
  54. return elm.addEventListener(event, callback);
  55. },
  56. create = (element, type, cname, iname, value) => {
  57. let el = document.createElement(element);
  58. type !== "none" ? (el.type = type) : false;
  59. cname ? (el.className = cname) : false;
  60. iname ? (el.id = iname) : false;
  61. value ? (el.value = value) : false;
  62. return el;
  63. },
  64. cmt_btn = create("input", "button", "btn btn-default btn-xs", "cmt-btn", "Comments"),
  65. top_btn = create("input", "button", "btn btn-default btn-xs", "top-btn", "Top");
  66. GM_addStyle(btn_CSS);
  67. qs("#wrapper").then((wrapper) => {
  68. if(Remove_Clutter) {
  69. qs("#sidebar-wrapper").then((sw) => sw.remove());
  70. qs(".ad-banner").then((e) => e.remove());
  71. wrapper.setAttribute("style", "padding-left: 0px !important");
  72. for (let i = 0; i < query("ul",true).length; i++) {
  73. query("ul",true)[i].setAttribute("style", "max-width: 100% !important")
  74. };
  75. };
  76. qs(".discussion-wrapper").then((dw) => {
  77. if(DisableComments) {
  78. dw.remove();
  79. } else {
  80. ael(cmt_btn,"click", () => {
  81. return dw.scrollIntoView();
  82. });
  83. };
  84. });
  85. ael(top_btn,"click", () => {
  86. return wrapper.scrollIntoView();
  87. });
  88. wrapper.append(top_btn,cmt_btn);
  89. (AutoScroll) ? qs("#page-content-wrapper").then((e) => e.scrollIntoView()) : false;
  90. });
  91. ael(document,"scroll", () => {
  92. return (document.documentElement.scrollTop > Scroll_Amount) ? (
  93. top_btn.setAttribute("style",'display: inline-block !important'),
  94. !DisableComments ? cmt_btn.setAttribute("style",'display: inline-block !important') : false
  95. ) : (
  96. top_btn.setAttribute("style",'display: none !important'),
  97. !DisableComments ? cmt_btn.setAttribute("style",'display: none !important') : false
  98. );
  99. });
  100. } catch (e) {
  101. console.log("[%cFLT%c] %cERROR","color: rgb(29, 155, 240);","","color: rgb(249, 24, 128);",e)
  102. }
  103. })();
  104.  
  105. /**
  106. * Defaults:
  107. *
  108. * Remove_Clutter = true // Removes some clutter + wider page
  109. * DisableComments = false,
  110. * AutoScroll = true,
  111. * Scroll_Amount = 202 // Set to 0 disables auto scroll AND "Top" button
  112. * btn_CSS = `
  113. #cmt-btn,
  114. #top-btn {
  115. display: none;
  116. top: 90%;
  117. font-weight: bold;
  118. width: auto;
  119. min-height: 5px;
  120. margin: 0 3px;
  121. padding: 10px 15px;
  122. text-transform: uppercase;
  123. text-align: center;
  124. position: fixed;
  125. z-index: 10000 !important;
  126. }
  127. #cmt-btn {
  128. left: 1%;
  129. }
  130. #top-btn {
  131. right: 1%;
  132. }`
  133. */
  134.  
  135. /**
  136. * Example = {
  137. * -right: 1%;
  138. * +left: 0%; "Top" will be moved to bottom left
  139. * The !important is needed for any color changes due to button matching site style.
  140. * +color: red !important; "Top" will have red text
  141. * +border: 2px solid #000 !important; "Top" will have black border with 2px width
  142. * ...}
  143. */