Jump to content

User:Topbanana/RLRL SR Utility.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Topbanana (talk | contribs) at 16:39, 28 May 2010. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
Gerbrant = {fw: {load: [
"Gerbrant.edit.regexReplace"
]}}

document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Gerbrant/fw.js&action=raw&ctype=text/javascript&dontcountme=s"><\u002fscript>');

function RLRL_SR_Utility()
{
   // If we're not editing, do nothing
   if ( !document.getElementById("editform") )
      return;

   // Check for and extract 'RLRLS' (search) and 'RLRLR' (replace) parameters
   // Method based on 'gup' (http://www.netlobo.com/url_query_string_javascript.html)
   param_match = new RegExp( '[\\?&]RLRLS=([^&#]*)' ).exec( window.location.href );
   parSearch = param_match ? param_match[1] : '';
   param_match = new RegExp( '[\\?&]RLRLR=([^&#]*)' ).exec( window.location.href );
   parReplace = param_match ? param_match[1] : '';

   // If we've not got a useful set of parameters, give up
   if( parSearch.length == 0 || parReplace.length == 0 )
      return;

   // Okay, do some work

   // Find and manipulate the controls produced by User:Gerbrant/edit/regexReplace.js f they are present
   editbox = document.editform.wpTextbox1;
   searchdiv = document.editform.childNodes[1];

   if( editbox == searchdiv )
   {
      // Cannot find the search box .. just post up advice on what needs done
      document.getElementById('editpage-copywarn').innerHTML +=
         '<B>' + parSerch + '</B>  should probably be <B>' + parReplace + '</B>';

   }
   else
   {
      // Found the controls - manipulate them
      searchdiv.childNodes[0].value = parSearch;
      searchdiv.childNodes[2].click();
      searchdiv.nextSibling.childNodes[0].value = parReplace;
   }

   // Post up a summary of what's been done
/*
   document.getElementById('editpage-copywarn').innerHTML +=
      '<B>v0.18: RLRL Search and Replace:<BR>' +
      'Searching for "' + parSearch + '", to replace with "' + parReplace + '"<BR>' +
      '</B>';
*/

   // Populate the edit summary
   document.forms.editform.wpSummary.value =
      'Link repair (' + parSearch + ' -> ' + parReplace + ') - [[Wikipedia:WikiProject Red Link Recovery|You can help!]]';
};
 
addOnloadHook( RLRL_SR_Utility );

*/