User:Shine/valve.js

From Team Fortress Wiki
< User:Shine
Revision as of 01:46, 8 August 2010 by Shine (talk | contribs)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// addPurge
addOnloadHook(function () {
    var hist; var url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                   'Purge', 'ca-purge', 'Purge server cache for this page', '0');
});

//

// Adds a "Replace" tab which pops up two prompt boxes; one for a regexp and one for a replacement
function wpTextboxReplace()
{
    var s = prompt("Search regexp:");
    if(s){
        var r = prompt("Replace /"+s+"/ with:");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "mg"), r);
    }
}
addOnloadHook(function () {
    if (document.forms.editform) {
        addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
                       'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
    }
});
 
//

/*
	NAMESPACE REDIRECT
	Description: Redirects pages that begin with certain prefixes to appropriate namespaces.
	Example: [[C:Test]] -> [[Category:Test]], [[F:Test]] -> [[File:Test]], [[T:Test]] -> [[Template:Test]]
	Link: [[User:Gary King/namespace redirect.js]]
*/
 
addOnloadHook(function() 
{
	if (wgPageName != 'Special:Search') return;
 
	var searchText = document.getElementById('searchText');
	if (!searchText) return;
	var searchTerm = searchText.value;
	var colon = searchTerm.indexOf(':');
 
	if (colon != -1)
	{
		var firstPart = searchTerm.substring(0, colon);
		var secondPart = searchTerm.substring(colon + 1);
		var pageName = '';
 
		switch (firstPart.toUpperCase())
		{
			case 'C':
				pageName = 'Category:' + secondPart;
				break;
			case 'F':
				pageName = 'File:' + secondPart;
				break;
			case 'T':
				pageName = 'Template:' + secondPart;
				break;
			case 'U':
				pageName = 'User:' + secondPart;
				break;
		}
 
		if (pageName != '')
			window.location = wgServer + '/wiki/' + pageName;
	}
});