User:JAAqqO/EnhancedSearchPage.js

/* jshint maxerr:10000 */ // per T1092 /*

Installation: See the documentation page at User:JAAqqO/EnhancedSearchPage or	https://en.wikipedia.org/wiki/User:JAAqqO/EnhancedSearchPage

What this does: This script adds the following features to the search page Special:Search: 1. Adds "Show 5000 results" into the two "Show x results" menus 2. Adds a shortened results list and four copy buttons to quickly copy the results to the clipboard (either plain text, wikitext or PetScan links) 3. Adds buttons to quickly scroll up and down 4. Adds "x results shown on the page" next to the results info 5. Adds (or brings back?) the red color and slightly bigger font for the "No results found for/Did you mean" notification

Updated: 15 March 2024

//-- BEGINS: this makes a copy of the search page's "Show x results" to top (disabled on 12 June 2023 because this is now a default feature of MediaWiki) //$(".mw-search-pager-bottom").clone.prependTo(".mw-search-results").css("padding", "5px 0px 10px 0px"); //-- ENDS: this makes a copy of the search page's "Show x results" to top (disabled on 12 June 2023 because this is now a default feature of MediaWiki) // // // // //-- BEGINS: this adds an option for 5000 into the two "Show x results" menus var JAAqqOfirst = $(' | ').insertAfter('.mw-numlink:eq(4)');

$('', {	text: '5000',	title: 'Show 5000 results per page',	href: "" + window.location.href + "&limit=5000", }).insertAfter('.mw-numlink:eq(4)').before(JAAqqOfirst);

var JAAqqOsecond = $(' | ').insertAfter('.mw-numlink:eq(9)');

$('', {	text: '5000',	title: 'Show 5000 results per page',	href: "" + window.location.href + "&limit=5000", }).insertAfter('.mw-numlink:eq(9)').before(JAAqqOsecond); //-- ENDS: this adds an option for 5000 into the two "Show x results" menus // // // // //-- BEGINS: this adds a shortened results list and four copy buttons var JAAqqOhide = $(" ").css({	"width": "30%",	"border": "1px solid grey",	"margin": "5px",	"padding": "5px",	"background-color": "lightyellow",	"borderRadius": "4px", }).hover(function {	$(this).css("background-color", "#ffffef"); }, function {	$(this).css("background-color", "lightyellow"); });

var JAAqqOexistelmnt = document.getElementById("mw-interwiki-results"); if (typeof(JAAqqOexistelmnt) != 'undefined' && JAAqqOexistelmnt != null) { $(JAAqqOhide).css({	"float": "right",	"clear": "right", }).insertBefore("#mw-interwiki-results"); } else { $(JAAqqOhide).css({   "position": "absolute",    "top": "20em",    "right": "0", }).insertBefore(".searchresults"); }

var JAAqqOhowmany = $( ".mw-search-result-data" ).length;

var JAAqqOhowmany2 = $( ".results-info" ).attr("data-mw-num-results-total").replace(/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g, "$&,");

var JAAqqOtitle = $(" Show a shortened list of this page's " + JAAqqOhowmany + " results (of total of " + JAAqqOhowmany2 + ") ").css({	"text-align": "center",	"font-weight": "bold",	"cursor": "pointer" }).appendTo(JAAqqOhide);

var JAAqqOplace = $(" ").css({	"width": "250x",	"height": "200px" }).appendTo(JAAqqOhide).hide;

var JAAqqOclone = $(".mw-search-result-heading").clone.appendTo(JAAqqOplace);

var JAAqqOcss = { "text-align": "center", "font-weight": "bold", "width": "15%", "border": "1px solid grey", "margin": "5px", "padding": "5px", "background-color": "lightyellow", "borderRadius": "4px", "cursor": "pointer" };

var JAAqqOnote1 = $(" Copy this page\'s " + JAAqqOhowmany + " results to the clipboard as... ").css({	"text-align": "center",	"font-weight": "bold",	"width": "30%",	"padding": "5px" }).insertAfter(JAAqqOhide).hide;

