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; }

/* -- 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]);

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")) { // 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); } }

function removeFandomFluffs { if (document.getElementsByClassName("global-navigation")[0]) document.getElementsByClassName("global-navigation")[0].remove; // remove Fandom sidenav if (document.getElementsByClassName("page-side-tools__wrapper")[0]) document.getElementsByClassName("page-side-tools__wrapper")[0].remove; // remove page side tools if (document.getElementsByClassName("page-header__top")[0]) document.getElementsByClassName("page-header__top")[0].remove; // remove Fandom meta & language header if (document.getElementById("WikiaBar")) document.getElementById("WikiaBar").remove; if (document.getElementsByClassName("wds-global-footer")[0]) document.getElementsByClassName("wds-global-footer")[0].remove; // fandom doesn't deserve any credit in forcing FandomDesktop on us

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

if (mw.config.get("wgIsMainPage")) document.getElementsByClassName("page-header")[0].remove; // remove home page header // why keep it here in the first place anyways }

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

function startHydra { fixImage; recreateMwNavigation; 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( 'http://localhost/minecraftwikiskinedit/revertLogo.js' ).then(function { startHydra; // }); });