Jump to content

User:Giorgi Eufshi/wildcard entry.js

From Wiktionary, the free dictionary

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.


var wildcard_entries = [
	{
		name: "season-episode contraction",
		regex: /S(\d)(\d)E(\d)(\d)/,
		success: function(match_result)
		{
			if(match_result && match_result[1] && match_result[2] && match_result[3] && match_result[4])
			{
				var sN = parseInt(match_result[1])*10 + parseInt(match_result[2]);
				var eN = parseInt(match_result[3])*10 + parseInt(match_result[4]);
				return "<i>Abbreviation of " + createHtmlLink("season") + " " + sN + ", " + createHtmlLink("season") + " " + eN + "</i>";
			}
		}
	}
];

function createHtmlLink(entry)
{
	return "<a href='" + entry + "'>" + entry + "</a>";
}

function getWildcards(title)
{
	var res = "";
	wildcard_entries.forEach(function(item, index){
		res += wildcard_entries[index].success(title.match(wildcard_entries[index].regex));
		res + "<br/>";
	});
	return res;
}

$(function(){
	var title = $(".mw-search-createlink .new").text();
	var meanings = getWildcards(title);
	$(".mw-search-createlink").after("<div style = 'border: 1px solid rgb(0, 222, 0);'><p style='color: rgb(0, 222, 0); font-weight: bold;'>There is no entry for it, but you may be looking for: </p>" + meanings + "</div>");
});