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").after(nav_div);

/* ===== Recreate mw-head header navigation ===== */ var head_div = createElement('div', "", { 'id': "mw-head" }); $("#mw-navigation").append(head_div);

/* left navigation */ var pageLink, pageLink_talk; if (mw.config.get('wgNamespaceNumber') % 2 === 0 || mw.config.get('wgNamespaceNumber') === -1) { pageLink = mw.config.get('wgPageName'); if (mw.config.get('wgNamespaceNumber') === 0) pageLink_talk = "Talk:" + mw.config.get('wgTitle'); else pageLink_talk = mw.config.get('wgCanonicalNamespace') + "_talk:" + mw.config.get('wgTitle'); } else if (mw.config.get('wgNamespaceNumber') % 2 === 1) { pageLink_talk = mw.config.get('wgPageName'); if (mw.config.get('wgNamespaceNumber') === 0) pageLink = mw.config.get('wgTitle'); else pageLink = mw.config.get('wgPageName').replace(/_talk/ig, ""); }

var namespaceTalk_title = "Talk"; var namespaceMain_title; if ([0, 1].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Page"; else if ([2, 3].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "User"; else if ([4, 5].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Project"; else if ([6, 7].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "File"; else if ([8, 9].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Interface"; else if ([10, 11].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Template"; else if ([12, 13].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Help"; else if ([14, 15].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Category"; else if ([-1].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) namespaceMain_title = "Special page"; else namespaceMain_title = "Page";

if (mw.config.get('wgTitle') === "Minecraft Wiki") namespaceMain_title = "Main page";

var namespaceMain_link = createElement('a', namespaceMain_title, {       'href': "/wiki/" + pageLink,        'title': "View the content page"    });

var namespaceMain = createElement('li', namespaceMain_link, {       'id': "ca-main",        'class': "mw-list-item"    }); if (document.getElementById("ca-talk")) { var talkOriginal = document.getElementById("ca-talk"); var talkLink = createElement('a', namespaceTalk_title, {           'href': talkOriginal.href,            'title': "Talk about the content page"        }); var namespaceTalk = createElement('li', talkLink, {           'id': "ca-talk",            'class': "mw-list-item"        }); if (talkOriginal.classList.contains("new")) { namespaceTalk.classList.add("new"); talkLink.title += " (page does not exist)"; }       talkOriginal.remove; } else { var namespaceTalk_link = createElement('a', namespaceTalk_title, {           'href': "/wiki/" + pageLink_talk,            'title': "Talk about the content page"        }); var namespaceTalk = createElement('li', namespaceTalk_link, {           'id': "ca-talk",            'class': "mw-list-item"        }); }   if (mw.config.get('wgNamespaceNumber') % 2 === 0) namespaceMain.classList.add("selected"); else if (mw.config.get('wgNamespaceNumber') % 2 === 1) namespaceTalk.classList.add("selected");

if (mw.config.get('wgNamespaceNumber') === -1) { namespaceMain.classList.add("selected"); namespaceTalk = undefined; }

var namespace = createElement('ul', [namespaceMain, namespaceTalk], {       'class': "vector-menu-content-list"    });

var namespace_div = createElement('div', [namespace], {       'class': "vector-menu-content"    });

var namespace_nav = createElement('nav', namespace_div, {       'id': "p-namespaces",        'role': "navigation",        'class': "vector-menu vector-menu-tabs"    });

var leftNav_div = createElement('div', namespace_nav, {       'id': "left-navigation"    }); if (document.getElementById("ca-talk")) document.getElementById("ca-talk").remove; head_div.appendChild(leftNav_div);

/* right navigation */ if (mw.config.get('wgArticleId') !== 0) { var view_link = createElement('a', "View", {           'href': "/wiki/" + mw.config.get('wgPageName')        }); var view = createElement('li', view_link, {           'id': "ca-view",            'class': "mw-list-item"        }); if (mw.config.get('wgAction') === "view") view.classList.add("selected"); }

var edit, source, history; if (document.getElementById("ca-edit")) { var editOriginal = document.getElementById("ca-edit"); var editLink = createElement('a', "", {           'href': editOriginal.href        }); var editText = editOriginal.innerText.trim;

editLink.innerHTML = editText.slice(0, 1) + editText.slice(1).toLocaleLowerCase; editOriginal.remove; edit = createElement('li', editLink, {           'id': "ca-edit",            'class': "mw-list-item"        }); if (mw.config.get('wgAction') === "edit") edit.classList.add("selected"); }

if (document.getElementById("ca-viewsource")) { var sourceOriginal = document.getElementById("ca-viewsource"); var sourceLink = createElement('a', "", {           'href': sourceOriginal.href        }); var sourceText = sourceOriginal.innerText.trim; sourceLink.innerHTML = sourceText.slice(0, 1) + sourceText.slice(1).toLocaleLowerCase; sourceOriginal.remove; source = createElement('li', sourceLink, {           'id': "ca-viewsource",            'class': "mw-list-item"        }); if (mw.config.get('wgAction') === "edit") source.classList.add("selected"); }

if (document.getElementById("ca-history")) { var historyOriginal = document.getElementById("ca-history"); var historyLink = createElement('a', "", {           'href': historyOriginal.href        }); var historyText = historyOriginal.innerText.trim; historyLink.innerHTML = historyText.slice(0, 1) + historyText.slice(1).toLocaleLowerCase; historyOriginal.parentNode.remove; history = createElement('li', historyLink, {           'id': "ca-history",            'class': "mw-list-item"        }); if (mw.config.get('wgAction') === "history") history.classList.add("selected"); }

var pages = createElement('ul', [view, edit, source, history], {       'class': "vector-menu-content-list"    });

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

var pages_nav = createElement('nav', pages_div, {       'id': "p-pages",        'role': "navigation",        'class': "vector-menu vector-menu-tabs"    }); //    if (mw.config.get('wgNamespaceNumber') !== -1) { var actions = createElement('ul', "", {           'class': "vector-menu-content-list"        });

for (var i = 0; i < document.querySelectorAll("#p-cactions li").length; i++) { var actions_original = document.querySelectorAll("#p-cactions li")[i]; if (!actions_original.firstElementChild?.id) continue; if (actions_original.firstElementChild.id == "ca-talk") continue; actions_original.firstElementChild.innerHTML = actions_original.firstElementChild.innerHTML.trim; var actions_link = actions_original.firstElementChild; var actions_list = createElement('li', actions_link, {               'id': actions_original.firstElementChild.id,                'class': "mw-list-item"            }); actions_link.id = ""; actions.appendChild(actions_list); }

// var actions_input = createElement('input', "", {       //     'type': "checkbox",        //     'id': "p-cactions-checkbox",        //     'class': "vector-menu-checkbox",        //     'aria-labelledby': "p-cactions-label",        //     'role': "button",        //     'aria-haspopup': "true",        //     'data-event-name': "ui.dropdown-p-cactions"        // });

var actions_header = createElement('h3', "More", {           'id': "p-cactions-label",            'class': "vector-menu-heading"        });

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

var actions_nav = createElement('nav', [/*actions_input, */actions_header, actions_div], {           'id': "p-cactions",            'role': "navigation",            'class': "vector-menu vector-menu-dropdown"        }); }

//    /** Search **/ var searchBox = createElement('input', "", {       'class': "vector-search-box-input",        'type': "search",        'name': "search",        'placeholder': "Search " + mw.config.get('wgSiteName'),        'aria-label': "Search " + mw.config.get('wgSiteName'),        'title': "Search " + mw.config.get('wgSiteName'),        'id': "searchInput",        'tabindex': "1",        'autocomplete': "off",    });

var searchBar = createElement('div', [       searchBox,        createElement('input', "", { 'name': "title", 'value': "Special:Search", 'type': "hidden" }),       createElement('input', "", { 'type': "submit", 'name': "go", 'value': "Go", 'title': "Go to a page with this exact name if it exists", 'id': "searchButton", 'class': "searchButton" })   ], {        'id': "simpleSearch",        'class': "vector-search-box-inner",        'data-search-loc': "header-navigation"    });

var searchForm = createElement('form', [searchBar], {       'id': "searchform",        'class': "vector-search-box-form",        'action': "/index.php"    });

/* Enable autocomplete */ mw.loader.using('mediawiki.searchSuggest');

var searchDiv = createElement('div', [searchForm], {       'id': "p-search",        'role': "search",        'class': "vector-search-box"    }); //

var rightNav_div = createElement('div', [pages_nav, actions_nav, searchDiv], {       'id': "right-navigation"    }); if (document.getElementsByClassName("page-header__actions")) document.getElementsByClassName("page-header__actions")[0].remove; head_div.appendChild(rightNav_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;            time = time.substring(0, time.length - 1);

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