(function($, mw){ 'use strict'; var wgPageName = mw.config.get('wgPageName'); var wgUserName = mw.config.get('wgUserName'); var wgNamespaceNumber = mw.config.get('wgNamespaceNumber'); var jsPage = false; // Never do anything in article space if (wgNamespaceNumber === 0){ return; } // Handle .js pages if ((wgPageName.lastIndexOf('.js') == wgPageName.length - 3) && (mw.config.get('wgAction') == 'view') && (wgNamespaceNumber > -1)) { // Exclude users' own common.js and skin.js pages var fixedUn = wgUserName.replace(/ /g,'_'); if ((wgPageName != 'User:' + fixedUn + '/common.js') && (wgPageName != 'User:' + fixedUn + '/monobook.js') && (wgPageName != 'User:' + fixedUn + '/minerva.js') && (wgPageName != 'User:' + fixedUn + '/vector.js') && (wgPageName != 'User:' + fixedUn + '/modern.js') && (wgPageName != 'User:' + fixedUn + '/cologneblue.js') && (wgPageName != 'User:' + fixedUn + '/timeless.js') && (wgPageName != 'User:Equazcion/ScriptInstaller.js')){ importStylesheet('User:Equazcion/ScriptInstaller.css'); // Set a flag so the rest of the script knows we're on a .js page jsPage = true; // Append the install link to the header, along with a "scriptInstallerLink" class for use by the rest of the script $('h1#firstHeading').append(''); } } // If script links are found on the page, start the music. Detection is based on span tags with "scriptInstallerLink" class, which are added by {{userscript}}. // Also run if we're on User:Equazcion/scriptInstaller, where we'll simply provide access to the installed script list and uninstall links if ((($('span.scriptInstallerLink').length > 0) && (mw.config.get('wgAction') != 'submit') && (mw.config.get('wgAction') != 'edit')) || (wgPageName == 'User:Equazcion/ScriptInstaller')){ if (jsPage !== true) { importStylesheet('User:Equazcion/ScriptInstaller.css'); // Stylesheet already fetched above on .js pages } if (wgPageName == 'User:Equazcion/ScriptInstaller') { var homePage = true; // Set a flag if we're running the limited User:Equazcion/ScriptInstaller functions } // Set URL prefix var pre = location.protocol + '//' + mw.config.get('wgPageContentLanguage') + '.' + mw.config.get('wgNoticeProject') + '.org' + '/search/?title='; // Set interface text var installerTitle = 'You currently have the following scripts installed Script Installer'; var installerMessage = 'Only scripts installed using Script Installer are shown here. To uninstall a script, click "Uninstall".'; var pipe = ' | '; var installerLink = 'Install'; var installed = 'Installed'; var unInstallerLink = 'Uninstall'; var noauto = 'Must be installed manually'; // Set up the regex pattern for later var regexObject = new RegExp( 'importScript\\(\'(.*)\'\\); \\/\\/Linkback: \\\\] Added by Script installer' , ); // Create array for installed script paths var installedScripts = ; // Append the box of installed scripts. Hide unless we're on a designated installation page $('div#contentSub').after(''); // Set parameters for common.js ajax request var request4 = { action:"query", titles: "User:" + mw.config.get("wgUserName") + "/common.js", prop: "revisions|info", intoken: "edit", rvprop: "content", indexpageids: 1, format: "xml" }; // Do common.js ajax request $.get(mw.config.get("wgScriptPath")+"/api.php", request4, function(response4){ // Grab common.js content and split by lines var lines = $(response4).find('rev').text().split('\n'); // Use the regex to iterate through the lines, looking for the ones that ScriptInstaller added $.each(lines, function(index, value){ var match = regexObject.exec(value); // Put the paths of the matches into the array of installed scripts if (match !== null){ installedScripts.push(match); } }); // If none were found, remove the installed script list box. Otherwise fade-in the box and set up the toggle link if (installedScripts.length < 1){ $('div.scriptInstaller').remove(); } else if ((wgPageName == 'Misplaced Pages:WikiProject_User_scripts/Scripts') || (wgPageName == 'Misplaced Pages:WikiProject_User_scripts') || (wgPageName == 'Misplaced Pages:User_scripts') || (jsPage === true) || (homePage === true)){ // Insert script list toggle link var toggleMessage = ((jsPage === true) || (homePage === true)) ? 'Show installed script list' : 'Hide installed script list'; $('.firstHeading').append(' ' + toggleMessage + ''); // The function to set the toggle link to function setScriptInstallerToggle(){ $('.scriptinstallerTog').click(function(){ if ($('.scriptinstallerTog').html() == "Show installed script list"){ $('.scriptInstaller').fadeIn(500); $('.scriptinstallerTog').html('Hide installed script list'); } else { $('.scriptInstaller').fadeOut(200); $('.scriptinstallerTog').html('Show installed script list'); } }); } // Set the toggle link function. Also fade the box in initially, if we're at the script listing page. if ((jsPage !== true) && (homePage !== true)){ setTimeout(function(){ $('.scriptInstaller').fadeIn(800, function(){ setScriptInstallerToggle(); }); }, 500); } else { setScriptInstallerToggle(); } } // Start building the code for display of the installed list. Iterate through each installed script in the array var installedList = '