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

/* -- Redo footer -- */ function footer { var footerPlaces_about = createElement('li', createElement('a', "About Minecraft Wiki", { 'href': "//minecraft.gamepedia.com/Minecraft_Wiki:About" }), { 'id': "footer-places-about" }); var footerPlaces_disclaimer = createElement('li', createElement('a', "Disclaimers", { 'href': "//minecraft.gamepedia.com/Minecraft_Wiki:General_disclaimer" }), { 'id': "footer-places-disclaimer" }); var footerPlaces_mobileview = createElement('li', createElement('a', "Mobile view", { 'href': "//minecraft.gamepedia.com/index.php?title=" + mw.config.get("wgPageName") + "&mobileaction=toggle_view_mobile" }), { 'id': "footer-places-mobileview" }); var footerPlaces = createElement('ul', [footerPlaces_about, footerPlaces_disclaimer, footerPlaces_mobileview], {       'id': "footer-places"    }); var footerCopyright = createElement('li', createElement('a', createElement('img', "", { 'src': "//i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" }), { 'href': "//creativecommons.org/licenses/by-nc-sa/3.0/" }), { 'id': "footer-copyrightico" }); // TODO: when mw1.36, change mediawiki icon var footerPoweredBy = createElement('li', [       createElement('a', createElement('img', "", { 'src': "//web.archive.org/web/20180727145016im_/https://minecraft.gamepedia.com/resources/assets/poweredby_mediawiki_88x31.png" }), { 'href': "//www.mediawiki.org" }),        createElement('a', createElement('img', "", { 'src': "//web.archive.org/web/20180727145016im_/https://minecraft.gamepedia.com/skins/Hydra/images/icons/poweredbyhydra.png" }), { 'href': "https://help.gamepedia.com/What_is_Hydra" }) ], {            'id': "footer-poweredbyico"    }); var footerIcons = createElement('ul', [footerCopyright, footerPoweredBy], { 'id': "footer-icons" }); var mainFooter = createElement('div', [footerPlaces, footerIcons], {       'class': "footer_gamepedia"    }); if (document.getElementsByClassName("license-description")[0]) mainFooter.insertBefore(document.getElementsByClassName("license-description")[0], mainFooter.firstChild); document.getElementsByClassName("resizable-container")[0].parentNode.appendChild(mainFooter);

if (mw.config.get('wgIsArticle')) { var api = new mw.Api; api.get({           action: 'query',            prop: 'revisions',            indexpageids: 1,            titles: mw.config.get('wgPageName'),            rvprop: 'timestamp',            rvslots: 'main',            rvlimit: 1,            meta: 'userinfo',            uiprop: 'options'        }).then(function(data) {            var id = data.query.pageids[0];            var time = data.query.pages[id].revisions[0].timestamp;            console.log(time);            time = time.substring(0, time.length - 1);            console.log(time);

var offset = Math.abs(data.query.userinfo.options.timecorrection.split("|")[1]); var offsethour = Math.floor(offset / 60); if (String(offsethour).length === 1) offsethour = "0" + offsethour; // time offset are inverted because UTC if (data.query.userinfo.options.timecorrection.split("|")[1] < 0) offsethour = "+" + offsethour; else offsethour = "-" + offsethour; var offsetminute = offset % 60; if (String(offsetminute).length === 1) offsetminute = "0" + offsetminute; offset = offsethour + ":" + offsetminute;

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var datetime = new Date(time + offset);

var day = datetime.getUTCDate; var month = months[datetime.getUTCMonth]; var year = datetime.getUTCFullYear; var hour = datetime.getUTCHours; var minute = datetime.getUTCMinutes; if (String(hour).length === 1) hour = "0" + hour; if (String(minute).length === 1) minute = "0" + minute; var lastEdit = createElement('div', "This page was last edited on " + day + " " + month + " " + year + ", at " + hour + ":" + minute + ".", {               'id': "footer-info-lastmod"            });

mainFooter.insertBefore(lastEdit, mainFooter.firstChild); });   } }

/* -- 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 && document.getElementsByClassName("toctitle")[0].firstElementChild.firstElementChild) document.getElementsByClassName("toctitle")[0].firstElementChild.firstElementChild.remove; // remove TOC collapse button 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-collapsible-panel__header")[0]); // remove category header tab 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; footer; console.log("JS End"); }

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