User:Mario Rk/global.js

// RemoveTracking require( ['wikia.window'], function( window ) {   'use strict';

// Prevent double-loading if ( window.RemoveTrackingLoaded ) return; window.RemoveTrackingLoaded = true;

// Copied from https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/ function getCookie ( name ) { var v = document.cookie.match( '(^|;) ?' + name + '=([^;]*)(|$)' ); return v ? v[2] : null; }

// Define meta-variables if undefined if ( !window.hasOwnProperty( 'dev' ) ) window.dev = {}; if ( !window.dev.hasOwnProperty( 'forceRemoveTracking' ) ) window.dev.forceRemoveTracking = true;

// Check if user rejected tracking if ( getCookie( 'tracking-opt-in-status' ) === 'rejected' || window.dev.forceRemoveTracking ) { // Catch tracking elements var trackers = document.querySelectorAll( '[data-tracking-label], [data-tracking]' );

// Prevent unusual exception when trackers doesn't exist if ( !trackers ) return;

// Perform to all tracking elements found trackers.forEach( function( tracker ) {           // Remove tracking attributes from elements            tracker.removeAttribute( 'data-tracking' );            tracker.removeAttribute( 'data-tracking-label' );        } ); } } );

//UCXSearchbar $.when(mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"])).then(function{   return new mw.Api.loadMessagesIfMissing(["search-modal-see-all-results", "tooltip-search", "tooltip-search-go"]); }).then(function{	if (mw.config.get("skin") !== "fandomdesktop"){		return;	}	var ScriptPath = mw.config.get("wgScriptPath");	var search_icon = $('  ');

var search_form = $(" ") .addClass("wiki-tools__search-container") .addClass("wds-dropdown") .attr("action", ScriptPath + "/wiki/Special:Search");

var search_box = $(" ") .addClass("wiki-tools__search-input") .attr("type", "search") .attr("name", "search") .attr("placeholder", mw.msg("tooltip-search")) .attr("title", mw.msg("tooltip-search")) .attr("autocomplete", "off");

var search_hidden = $(" ") .attr("type", "hidden") .attr("name", "title") .attr("value", "Special:Search");

var search_button = $(" ") .addClass("wiki-tools__search-button") .addClass("wds-button") .addClass("wds-is-secondary") .attr("type", "submit") .attr("name", "go") .attr("value", "Go") .attr("title", mw.msg("tooltip-search-go")) .append(search_icon);

var search_linksuggest_box = $("") .addClass("wds-list") .addClass("wds-is-linked");

var search_linksuggest_box_div = $(" ") .addClass("wiki-tools__search-linksuggest-list") .addClass("wds-dropdown__content") .addClass("wds-is-not-scrollable") .attr("style", "display: none !important;") .append(search_linksuggest_box);

search_form.append(search_box, search_hidden, search_button, search_linksuggest_box_div);

$(".wiki-tools__search").replaceWith(search_form);

function update_linksuggest(container_selector){ var search_query = $(container_selector + " .wiki-tools__search-input").val.trim; if(!search_query){ $(container_selector + " .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;"); return; }		new mw.Api.get({			action: "linksuggest",			get: "suggestions",			query: search_query,			format: "json"		}).then(function(data){			$(container_selector + " .wiki-tools__search-linksuggest-list > ul").empty;			data.linksuggest.result.suggestions.forEach(function(suggestion){ $(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("")					.attr("title", suggestion)					.append($('' + suggestion.replace(new RegExp("(" + search_query + ")", "gi"), "$1") + ""))				); });			$(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("") .append($('' + mw.msg("search-modal-see-all-results", search_query) + "")) );			$(container_selector + " .wiki-tools__search-linksuggest-list").attr("style", "display: block !important;");		}); }

$(".fandom-community-header__top-container .wiki-tools__search-input").on("input paste", function{		update_linksuggest(".fandom-community-header__top-container");	});

$(".fandom-sticky-header .wiki-tools__search-input").on("input paste", function{		update_linksuggest(".fandom-sticky-header");	});

$(window).on("click", function(event){		if($(".fandom-community-header__top-container .wiki-tools__search-linksuggest-list").attr("style") == "display: block !important;"){			if(!$(".fandom-community-header__top-container .wiki-tools__search-container").get(0).contains(event.target)){				$(".fandom-community-header__top-container .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;");			}		}		if($(".fandom-sticky-header .wiki-tools__search-linksuggest-list").attr("style") == "display: block !important;"){			if(!$(".fandom-sticky-header .wiki-tools__search-container").get(0).contains(event.target)){				$(".fandom-sticky-header .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;");			}		}	}); });