User:Bebiezaza/hydrafication.js

/* -- Functions -- */ /** * Better createElement, with the ability to add child element and attributes as you create the element * * @param { String } nodename Required. The name of the element you want to create * @param { Array } child Child elements you want to put inside this element * @param { Object } attributes Styles, Classes, IDs, etc * @returns HTML Node */ function createElement(nodename, child, attributes) { var element = document.createElement(nodename); if (!(child instanceof Array)) child = [child];

for (var i = 0; i < child.length; i++) { var child_members = child[i]; if (typeof child_members == 'string') child_members = document.createTextNode(child_members); if (child_members) element.appendChild(child_members); }

if (typeof attributes == 'object') { for (var k in attributes) { switch (k) { case 'class': element.className = attributes[k]; break; default: element.setAttribute(k, attributes[k]); }       }    }    return element; }

/** * This function moves Fandom topnav to original Mediawiki leftnav * * @param { Number } elementNum Required. The number of the element, starting 1 at the menu after "Explore" * @param { String } headerName Required. The name you want the header of the section to appear * @returns HTML Node */ function makeSidebar(elementNum, headerName) { var headerName_squashed = headerName.replace(/\ /g, ""); var fandomtop = document.getElementsByClassName("wds-tabs")[0].getElementsByClassName("wds-dropdown")[elementNum].childNodes[3].firstElementChild; var sidebarCount = fandomtop.childElementCount; var sidebar = createElement('ul', "", {       'class': "vector-menu-content-list"    }); var sidebarHeader = createElement('h3', "", { 'id': "p-" + headerName_squashed + "-label" }); sidebarHeader.innerHTML = headerName;

for (var i = 0; i < sidebarCount; i++) { var count = i+1; sidebar.appendChild(fandomtop.childNodes[count]); }

var sidebarDiv = createElement('div', sidebar, {       'class': "vector-menu-content"    });

var sidebarDiv_top = createElement('div', [sidebarHeader, sidebarDiv], {       'id': "p-" + headerName_squashed,        'role': "navigation",        'class': "sidebar-header vector-menu-portal",        'aria-labelledby': "p-" + headerName_squashed + "-label"    });

return sidebarDiv_top; }

/* Just for removing Fandom Fluffs */ function removeFluff(node) { if (node) node.remove; }

/* -- Functions end -- */

/* -- Image fixes -- */ function fixImage { // Credits to User:DelimanCZ/common.js var imgs = document.getElementsByTagName('img'); for(i=0; i= 176 && imgs[i].width <= 180) { imgs[i].width = 300; imgs[i].style.height = 'auto'; imgs[i].style.imageRendering = 'pixelated'; }			imgs[i].style.imageRendering = 'pixelated'; console.log("ahoj"); }	var imgsFigure = document.getElementsByClassName('thumb'); for(i=0; i<imgsFigure.length; i++){ if (imgsFigure[i].style.width == "180px") { imgsFigure[i].style.width = "300px"; }	}	// Fixes link of images var imgsA = document.getElementsByClassName('page__main')[0].getElementsByClassName('image'); for(i=0; i<imgsA.length; i++){ var imgsAHrefCutIndex = imgsA[i].href.search('/revision'); if (imgsAHrefCutIndex != -1) { console.log(imgsA[i].href); var imgsAHref = imgsA[i].href.substring(0, imgsAHrefCutIndex);//var imgsAHref = imgsA[i].href.replace(,); var hrefFileIndex = imgsAHref.lastIndexOf("/"); imgsAHref = imgsAHref.substring(hrefFileIndex+1, imgsAHref.length); imgsAHref = "https://minecraft.gamepedia.com/File:" + imgsAHref; imgsA[i].href = imgsAHref; console.log(imgsAHref); }	} }

/* -- Recreate mediawiki navigations -- */ function recreateMwNavigation { var nav_div = createElement('div', "", { 'id': "mw-navigation" }); $(".resizable-container").before(nav_div);

/* ===== Recreate mw-panel left navigation ===== */ var logo = createElement('div', "", { 'id': "p-logo", 'role': "banner" }); logo.appendChild(document.getElementsByClassName("fandom-community-header__image")[0]); logo.firstElementChild.href = "//minecraft.gamepedia.com";

var panel_div = createElement('div', logo, { 'id': "mw-panel" }); $("#mw-navigation").append(panel_div);

// move fandom topnav to normal leftnav panel_div.appendChild(makeSidebar(1, "Minecraft Wiki")); panel_div.appendChild(makeSidebar(2, "Games")); panel_div.appendChild(makeSidebar(3, "Useful Pages")); panel_div.appendChild(makeSidebar(4, "Minecraft Links")); panel_div.appendChild(makeSidebar(5, "Gamepedia")); // delete residue if (document.getElementsByClassName("community-header-wrapper")[0]) document.getElementsByClassName("community-header-wrapper")[0].remove; // remove Fandom main header

// page tools if (document.getElementsByClassName("page__right-rail")[0]) { // move page tools back to leftnav var toolbox = createElement('ul', "", { 'class': "vector-menu-content-list" }); var toolbox_div = createElement('div', toolbox, { 'class': "vector-menu-content" }); var toolbox_header = createElement('h3', "", { 'id': "p-tb-label" }); toolbox_header.innerHTML = "Page Tools";

var toolbox_div_top = createElement('div', [toolbox_header, toolbox_div], {           'id': "p-tb",            'role': "navigation",            'class': "sidebar-header vector-menu-portal",            'aria-labelledby': "p-tb-label"        }); panel_div.appendChild(toolbox_div_top); setTimeout(function { // wait for page tools to load bruh           var fandom_tb = document.getElementsByClassName("sticky-modules-wrapper")[0].firstElementChild.lastElementChild;            if (fandom_tb) {                var fandom_tb_count = fandom_tb.childElementCount;

for (var i = 0; i < fandom_tb_count; i++) { var count = i+1; toolbox.appendChild(fandom_tb.childNodes[count]); }           }        }, 1000);    }

