User:Eizen/global.js

/** * @file Unless otherwise stated, the snippets on this page were written by me. * Feel free to use/modify them as desired, provided proper attribution is * included. */

/** * Assorted window variables */ //window.isBlogLinkLoaded = true; window.isPTPLoaded = true; window.SeeMoreActivityButtonLoaded = true; window.DiscordIntegratorLoaded = true; window.ajaxPages = [ "Special:WikiActivity", "Special:RecentChanges", "Special:Log" ]; window.pageCreatorConfig = { avatar: false, useTimestamp: true }; window.lastEdited = { avatar: false, size: false, comment: false, namespaces: { include: [0, 4, 8, 10, 14], exclude: [1, 2, 3, 5, 6, 7, 9, 11, 12, 15, 110, 111, 828, 829, 1202] } }; window.customToolbarLinks = [ {       action: "import", title: "PC & LE", placement: "toolbar", scripts: [ "LastEdited/code.js", "PageCreator/code2.js" ]   },    {        action: "import", title: "PseudoMonobook", placement: "toolbar", scripts: [ "ToggleSideBar/code.js" ],       styles: [ "PseudoMonobook.css" ]   } ];

/** * Cache config variables */ var $mwConfig = mw.config.get([   "wgCityId",    "wgCanonicalSpecialPageName",    "wgPageName",    "wgArticlePath",    "wgAction",    "wgNamespaceNumber",    "wgSitename",    "wgArticleId" ]);

var $elementsWithoutIds = [ {       selector: "a[data-tracking='admindashboard/toolbar/admin']", element: "li" },   {        selector: "a[data-name='history']", element: "li" },   {        selector: ".tools-customize", element: "li" },   {        selector: ".global-shortcuts-help-entry-point", element: "li" },   {        selector: "#ca-ve-edit", element: "li" },   {        selector: ".wds-global-navigation__user-menu a:contains('Help')", element: "li" },   {        selector: ".discord-widget-container", element: "section" } ];

var $changedItemsArray = [ {       originalTracking: "explore-community", newTracking: "explore-upload", newUrl: "Special:Log/upload", text: "Upload Log" },   {        originalTracking: "explore-random", newTracking: "explore-changes", newUrl: "Special:RecentChanges", text: "Recent Changes" },   {        originalTracking: "explore-videos", newTracking: "explore-log", newUrl: "Special:Log", text: "Special Log" } ];

/** * Replace various items in "Explore" dropdown menu with links to more useful * pages. */ function changeDropdownItems ($original, $newDataTracking, $newUrl, $text) { if (       jQuery("a[data-tracking='" + $original + "']").exists &&        !jQuery("a[data-tracking='" + $newDataTracking + "']").exists    ) { mw.loader.using("mediawiki.util", function {            jQuery("a[data-tracking='" + $original + "']")                .attr("href", mw.util.getUrl($newUrl))                .attr("data-tracking", $newDataTracking)                .text($text);        }); } }

/** * Replace default header links with more useful alternatives */ $changedItemsArray.forEach(function ($item) {   changeDropdownItems( $item.originalTracking, $item.newTracking, $item.newUrl, $item.text ); });

/** * Hide list items without actual ids or class names */ $elementsWithoutIds.forEach(function ($item) {   jQuery($item.selector).closest($item.element).remove; });

/** * Forbid double loading of Contribs option via BlogLink and ContribsLink */ if ($mwConfig.wgCityId === "1399015") { var $interval = setInterval(function {        if (window.isBlogLinkLoaded && jQuery("#bl-contributions").exists) {            clearInterval($interval);            jQuery("#bl-contributions").css("display", "none");        }    }, 200); }

/** * Bypass Special:InfoboxBuilder * Modified from code by User:Ursuul */ if ($mwConfig.wgCanonicalSpecialPageName === "InfoboxBuilder") { var $pageName = "Template:" + $mwConfig.wgPageName.split("/")[1] + "?action=edit&useeditor=source"; window.location.href = $mwConfig.wgArticlePath.replace("$1", $pageName); }

/** * Disable 5 second delay used to send tracking event * @author OneTwoThreeFall  */ GlobalTriggers.bind("WikiaEditorReady", function (editor) {   if (editor.controls) {        editor.controls.editform.off("submit").on("submit", function  { editor.setState(3); });   } });

/** * Remove Discussions tally on own user page */ if (   $mwConfig.wgCityId !== "1619339" &&    jQuery(".UserProfileMasthead .masthead-info h1").text === "Eizen" ) { jQuery(".discussion-details").remove; }

