FextraLife Tweaks

Implements various tweaks to FextraLife wiki(s)

目前为 2022-05-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name FextraLife Tweaks
  3. // @description Implements various tweaks to FextraLife wiki(s)
  4. // @version 1.2
  5. // @author Magic <magicoflolis@tuta.io>
  6. // @license MIT
  7. // @icon https://fextralife.com/wp-content/uploads/2015/07/flswords-152.png
  8. // @namespace https://github.com/magicoflolis/userscriptrepo/tree/master/FextraLifeTweaks
  9. // @homepageURL https://github.com/magicoflolis/userscriptrepo/tree/master/FextraLifeTweaks
  10. // @supportURL https://github.com/magicoflolis/userscriptrepo/issues/new
  11. // @match https://*.wiki.fextralife.com/*
  12. // @exclude https://www.wiki.fextralife.com/*
  13. // @grant none
  14. // @run-at document-start
  15. // ==/UserScript==
  16.  
  17. // Defaults are listed at the end of the user script.
  18. let Remove_Clutter = true, // Removes some clutter + wider page
  19. DisableComments = false, // Disables comments
  20. AutoScroll = true, // Automatically scrolls on page load
  21. Scroll_Amount = 202, // Scroll amount for "Top" button.
  22. debug = false;
  23.  
  24. const fltCSS = `[id^=div-gpt-ad],.ad-banner,#sidebar-wrapper,.wrap>#content-add-a,.section-heading,.collapse-com>#pmalerts,br{content:"" !important;display:none !important;visibility:hidden !important;margin:0px 0px 0px 0px !important;padding:0px 0px 0px 0px !important;width:0px !important;max-width:0px !important;min-width:0px !important;height:0px !important;max-height:0px !important;min-height:0px !important}#cmt-btn,#top-btn{transition:top 100ms ease-in-out 100ms;cursor:pointer;top:100%;font-weight:bold;font-family:inherit;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;height:auto;border-radius:16px;margin:0 3px;line-height:25px;padding:0 20px;text-transform:uppercase;text-align:center;position:fixed;z-index:10000 !important}#cmt-btn{left:1%}#top-btn{right:1%}.collapse-com{cursor:default !important}
  25. `; // Stylesheet
  26.  
  27. // Userscript Code
  28. "use strict";
  29. const err = (...error)=>{
  30. console.error("[%cFLT%c] %cERROR", "color: rgb(180, 178, 176);", "", "color: rgb(249, 24, 128);", ...error);
  31. }, info = (...message)=>{
  32. if (!debug) {
  33. return;
  34. };
  35. console.info("[%cFLT%c] %cINF", "color: rgb(180, 178, 176);", "", "color: rgb(0, 186, 124);", ...message);
  36. }, log = (...message)=>{
  37. if (!debug) {
  38. return;
  39. };
  40. console.log("[%cFLT%c] %cDBG", "color: rgb(180, 178, 176);", "", "color: rgb(255, 212, 0);", ...message);
  41. }, ael = (elm = document, event, callback)=>{
  42. return elm.addEventListener(event, callback);
  43. }, create = (element, type, cname, iname, value)=>{
  44. let el = document.createElement(element);
  45. type !== "none" ? el.type = type : false;
  46. cname ? el.className = cname : false;
  47. iname ? el.id = iname : false;
  48. value ? el.value = value : false;
  49. return el;
  50. }, loadCSS = (css, name = "common")=>{
  51. info("injecting CSS");
  52. document.head.insertAdjacentHTML('beforeend', `<style id="flt-${name}">${css}</style>`);
  53. },
  54. query = async (element)=>{
  55. while(document.querySelector(element) === null){
  56. await new Promise((resolve)=>requestAnimationFrame(resolve)
  57. );
  58. }
  59. return document.querySelector(element);
  60. }, qs = (element)=>{
  61. return document.querySelector(element);
  62. }, qsA = (element)=>{
  63. return document.querySelectorAll(element);
  64. }, cmt_btn = create("input", "button", "btn btn-default btn-xs", "cmt-btn", "Comments"), top_btn = create("input", "button", "btn btn-default btn-xs", "top-btn", "Top"), main = ()=>{
  65. try {
  66. info("Running script");
  67. loadCSS(fltCSS);
  68. query("#wrapper").then((wrapper)=>{
  69. if (Remove_Clutter) {
  70. info("Removing clutter");
  71. wrapper.setAttribute("style", "padding-left: 0px !important");
  72. qsA("ul").forEach((item, i)=>{
  73. qsA("ul")[i].setAttribute("style", "max-width: 100% !important");
  74. });
  75. };
  76. query("button#btnPostCommentu").then((dw)=>{
  77. if (DisableComments) {
  78. info("Hiding comments");
  79. qs(".discussion-wrapper").setAttribute("style", 'display: none !important');
  80. } else {
  81. ael(cmt_btn, "click", ()=>{
  82. return dw.scrollIntoView();
  83. });
  84. };
  85. });
  86. ael(top_btn, "click", ()=>{
  87. return wrapper.scrollIntoView();
  88. });
  89. info("injecting buttons...");
  90. wrapper.append(top_btn, cmt_btn);
  91. AutoScroll ? qs("#page-content-wrapper").scrollIntoView() : false;
  92. ael(document, "scroll", ()=>{
  93. return document.documentElement.scrollTop > Scroll_Amount ? (top_btn.setAttribute("style", 'top: 90% !important'), !DisableComments ? cmt_btn.setAttribute("style", 'top: 90% !important') : false) : (top_btn.setAttribute("style", 'top: 100% !important'), !DisableComments ? cmt_btn.setAttribute("style", 'top: 100% !important') : false);
  94. });
  95. info("Done!");
  96. });
  97. } catch (e) {
  98. error(e);
  99. };
  100. };
  101. ael(window, "load", main);
  102.  
  103.  
  104. /**
  105. * Defaults:
  106. *
  107. * Remove_Clutter = true // Removes some clutter + wider page
  108. * DisableComments = false,
  109. * AutoScroll = true,
  110. * Scroll_Amount = 202 // Set to 0 disables auto scroll AND "Top" button
  111. */

QingJ © 2025

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