Benutzer:Der Buckesfelder/SkriptInstaller.js

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 15. Oktober 2013 um 21:21 Uhr durch Equazcion (Diskussion | Beiträge). Sie kann sich erheblich von der aktuellen Version unterscheiden.
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
 if(wgNamespaceNumber!=0){
 if((wgPageName.lastIndexOf('.js')==wgPageName.length-3)&&(wgAction!='submit')&&(wgAction!='edit')&&(wgNamespaceNumber>-1)){
 varfixedUn=wgUserName.replace(/ /g,'_');
 if((wgPageName!='User:'+fixedUn+'/common.js')&&
 (wgPageName!='User:'+fixedUn+'/monobook.js')&&
 (wgPageName!='User:'+fixedUn+'/vector.js')&&
 (wgPageName!='User:'+fixedUn+'/modern.js')&&
 (wgPageName!='User:'+fixedUn+'/cologneblue.js')&&
 (wgPageName!='User:Equazcion/ScriptInstaller.js')){
 importStylesheet('User:Equazcion/ScriptInstaller.css');
 varjsPage=true;
 $('h1#firstHeading').append(' | <span style="font-size:0.8em;font-weight:bold;" id="'+wgPageName+'" class="scriptInstallerLink jsPage"></span>');
 }
 }

 if((($('span.scriptInstallerLink').length>0)&&(wgAction!='submit')&&(wgAction!='edit'))||(wgPageName=='User:Equazcion/ScriptInstaller')){

 if(jsPage!=true)importStylesheet('User:Equazcion/ScriptInstaller.css');
 if(wgPageName=='User:Equazcion/ScriptInstaller')varhomePage=true;

 // Set URL prefix
 varpre=location.protocol+'//'+wgPageContentLanguage+'.'+wgNoticeProject+'.org'+'/w/index.php?title=';

 // Set interface text
 varinstallerTitle='You currently have the following scripts installed <div class="titleBadge"><a href="'+pre+'User:Equazcion/ScriptInstaller'+'">Script Installer</a></div>';
 varinstallerMessage='Only scripts installed using <span style="font-weight:bold">Script Installer</span> are shown here. To uninstall a script, click "Uninstall".';
 varinstallerLink='Install';
 varunInstallerLink='Uninstall';
 varnoauto='Must be installed manually';

 // Set up the regex pattern for later
 varregex1='(importScript)';
 varregex2='(\\(.*\\))';
 varregex3='; \\/\\/Linkback: \\[.*?\\]\\] Added by Script installer';
 varregexObject=newRegExp(regex1+regex2+regex3,["i"]);

 // Create array for installed script paths
 varinstalledScripts=[];

 // Append the box of installed scripts. Hide unless we're on a designated installation page
 $('div#contentSub').after('<div hidden="hidden" class="scriptInstaller"></div>');

 // Set parameters for common.js ajax request	
 varrequest4={
 action:"query",
 titles:"User:"+mw.config.get("wgUserName")+"/common.js",
 prop:"revisions|info",
 intoken:"edit",
 rvprop:"content",
 indexpageids:1,
 dataType:"xml",
 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 
 varcontent=$(response4).find('rev').text();
 varlines=content.split('\n');

 // Use the regex to iterate through the lines, looking for the ones that ScriptInstaller added
 $.each(lines,function(index,value){
 varmatch=regexObject.exec(value);

 // Put the paths of the matches into the array of installed scripts
 if(match!=null){
 installedScripts.push(match[2].replace(/\'/g,'').replace(/\(/g,'').replace(/\)/g,''));
 }
 });

 // 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();
 }elseif((wgPageName=='Wikipedia:WikiProject_User_scripts/Scripts')||(wgPageName=='Wikipedia:WikiProject_User_scripts')||
 (wgPageName=='Wikipedia:User_scripts')||(jsPage==true)||(homePage==true)){

 // Insert script list toggle link
 vartoggleMessage=((jsPage==true)||(homePage==true))?'Show installed script list':'Hide installed script list';
 $('.firstHeading span:last').after(' <a style="font-weight:bold;font-size:10px" class="scriptinstallerTog" href="#bbx">'+toggleMessage+'</a>');

 functionsetScriptInstallerToggle(){
 $('.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');
 }
 });
 }

 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
 varinstalledList='<ul style="list-style-type:none;">';
 $.each(installedScripts,function(index,value){

 // For each script already installed, change the install links (into "installed" messages) that are on the current page (if any)
 $('span.scriptInstallerLink[id="'+encodeURIComponent(value).replace('%3A',':').replace(/\//g,'.2F').replace(/ /g,'_').replace(/%/g,'.').replace(/\.20/g,'_')+'"]')
 .attr('id','installed'+index)
 .addClass('installed')
 .html('Installed')
 .css('font-weight','bold');
 if(jsPage==true)
 $('span.scriptInstallerLink[id="'+value.replace(/ /g,'_')+'"]')
 .attr('id','installed'+index)
 .addClass('installed')
 .html('Installed')
 .css('font-weight','bold');

 // Add an HTML list element for each installed script, containing .js and uninstall links
 installedList=installedList+'<li>'+
 '<a href="#installerLink" class="unInstallerLink">'+unInstallerLink+'</a>: '+
 '<a href="'+pre+value+'">'+decodeURIComponent(value)+'</a>'+
 '</li>';
 });

 // Cap off the list of installed scripts
 installedList=installedList+'</ul>';

 // Build and append the rest if the list box code, and insert our constructed list of installed scripts
 $('.scriptInstaller').html('<div class="installerTitle">'+installerTitle+'</div>'+
 '<div class="container1">'+
 '<div class="installerMessage">'+installerMessage+'</div>'+
 '<div class="uninstallList">'+installedList+'</div>'+
 '</div>');

 // Iterate through each line in the installed list and set the click function for their uninstall links
 $('.scriptInstaller li').each(function(){
 varpath=$(this).find('a:last').html();
 $(this).find('a:first').click(function(){

 // Set parameters for the first uninstall ajax request that occurs when the uninstall link is clicked
 varrequest5={
 action:"query",
 titles:"User:"+mw.config.get("wgUserName")+"/common.js",
 prop:"revisions|info",
 intoken:"edit",
 rvprop:"content",
 indexpageids:1,
 dataType:"xml",
 format:"xml"
 };

 // Send the request
 $.get(mw.config.get("wgScriptPath")+"/api.php",request5,function(response5){

 //Grab common.js content and find/replace our line with nothing, thereby removing the script
 varcontent=$(response5).find('rev').text();
 varnewText=content.replace("\n"+"importScript('"+path+"'); //Linkback: [["+path+"]] Added by Script installer","");

 // Set paraemeters for the ajax post that replaces common.js with our edited version
 varrequest6={
 action:"edit",
 title:"User:"+mw.config.get("wgUserName")+"/common.js",
 text:newText,
 summary:"[[User:Equazcion/ScriptInstaller|Script installer]]: Removed [["+path+"]]",
 token:mw.user.tokens.get("editToken")
 };

 // Send the ajax post to save the new common.js, then reload the current page
 $.post(mw.config.get("wgScriptPath")+"/api.php",request6,function(response6){
 location.reload();
 });
 });
 });
 });
 });

 // Iterate through each templated (via {{userscript}}) script on the page
 $('span.scriptInstallerLink').each(function(){

 // Get the script path, which the template places in the span's ID
 varpath=$(this).attr('id');
 path=path.replace(/.2F/g,'/').replace(/\_/g,' ');

 // If there's more than one dot left in the path, assume percent encoding was converted to dots. Leave the last dot for ".js"
 if((path.split(".").length-1)>1){
 varparts=path.split('.');
 path=parts.slice(0,-1).join('%')+'.'+parts.slice(-1);
 }

 // If this path leads to a valid en-wiki .js script in userspace or wikipedia space, add an install link
 if(((path.toLowerCase().substring(0,5)=="user:")||(path.toLowerCase().substring(0,10)=='wikipedia:'))&&(path.lastIndexOf('.js')==path.length-3)){
 varpipe=(jsPage==true)?'':' | ';
 $(this).html(pipe+'<a href="#installerLink" class="installerLink">'+installerLink+'</a>');

 // Set the click function for the install link
 $(this).find('a.installerLink').click(function(){

 // Set ajax parameters for the ajax post that occurs when the install link is clicked 
 varrequest1={
 action:"edit",
 title:"User:"+mw.config.get("wgUserName")+"/common.js",
 appendtext:"\nimportScript('"+decodeURIComponent(path)+"'); //Linkback: [["+decodeURIComponent(path)+"]] Added by Script installer",
 summary:"[[User:Equazcion/ScriptInstaller|Script installer]]: Added [["+path+"]]",
 token:mw.user.tokens.get("editToken")
 };

 // Send the ajax post, which appends our new importScript line to common.js, then reload the current page
 $.post(mw.config.get("wgScriptPath")+"/api.php",request1,function(response1){
 location.reload();
 });
 });
 }else{
 // If this is not a valid path to an en-wiki .js script in user or wikipedia space, add a "must install manually" message
 $(this).html(' | <span class="noauto">'+noauto+'</span>');
 }
 });
 }
 }
Abgerufen von „https://de.wikipedia.org/w/index.php?title=Benutzer:Der_Buckesfelder/SkriptInstaller.js&oldid=128811281"