Dalībnieks:Edgars2007/rlrl.js

Vikipēdijas lapa

Piezīme: Lai redzētu izmaiņas, pēc publicēšanas var nākties iztīrīt sava pārlūka kešatmiņu.

  • Firefox / Safari: Pieturi Shift un klikšķini uz Pārlādēt vai nospied Ctrl-F5 vai Ctrl-R (⌘-R uz Mac)
  • Google Chrome: Nospied Ctrl-Shift-R (⌘-Shift-R uz Mac)
  • Internet Explorer / Edge: Pieturi Ctrl un klikšķini uz Pārlādēt vai nospied Ctrl-F5
  • Opera: Nospied Ctrl-F5.
// Create some search-and-replace tools - this uses a slightly modified version
// of [[User:Gerbrant/edit/regexReplace.js]])

mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=User:Topbanana/regexReplace.js&action=raw&ctype=text/javascript');

function RLRL_SR_Utility()
{
   // Check if we are editing
   if ( document.getElementById("editform") )
   {
      // Check for and extract parameters
      parSearch  = mw.util.getParamValue( 'RLRLS' );
      parReplace  = mw.util.getParamValue( 'RLRLR' );
      parRedirect = mw.util.getParamValue( 'RLRLRD' );

      // First check if we are being asked to create a redirect
     if( parRedirect )
     {
        // Check we have no other parameters
        if( parSearch || parReplace )
          return;
 
        // Check the edit box is empty
        if( document.forms.editform.wpTextbox1.value.length > 0 )
          return;
 
        // Correct the parameters provided
        parRedirect = unescape( decodeURIComponent( parRedirect.replace( /_/g, " " ) ) );

        // Okay, populate the edit box and summary
        document.forms.editform.wpTextbox1.value = '#REDIRECT [[' + parRedirect+ ']]';
        document.forms.editform.wpSummary.value =
            'Saites labojums: lapa pāradresēta uz ' + parRedirect;
        document.forms.editform.wpWatchthis.checked = true;
 
        return;
     }
 
     // Okay, not a redirect.  Check if we are being asked to search-and-replace
 
     // If we've not got a useful set of parameters, give up   
     if( !parSearch || !parReplace )
       return;
 
     // Correct the parameters provided
     parSearch = unescape( decodeURIComponent( parSearch.replace( /_/g, " " ) ) );
     parReplace = unescape( decodeURIComponent( parReplace.replace( /_/g, " " ) ) );
 
     // Check for Template namespace prefix
     if( parSearch.indexOf( "Template:" ) == 0 &&
         parReplace.indexOf( "Template:" ) == 0 )
     {
        parSearch = parSearch.slice( 9 );
        parReplace = parReplace.slice( 9 );
     }

     // Escape any characters with special meanings in regular expressions
     parRegex = parSearch.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");

     // Specifically ignore the case of the first letter
     parRegex = '[' + parRegex.substring(0, 1).toUpperCase() +
                parRegex.substring(0, 1).toLowerCase() + ']' +
                parRegex.substring(1);

     // Find and manipulate the search and replace controls
     createRegexControls();
 
     document.getElementById('tbRegex_SearchCaseSensitive').checked = true;
     document.getElementById('tbRegex_SearchTextBox').value = parRegex;
     document.getElementById('tbRegex_FindButton').click();
     document.getElementById('tbRegex_ReplaceTextBox').value = parReplace;
 
     // Populate the edit summary
     document.forms.editform.wpSummary.value =
        'Saites labojums: ' + parSearch + ' -> ' + parReplace;
     document.forms.editform.wpMinoredit.checked = true;
   }

   // Check if we are editing
   if ( document.getElementById("movepage") )
   {
      // Check for and extract parameters
      parNewNS    = mw.util.getParamValue( 'RLRLMNS' );
      parNewTitle = mw.util.getParamValue( 'RLRLMNT' );
 
     // If we've not got a useful set of parameters, give up   
     if( !parNewNS || !parNewTitle )
       return;
 
     // Correct the parameters provided
     parNewTitle = unescape( decodeURIComponent( parNewTitle.replace( /_/g, " " ) ) );
 
     document.getElementById('wpNewTitleNs').value = parNewNS;
     document.getElementById('wpNewTitleMain').value = parNewTitle;
   }
};
 
$( RLRL_SR_Utility );