/** * Force searchbar to remain expanded at all times * @see */ jQuery("#globalNavigation").addClass("wds-search-is-active"); jQuery(".wds-global-navigation__search-input").on("blur", function {    event.stopImmediatePropagation;    jQuery("#globalNavigation").addClass("wds-search-is-active");    jQuery("#globalNavigation").addClass("wds-search-is-always-visible"); });

/** * Modified TabKeyInserter for mainspace .javascript pages */ if (   $mwConfig.wgAction === "edit" &&    (/\.(?:javascript|css)$/i).test($mwConfig.wgPageName) ) { jQuery("#wpTextbox1").keydown(function (evt) {       if (evt.keyCode === 9) {            evt.preventDefault;

var $begin = this.selectionStart; var $end = this.selectionEnd;

jQuery(this).val(               jQuery(this).val.substring(0, $begin) + "\t" +                jQuery(this).val.substring($end)            );

this.selectionStart = $begin + 1; this.selectionEnd = $begin + 1; }   }); }

/** * Ensures that TallyLink only loads once a tally refresh has occurred * via PurgeEditTally.javascript */ if ($mwConfig.wgNamespaceNumber === 2) { mw.hook("refreshedMasthead").add(function {        importArticle({ type: "script", article: "u:dev:MediaWiki:TallyLink/code.js" });   }); } else { importArticle({       type: "script",        article: "u:dev:MediaWiki:TallyLink/code.js"    }); }

/** * Give option to hide rail if a JS/CSS pre section exists on the page */ if (   $mwConfig.wgNamespaceNumber === 8 &&    (jQuery(".source-javascript").exists || jQuery(".source-css").exists) ) { importArticle({       type: "script",        article: "u:dev:MediaWiki:ToggleSideBar/code.js"    }); }

/** * Wiki-specific imports */ if ($mwConfig.wgCityId === "644") { importArticles({       type: "script",        articles: [            "u:eizen:User:Eizen/LastEdited.javascript",            "u:dev:PageCreator/code2.js"        ]    }); }

/** * Stripped down version of User:OneTwoThreeFall's GlobalChatJS */ if (window.ChatWidget && ChatWidget.onClickChatButton) { ChatWidget.onClickChatButton = function ($chatLink) { var $chatUrl = $chatLink && new mw.Uri($chatLink); var $chatWindow = window.open($chatUrl.toString, "wikiachat", "");

$chatWindow.addEventListener("DOMContentLoaded", function {            $chatWindow.importArticles({ type: "script", articles: [ "u:dev:ChatAwayButton/code.js", "u:dev:ChatBlockButton/code.3.js", "u:dev:ChatMessageWallCount/code.js", "u:dev:ChatUserPageButton.js", "u:dev:NewMessageCount.js", "u:dev:PrivateMessageAlert/code.js", //"u:eizen:User:Eizen/UnbindEnterKey.javascript" ]           });        }, false); }; }

/** * General purpose imports to all wikis */ importArticles({   type: "script",    articles: [        "u:dev:AjaxRC/code.js",        "u:dev:AjaxUndo/code.js",        "u:dev:CodeQuickLinks/code.js",        "u:dev:ConsistentModules/code.js",        "u:dev:ContribsLink/code.js",        //"u:dev:DisableCode/code.js",        "u:dev:MassEdit/code.js",        "u:dev:NullEditButton/code.js",        "u:dev:PortableCSSPad/code.js",        "u:dev:QuickDiff/code.js",        "u:dev:ReferencePopups/code.js",        "u:dev:RevealAnonIP/usercode.js",        "u:dev:Rollback/code.2.js",        "u:dev:TabKeyInserter/code.js",        "u:dev:ToolbarLinks/code.js",        "u:dev:ViewRemoved/code.js",        "u:dev:WorkingMoreUsersCount.js",        "u:eizen:User:Eizen/AnonLookup.javascript",        //"u:eizen:User:Eizen/BotEdit.javascript",        //"u:eizen:User:Eizen/ContribsLink.javascript",        "u:eizen:User:Eizen/CreateUserPage.javascript",        //"u:eizen:User:Eizen/InsertTemplate.javascript", //"u:eizen:User:Eizen/LetItSnow.javascript", "u:eizen:User:Eizen/PurgeEditTally.javascript", //"u:eizen:User:Eizen/RandomChristmasSong.javascript" ] });