Skip to content

Instantly share code, notes, and snippets.

@oliver4888
Last active January 4, 2024 11:54
Show Gist options
  • Save oliver4888/b877ad26d0ef96b6fb28e0e53068ac41 to your computer and use it in GitHub Desktop.
Save oliver4888/b877ad26d0ef96b6fb28e0e53068ac41 to your computer and use it in GitHub Desktop.
UserScript to clean up Fandom's new UI
// ==UserScript==
// @name Fandom site cleanup
// @namespace https://github.com/oliver4888/
// @version 1.0.1
// @description Clean up the garbage Fandom UI
// @author oliver4888
// @match *.fandom.com/*
// @icon https://www.google.com/s2/favicons?domain=fandom.com
// @grant none
// @downloadUrl https://gist.github.com/oliver4888/b877ad26d0ef96b6fb28e0e53068ac41/raw/fandom-site-cleanup.user.js
// @updateUrl https://gist.github.com/oliver4888/b877ad26d0ef96b6fb28e0e53068ac41/raw/fandom-site-cleanup.user.js
// ==/UserScript==
(function() {
'use strict';
// Don't run on frames or iframes
if (window.top != window.self) return;
const documentHead = document.getElementsByTagName("head")[0];
// Everything hidden here belongs in the bin
const inlineCssEle = document.createElement("style");
inlineCssEle.innerText = `\
#WikiaBar, .page__right-rail, #mixed-content-footer, .ad-slot-placeholder, .page-side-tool.content-size-toggle {\
display:none !important;\
}\
.resizable-container{\
max-width: 100% !important;\
width: 95% !important;\
}`;
documentHead.appendChild(inlineCssEle);
// We force the width that this class gives, but we should add it anyway in case some other part of the UI checks for it
if (!document.documentElement.classList.contains("is-content-expanded")){
document.documentElement.classList.add("is-content-expanded");
}
// Some of the MediaWiki API is not available straight away
const intervalId = setInterval(function () {
// eslint-disable-next-line no-undef
if (typeof $ === "function" && typeof mw.loader.using === "function") {
clearInterval(intervalId);
MWReady();
}
}, 25);
function MWReady () {
try
{
// This is in here because it thows an error outside of our interval, perhaps it doesn't appear straight away?
// I don't know what this class does, but since we remove the right rail anyway it can't hurt to remove the class right?
document.getElementsByClassName("page has-right-rail")[0].classList.remove("has-right-rail");
}
catch (err) {
console.log(err);
}
// Some Fandom staff member posted a snippet to remove the popup search box, below is the script and css that it fetches
const searchScript = document.createElement("script");
searchScript.setAttribute("src", "https://dev.fandom.com/wiki/MediaWiki:UCXSearchBar.js?action=raw&ctype=text/javascript");
const template = document.createElement("template");
template.innerHTML = `<link rel="stylesheet" type="text/css" href="https://dev.fandom.com/wiki/MediaWiki:UCXSearchBar.css?action=raw&amp;ctype=text/css" media="all">`;
documentHead.appendChild(searchScript);
documentHead.appendChild(template.content.firstChild);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment