fandom-debloater.user.js 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // ==UserScript==
  2. // @name YA-Fandom-Debloater
  3. // @namespace Violentmonkey Scripts
  4. // @match https://*.fandom.com/*
  5. // @grant none
  6. // @version 1.5
  7. // @author Steve0Greatness
  8. // @description (Yet Another Fandom Debloater)
  9. // @copyright GPL-v3
  10. // @homepageURL https://notabug.org/Steve0Greatness/Yet-Another-Fandom-Debloater
  11. // @supportURL https://notabug.org/Steve0Greatness/Yet-Another-Fandom-Debloater/issues
  12. // @updateURL https://notabug.org/Steve0Greatness/Yet-Another-Fandom-Debloater/raw/master/fandom-debloater.user.js
  13. // ==/UserScript==
  14. if (location.search == "?action=edit&redlink=1") location.replace(location.pathname);
  15. `<div class="sticky-toc-wrapper" aria-labelledby="mw-sticky-toc-heading"><button class="page-side-tool sticky-toc-toggle" data-wds-tooltip="Contents" data-wds-tooltip-position="right" data-tooltip-attached="1" aria-label="Contents"><svg class="wds-icon wds-icon-small toc-small-icon">
  16. <use href="#wds-icons-bullet-list-small"></use>
  17. </svg></button><div id="sticky-toc" role="navigation" class="toc sticky-toc"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-sticky-toc-heading">Contents</h2><svg class="wds-icon wds-icon-tiny sticky-toc-close">
  18. <use href="#wds-icons-close-tiny"></use>
  19. </svg></div><ul></ul>
  20. </div></div>`
  21. waitForElementToDisplay("#p-tb .rail-module__list", function() {
  22. const PageTools = document.querySelectorAll("#p-tb .rail-module__list :any-link");
  23. const toolsWrapper = buildToolsButton();
  24. for (let i = 0; i < PageTools.length; i++) {
  25. toolsWrapper.querySelector("ul").innerHTML += `<li><a href="${PageTools[i].href}">${PageTools[i].innerText}</a></li>`;
  26. }
  27. document.querySelector(".page-side-tools").appendChild(toolsWrapper)
  28. }, 500, 2000);
  29. function buildToolsButton() {
  30. const StickyToolsWrapper = document.createElement("div");
  31. StickyToolsWrapper.classList.add("sticky-toc-wrapper")
  32. StickyToolsWrapper.setAttribute("aria-labelledby", "mw-sticky-tools-heading")
  33. StickyToolsWrapper.innerHTML = `<button class="page-side-tool sticky-toc-toggle" data-wds-tooltip="Page Tools" data-wds-tooltip-position="right" data-tooltip-attached="1" aria-label="Page Tools">
  34. <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="none" viewBox="0 0 24 24" class="wds-icon wds-icon-small toc-small-icon">
  35. <g clip-path="url(#wrench_clip0)">
  36. <path d="M23 4c-.265 0-.52.105-.707.293C22.105 4.48 22 4.735 22 5v2h-5V2h2c.265 0 .52-.105.707-.293C19.895 1.52 20 1.265 20 1c0-.265-.105-.52-.293-.707C19.52.105 19.265 0 19 0h-5c-.132 0-.262.024-.384.074-.122.05-.233.123-.326.216l-4 4c-.093.093-.166.204-.216.326C9.024 4.738 9 4.868 9 5v4.59l-7.71 7.7C.571 18.009.167 18.984.167 20c0 1.017.404 1.991 1.123 2.71.719.719 1.694 1.122 2.71 1.122s1.991-.403 2.71-1.122l7.7-7.71H19c.132 0 .262-.024.384-.074.122-.05.233-.123.326-.216l4-4c.093-.093.166-.204.216-.326.05-.122.075-.252.074-.384V5c0-.265-.105-.52-.293-.707C23.52 4.105 23.265 4 23 4zm-1 5.59L18.59 13H14c-.132 0-.262.024-.384.074-.122.05-.233.123-.326.216l-8 8c-.342.342-.806.534-1.29.534s-.948-.192-1.29-.534c-.342-.342-.534-.806-.534-1.29s.192-.948.534-1.29l8-8c.093-.093.166-.204.216-.326.05-.122.075-.252.074-.384V5.41L14.41 2H15v6c0 .265.105.52.293.707.187.188.442.293.707.293h6v.59z"></path>
  37. </g>
  38. <defs>
  39. <clipPath id="wrench_clip0">
  40. <path fill="#fff" d="M0 0H24V24H0z"></path>
  41. </clipPath>
  42. </defs>
  43. </svg>
  44. </button><div id="sticky-tools" role="navigation" class="toc sticky-toc wds-is-hidden"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-sticky-tools-heading">Page Tools</h2><svg id="tools-close-button" class="wds-icon wds-icon-tiny sticky-toc-close">
  45. <use href="#wds-icons-close-tiny"></use>
  46. </svg></div><ul></ul></div>`
  47. StickyToolsWrapper.querySelector("button").addEventListener("click", function() {
  48. StickyToolsWrapper.querySelector("#sticky-tools").classList.toggle("wds-is-hidden");
  49. });
  50. StickyToolsWrapper.querySelector("#tools-close-button").addEventListener("click", function() {
  51. if (!StickyToolsWrapper.querySelector("#sticky-tools").classList.contains("wds-is-hidden")) StickyToolsWrapper.querySelector("#sticky-tools").classList.add("wds-is-hidden");
  52. });
  53. return StickyToolsWrapper;
  54. }
  55. function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs, stopAfterLoops=-1) {
  56. var startTimeInMs = Date.now();
  57. var index = 0;
  58. (function loopSearch() {
  59. if (document.querySelector(selector) != null) {
  60. console.debug(`Found ${selector}!`)
  61. callback();
  62. return;
  63. }
  64. setTimeout(function () {
  65. if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs)
  66. return;
  67. loopSearch();
  68. }, checkFrequencyInMs);
  69. })();
  70. }