fandom.com - Remove bloatware

Removes unnecessary elements from fandom website, leaving only what's important.

Fra og med 24.04.2024. Se den nyeste version.

// ==UserScript==
// @name           fandom.com - Remove bloatware
// @namespace      fandom.com utils
// @match          https://*.fandom.com/*
// @icon           https://www.google.com/s2/favicons?sz=64&domain=fandom.com
// @grant          none
// @version        1.0.0
// @author         eye-wave
// @license        GPL-3.0+
// @description    Removes unnecessary elements from fandom website, leaving only what's important.
// ==/UserScript==
"use strict";
const d = document;
function $(query, all = false) {
  if (all)
    return d.querySelectorAll(query);
  return d.querySelector(query);
}
const toResize = [".fandom-community-header__background", ".main-container"];
const massRemove = ["iframe", "link[as='script']", "meta", "script", "style:not([type='text/css'])"];
const removeListSingle = [
  ".bottom-ads-container",
  ".fandom-sticky-header",
  ".global-navigation",
  ".global-registration-buttons",
  ".notifications-placeholder",
  ".page__right-rail",
  ".page-side-tools",
  ".right-rail-wrapper",
  ".top-ads-container",
  ".unified-search__layout__right-rail",
  "#age-gate",
  "#featured-video__player-container",
  "#global-explore-navigation",
  "#p-views",
  "#WikiaBar",
  "body > svg + *",
  "div>div[data-tracking-opt-in-overlay]",
  "footer"
];
removeBloatware();
function removeBloatware() {
  removeListSingle.forEach((q) => $(q)?.remove());
  massRemove.forEach((q) => $(q, true).forEach((e) => e?.remove()));
  for (const q of toResize) {
    const el = $(q);
    if (!el)
      continue;
    el.style.width = "100%";
    el.style.margin = 0;
  }
}
removeExcessiveBodyClassNames();
function removeExcessiveBodyClassNames() {
  for (const c of d.body.classList) {
    if (c.includes("skin-fandom"))
      continue;
    d.body.classList.remove(c);
  }
}
function removeExcessiveHtmlAttrs() {
  d.documentElement.removeAttribute("class");
  d.documentElement.removeAttribute("dir");
  d.documentElement.removeAttribute("style");
}
new MutationObserver((mutationsList) => {
  for (const mutation of mutationsList) {
    if (mutation.type === "childList")
      removeBloatware();
    if (mutation.type === "attributes") {
      removeExcessiveBodyClassNames();
      removeExcessiveHtmlAttrs();
    }
  }
}).observe(d.documentElement, {
  childList: true,
  subtree: true,
  attributes: true,
  attributeOldValue: true
});
window.ads = void 0;