// languages if (document.getElementsByClassName("page-header__languages")[0]) { var fandom_lang = document.getElementsByClassName("page-header__languages")[0].lastElementChild.lastElementChild.lastElementChild; var fandom_lang_count = fandom_lang.childElementCount; var lang = createElement('ul', "", { 'class': "vector-menu-content-list" }); var lang_header = createElement('h3', "", { 'id': "p-lang-label" }); lang_header.innerHTML = "Languages"; for (var i = 0; i < fandom_lang_count; i++) { var count = i+1; lang.appendChild(fandom_lang.childNodes[count]); }       var lang_div = createElement('div', lang, { 'class': "vector-menu-content" }); var lang_div_top = createElement('div', [lang_header, lang_div], {           'id': "p-lang",            'role': "navigation",            'class': "sidebar-header vector-menu-portal",            'aria-labelledby': "p-lang-label"        }); panel_div.appendChild(lang_div_top); } }

/* -- Alters editsection button -- */ function alterEditsectionButton { if (mw.config.get("wgAction") == "view") { var editbuttons = document.getElementsByClassName("mw-editsection"); var editbuttons_count = editbuttons.length; for (var i = 0; i < editbuttons_count; i++) { if (!editbuttons[i].childNodes[1].firstChild) { editbuttons[i].childNodes[2].remove; editbuttons[i].childNodes[2].innerHTML = "edit"; } else editbuttons[i].childNodes[1].innerHTML = "edit"; }   } }

/* -- Alter Fandom fluffs -- */ function alterFandomFluffs { if (document.getElementsByClassName("fandom-sticky-header__logo")[0]) document.getElementsByClassName("fandom-sticky-header__logo")[0].href = "//www.gamepedia.com"; if (document.getElementsByClassName("fandom-sticky-header__sitename")[0]) { document.getElementsByClassName("fandom-sticky-header__sitename")[0].innerHTML = "Help"; document.getElementsByClassName("fandom-sticky-header__sitename")[0].href = "//support.gamepedia.com"; } }

/* -- Remove Fandom fluffs -- */ function removeFandomFluffs { // unused stuffs in netbar removeFluff(document.getElementsByClassName("fandom-community-header__local-navigation")[0]); // language removeFluff(document.getElementsByClassName("page-header__top")[0]); // remove Fandom meta & language header removeFluff(document.getElementsByClassName("page-footer__languages")[0]); // remove Fandom language footer // dumb tools removeFluff(document.getElementsByClassName("global-navigation")[0]); // remove Fandom sidenav removeFluff(document.getElementsByClassName("page-side-tools__wrapper")[0]); // remove page side tools removeFluff(document.getElementById("WikiaBar")); // remove dumb tool tab on bottom right // content if (document.getElementsByClassName("toctitle")[0]) document.getElementsByClassName("toctitle")[0].firstElementChild.firstElementChild.remove; // remove TOC image thingy removeFluff(document.getElementsByClassName("toctogglespan")[0]); // remove TOC collapse button if (mw.config.get("wgIsMainPage")) document.getElementsByClassName("page-header")[0].remove; // remove home page header // why keep it here in the first place anyways // footer removeFluff(document.getElementById("mixed-content-footer")); // remove Fandom content footer removeFluff(document.getElementsByClassName("wds-global-footer")[0]); // Fandom doesn't deserve any credit in forcing FandomDesktop on us

setTimeout(function { // wait for page tools to load bruh       removeFluff(document.getElementsByClassName("page__right-rail")[0]); // remove Fandom rightnav    }, 1100); }

function fandomAdMove { if (document.getElementsByClassName("top-ads-container")[0]); }

function startHydra { fixImage; recreateMwNavigation; alterEditsectionButton; alterFandomFluffs; removeFandomFluffs; console.log("JS End"); }

$(document).ready(function {   console.log("Every night, I can feel my leg… and my arm… even my fingers.");    mw.loader.getScript( '//minecraft.fandom.com/wiki/User:Bebiezaza/revertLogo.js?action=raw&ctype=text/javascript' ).then(function { startHydra; }); });