User:ThunderDragon2/common.js

$.when($.ready, mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"])).then(function{	return new mw.Api.loadMessagesIfMissing(["global-navigation-search-placeholder-inactive", "global-navigation-search-placeholder-in-wiki", "recentchanges"]); }).then(function{	var config = mw.config.get([ 'wgScriptPath', 'wgSiteName', 'wgArticlePath', ]);

//prevent double loading if( $(document.body).hasClass("oasis-is-revived") ) { return; }

var oasisRevivedClass = $(document.body).addClass("oasis-is-revived");

//Search bar in global nav var search_container = $(" ", {		class: "global-navigation__search-container",		action: config.wgScriptPath + "/wiki/Special:Search",	});

$(".global-navigation__search").remove; $(".global-navigation__bottom").append(search_container);

var search_mainDiv = $(" ").addClass("global-navigation__search");

var search_toggle = $(" ").addClass("global-navigation__search-toggle");

var search_toggleIconSmall = $(' ');

var search_toggleIcon = $(' ');

var search_toggleText = $(" ", {		class: "global-navigation__search-toggle-text",		text: mw.msg("global-navigation-search-placeholder-inactive"),	});

var search_inputWrapper = $(" ").addClass("global-navigation__search-input-wrapper");

var search_boxDiv = $(" ") .addClass("wds-dropdown") .addClass("global-navigation__suggestions-anchor") .addClass("wds-no-chevron");

var search_box = $(" ", {		type: "search",		class: "global-navigation__search-input",		name: "query",		autocomplete: "off",		"data-suggestions-param-name": "query",		"data-suggestions-tracking-label": "search-suggestion",		placeholder: mw.msg("global-navigation-search-placeholder-in-wiki").replace("$1", config.wgSiteName ),	});

var search_boxHidden = $(" ", {		type: "hidden",		name: "navigationSearch",		value: "true",	});

var search_boxCloseButton = $(" ", {		class: "wds-button wds-is-text global-navigation__search-close",		type: "button"	});

var search_boxCloseButtonIcon = $(' ');

var search_Suggest = $(' ');

$(search_container).append(search_mainDiv); $(search_mainDiv).append(search_toggle, search_inputWrapper); $(search_toggle).append(search_toggleIconSmall, search_toggleIcon, search_toggleText);

$(search_inputWrapper).append(search_boxDiv); $(search_boxDiv).append(search_box, search_boxHidden, /*search_boxCloseButton,*/ search_Suggest);

//$(search_boxCloseButton).append(search_boxCloseButtonIcon);

var windowWidth = $(window).width, searchClicked = 0;

$('.global-navigation__search-toggle').click(function {		searchClicked++;

if ( windowWidth < 1500 ) { if (searchClicked%2===0) { $('.global-navigation__search-input-wrapper').css('display', 'none'); $('.global-navigation .global-navigation__links').css('display', 'inline-flex'); console.log("clicked search 2"); } else { $('.global-navigation__search-input-wrapper').css('display', 'flex'); $('.global-navigation .global-navigation__links').css('display', 'none'); console.log("clicked search 1"); }		}	});

//for when screen width is changed to > 1500 from < 1500 if ( windowWidth >= 1500 ) { $('.global-navigation__search-input-wrapper').css('display', 'flex'); }

//getting community header color var commHeaderColor = getComputedStyle(document.documentElement).getPropertyValue('--theme-header-background-color');

//convert hex code to RGB function hexToRGB(hex, alpha) { var r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16);

if (alpha) { return (r + ", " + g + ", " + b + ", " + alpha); } else { return (r + ", " + g + ", " + b); }	}

//community header background color in RGB document.documentElement.style.setProperty("--theme-header-background-color--rgb", hexToRGB(commHeaderColor) );

var CommImgGradient = 'linear-gradient(to right, rgba(var(--theme-header-background-color--rgb),.5), rgba(var(--theme-header-background-color--rgb),.5)), linear-gradient(to left, transparent var(--theme-header-gradient-start),var(--theme-header-background-color) var(--theme-header-gradient-end))';

//appending community header image $('.fandom-community-header').css('background-image', CommImgGradient + ', url(' + config.wgScriptPath + '/wiki/Special:FilePath/Community-header-background?width=471&height=115)' );

//requesting header image url var CommImgURLRequest = new Request(config.wgScriptPath + '/wiki/Special:FilePath/Community-header-background?width=471&height=115');

//getting redirected url function CommImgURLRedirect { fetch(CommImgURLRequest).then( function (response) {			return JSON.stringify(response.url);		}); }

//zoom-crop image var CommImgURL = String(CommImgURLRedirect ).replace("scale-to-width-down", "zoom-crop");

//checking if File:Community-header-background exists function checkExist { $.ajax({			url: config.wgScriptPath + '/wiki/Special:FilePath/Community-header-background?width=471&height=115',			type:'HEAD',			error: function {				console.log("error. url doesnt exist");			},			success: function {				console.log("url exists");			}		}); }

//Popular pages module var popularPages_section = $(' ') .addClass("popular-pages premium-recirculation-rail") .attr("id", "recirculation-rail");

var popularPages_title = $(' ') .addClass("rail-module__header") .text("Popular Pages");

var popularPages_list = $('') .addClass("rail-module__list thumbnails");

$(popularPages_section).appendTo(".sticky-modules-wrapper"); $(popularPages_section).append(popularPages_title, popularPages_list);

//Recent changes in Explore tab var exploreTab_recentchanges = $('').html(		$('', { href: config.wgArticlePath.replace("$1", "Special:RecentChanges"), text: mw.message("recentchanges"), "data-tracking": "explore-recent-changes", })	);

$('.fandom-community-header__local-navigation .wds-list').prepend(exploreTab_recentchanges);

console.log( CommImgURLRedirect + " this is the message of CommImgURLRedirect"); console.log( CommImgURLRequest + " this is the message of CommImgURLRequest"); console.log( CommImgURL + " this is the message of CommImgURL");

});