var JAAqqOnote2 = $(" ...plain text(?) ").css(JAAqqOcss).insertAfter(JAAqqOnote1).hide.hover(function {   $(this).css("background-color", "#ffffef");    $(this).attr('title', 'This button copies this page\'s ' + JAAqqOhowmany + ' results to the clipboard as plain text, i.e. without wikitext markup. Since this copies only the results shown on this search page, make sure you have clicked the "view 20, 50, 100, 250, 500, 5000" link. This format is compatible with PetScan and AutoWikiBrowser (AWB) for example.'); // AutoWikiBrowser }, function {   $(this).css("background-color", "lightyellow"); });

var JAAqqOnote3 = $(" ...wikitext(?) ").css(JAAqqOcss).insertAfter(JAAqqOnote2).hide.hover(function {   $(this).css("background-color", "#ffffef");    $(this).attr('title', 'This button copies this page\'s ' + JAAqqOhowmany + ' results to the clipboard and also adds wikitext markup, like this:\n* Article\n* Article 2\nSince this copies only the results shown on this search page, make sure you have clicked the "view 20, 50, 100, 250, 500, 5000" link.'); }, function {    $(this).css("background-color", "lightyellow"); });

var JAAqqOnote4 = $(" ...PetScan URL(?) ").css(JAAqqOcss).insertAfter(JAAqqOnote3).hide.hover(function {	$(this).css("background-color", "#ffffef");	$(this).attr('title', 'This button copies a PetScan URL with this page\'s ' + JAAqqOhowmany + ' results to the clipboard. Note that if the PetScan URL becomes too long (~250+ pages), the URL might not work. For a link with this search query\'s all ' + JAAqqOhowmany2 + ' results, click the button below instead.'); }, function {	$(this).css("background-color", "lightyellow"); }); // PetScan

var JAAqqOnote5 = $(" ...or this search query's total results of " + JAAqqOhowmany2 + "(?) as... ").css({	"text-align": "center",	"font-weight": "bold",	"width": "30%",	"padding": "5px" }).insertAfter(JAAqqOnote4).hide.hover(function {	$(this).attr('title', 'Note that the actual limit is 10,000, which is MediaWiki\'s maximum limit.'); });

var JAAqqOnote6 = $(" ...PetScan URL(?) ").css(JAAqqOcss).insertAfter(JAAqqOnote5).hide.hover(function {	$(this).css("background-color", "#ffffef");	$(this).attr('title', 'This button copies a PetScan URL with all ' + JAAqqOhowmany2 + ' results to the clipboard. Note that the maximum limit is 10,000 due to MediaWiki\'s restriction. Also, because this PetScan URL\'s default is the article namespace, you will have to change the namespace in PetScan\'s "Page properties" tab for pages in other namespaces.'); }, function {	$(this).css("background-color", "lightyellow"); });

var JAAqqOnote7 = $(" (?) = hover over for tooltip details ").css({	"text-align": "right",	"font-weight": "bold",	"width": "30%",	"padding": "5px" }).insertAfter(JAAqqOnote6).hide;

const JAAqqOfloat = { "float": "right", "clear": "right" };

const JAAqqOabsolute = (JAAqqOpercentage) => ({   "position": "absolute",    "top": JAAqqOpercentage,    "right": "0" });

if (typeof(JAAqqOexistelmnt) !== 'undefined' && JAAqqOexistelmnt !== null) { $(JAAqqOnote1).css(JAAqqOfloat); $(JAAqqOnote2).css(JAAqqOfloat); $(JAAqqOnote3).css(JAAqqOfloat); $(JAAqqOnote4).css(JAAqqOfloat); $(JAAqqOnote5).css(JAAqqOfloat); $(JAAqqOnote6).css(JAAqqOfloat); $(JAAqqOnote7).css(JAAqqOfloat); } else { $(JAAqqOnote1).css(JAAqqOabsolute("30em")); $(JAAqqOnote2).css(JAAqqOabsolute("33em")); $(JAAqqOnote3).css(JAAqqOabsolute("36em")); $(JAAqqOnote4).css(JAAqqOabsolute("39em")); $(JAAqqOnote5).css(JAAqqOabsolute("42em")); $(JAAqqOnote6).css(JAAqqOabsolute("45em")); $(JAAqqOnote7).css(JAAqqOabsolute("48em")); }

function JAAqqOcopy(element) { var $temp = $(" "); $("body").append($temp); var html = $(element).html; const reg1 = /" data-serp-pos="\d+">.*?<\/a>   <\/div>/g;	html = html.replace(reg1, "\r\n");	const reg2 = /" data-serp-pos="\d+"> .*<\/span>.*?<\/a>    <\/div>/g; html = html.replace(reg2, "\r\n"); const reg3 = / .*?<\/a>   <\/div>/g;	html = html.replace(reg1, "]]\r\n* [[");	const reg2 = /" data-serp-pos="\d+"> .*<\/span>.*?<\/a>    <\/div>/g; html = html.replace(reg2, "]]\r\n* [["); const reg3 = / <a href="\/wiki\/.*?" title="/g;	html = html.replace(reg3, "");	html = html.replace(/^/, "This is a list of [" + window.location.href + " these search results] \(made with the script EnhancedSearchPage):\r\n* [[User:JAAqqO/EnhancedSearchPage|EnhancedSearchPage | EnhancedSearchPage }}):\r\n* [[");	const reg4 = /\[\[(Category|File|Luokka|Tiedosto):/g;	html = html.replace(reg4, "[[:$1:");	html = html.replace(/....$/, "");	console.log(html);	$temp.val(html).select;	document.execCommand("copy");	$temp.remove; }

function JAAqqOcopy3(element) { var $temp = $(" "); $("body").append($temp); var html = $(element).html; const reg1 = /" data-serp-pos="\d+">.*?<\/a>   <\/div>/g;	html = html.replace(reg1, "%0A");	const reg2 = /" data-serp-pos="\d+"> .*<\/span>.*?<\/a>    <\/div>/g; html = html.replace(reg2, "%0A"); const reg3 = / <a href="\/wiki\/.*?" title="/g;	html = html.replace(reg3, "");	html = html.replace(/ /g, "%20");	html = html.replace(/&/g, "%26");	html = html.replace(/^/, "https://petscan.wmflabs.org/?active_tab=tab_other_sources&manual_list=");	html = html.replace(/%0A$/, "&manual_list_wiki=" + JAAqqOlanguage + "wiki&project=wikipedia&language=" + JAAqqOlanguage + "&doit=");	console.log(html);	$temp.val(html).select;	document.execCommand("copy");	$temp.remove; }

function JAAqqOcopy4 { var $temp = $(" "); $("body").append($temp); var value = document.getElementById("ooui-php-1").value; value = value.replace(/ /g, "%20"); value = value.replace(/^/, "https://petscan.wmflabs.org/?active_tab=tab_other_sources&ns%5B0%5D=1&search_query="); value = value.replace(/$/, "&search_wiki=" + JAAqqOlanguage + "wiki&search_max_results=10000&project=wikipedia&language=" + JAAqqOlanguage + "&doit="); console.log(value); $temp.val(value).select; document.execCommand("copy"); $temp.remove; }

var JAAqqOend = $(JAAqqOhide).click(function {	$(JAAqqOplace).slideDown;	$(".searchalttitle").remove;	$(JAAqqOhide).css({ "fontSize": "10px", "overflow": "auto", "resize": "vertical" });	$(JAAqqOtitle).remove;	$(JAAqqOnote1).show;	$(JAAqqOnote2).show;	$(JAAqqOnote3).show;	$(JAAqqOnote4).show;	$(JAAqqOnote5).show;	$(JAAqqOnote6).show;	$(JAAqqOnote7).show; });

function JAAqqOcopied(event) { var posX = event.pageX; var posY = event.pageY;

var $copiedMessage = $(" Copied! ").appendTo("body"); $copiedMessage.css({       position: "absolute",        top: posY + 10 + "px",        left: posX + 10 + "px",        backgroundColor: "#f0f0f0",        border: "1px solid grey",        padding: "5px 10px",        borderRadius: "5px",    });

setTimeout(function {       $copiedMessage.fadeOut("slow", function { $(this).remove; });   }, 500); // duration in milliseconds }

$(JAAqqOnote2).click(function(event) {   $(JAAqqOcopy(JAAqqOplace));    JAAqqOcopied(event);    $(this).css("transform", "scaleY(0.9)").animate({ opacity: '0.5', }, "fast", function { $(this).animate({           opacity: '1',        }, "slow").css("transform", "scaleY(1)"); }); });

$(JAAqqOnote3).click(function(event) {   $(JAAqqOcopy2(JAAqqOplace));    JAAqqOcopied(event);    $(this).css("transform", "scaleY(0.9)").animate({ opacity: '0.5', }, "fast", function { $(this).animate({           opacity: '1',        }, "slow").css("transform", "scaleY(1)"); }); });

$(JAAqqOnote4).click(function(event) {   $(JAAqqOcopy3(JAAqqOplace));    JAAqqOcopied(event);    $(this).css("transform", "scaleY(0.9)").animate({ opacity: '0.5', }, "fast", function { $(this).animate({           opacity: '1',        }, "slow").css("transform", "scaleY(1)"); }); });

$(JAAqqOnote6).click(function(event) {   $(JAAqqOcopy4);    JAAqqOcopied(event);    $(this).css("transform", "scaleY(0.9)").animate({ opacity: '0.5', }, "fast", function { $(this).animate({           opacity: '1',        }, "slow").css("transform", "scaleY(1)"); }); }); //-- ENDS: this adds a shortened results list and four copy buttons // // // // //-- BEGINS: this adds buttons to scroll up and down var JAAqqOpagedown = $("

[ ↓ ] ").css({	"fontSize": "20px",	"color": "#447ff5",	"position": "absolute",	"right": "40%",	"font-weight": "bold",	"cursor": "pointer" }).hover(function {	$(this).css("color", "#36c");	$(this).attr('title', 'Go to the bottom of the page'); }, function {	$(this).css("color", "#447ff5"); }).insertBefore('.mw-search-result:eq(0)');

var JAAqqOpageup = $(" [ ↑ ] ").css({	"fontSize": "20px",	"color": "#447ff5",	"position": "absolute",	"right": "40%",	"font-weight": "bold",	"cursor": "pointer" }).hover(function {	$(this).css("color", "#36c");	$(this).attr('title', 'Go to the top of the page'); }, function {	$(this).css("color", "#447ff5"); }).insertAfter('.mw-search-result:eq(-1)');

$(JAAqqOpagedown).click(function(event) {	event.preventDefault;	var JAAqqOheight = $(document).height;	$('html, body').animate({scrollTop:JAAqqOheight}, 500); });

$(JAAqqOpageup).click(function(event) {	$('html, body').animate({scrollTop:0}, 500); }); //-- ENDS: this adds buttons to scroll up and down // // // // //-- BEGINS: this adds "x shown on the page" next to the results info $("  (" + JAAqqOhowmany + " shown on the page) ").appendTo('.results-info'); //-- ENDS: this adds "x shown on the page" next to the results info // // // // //-- BEGINS: this adds/brings back the red color and slighlty bigger font for the "No results found for/Did you mean" text var JAAqqOdidyou = document.querySelector('.searchdidyoumean'); JAAqqOdidyou.style.color = '#b32424'; JAAqqOdidyou.style.fontSize = '20px'; //-- ENDS: this adds/brings back the red color and slighlty bigger font for the "No results found for/Did you mean" text