From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search
m (last character, hopefully)
(test worked)
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
//Common library functions used by many of the scripts below
// FIND AND REPLACE (modified)
importScript('User:Ryan Schmidt/Scripts/library.js');
//
//  Author: User:Zocky @ en.wikipedia.org
//  License: (c) 2006, released under GPL
//   Desc: Adds a dropdown utility under the edit toolbar for search and replace terms.


//Find and replace script
importScript('User:Najzere/zockys SearchBox.js');
//by Zocky
importScript('User:Ryan Schmidt/Scripts/SearchBox.js');
/**
* AJAX patrol feature version 1.1
* by Ryan Schmidt < http://strategywiki.org/wiki/User:Ryan_Schmidt >
*/


/*
// AJAX PATROL V1.1 (modified)
* CONFIGURATION
//
* You may set whether or not to automatically browse to the next diff
//  Author: User:Ryan Schmidt
* By placing the following BEFORE the importScript() call:
//  License: Unstated (CC-BY-SA)
* var AjaxPatrolAutoNext = true;
//  Description: Moves to next diff when you patrol and edit, or removes link if you're on the last one.
*/


var AjaxPatrolAutoNext = true;
var AjaxPatrolAutoNext = true; // set to "true" to turn on, or "false" to turn off
AjaxPatrol = new function() {
importScript('User:Najzere/ajaxpatrol.js');
this.setup = function() {
var links = getElementsByClassName(document, 'span', 'patrollink');
for(var i=0; i<links.length; i++) {
addClickHandler(links[i].getElementsByTagName('a')[0], function(e) { AjaxPatrol.patrol(e); });
}
};


this.patrol = function(e) {
// URL SOURCE ON UPLOAD
var a = e.target || e.srcElement;
//
var next;
//  Author: User:Najzere
var ajax = this.ajaxRequest();
//  License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
if(ajax) {
//  Description: Adds image source to upload summary when uploading from URL
ajax.onreadystatechange = function() {
if(ajax.readyState == 4) {
if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) {
window.location = next.href;
} else {
document.getElementById('mw-diff-ntitle4').style.display="none";
}
}
};
ajax.open('GET', a.href, true);
ajax.send(null);
e.preventDefault();
}
};


this.ajaxRequest = function() {
importScript('User:Najzere/adduploadurl.js');
var ret = false;
try {
ret = new XMLHttpRequest();
} catch(e) {
try {
ret = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
ret = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
return false;
}
}
}
return ret;
};
}();
 
addOnloadHook(function() {
if(typeof AjaxPatrolAutoNext == 'undefined') {
AjaxPatrolAutoNext = false;
}
AjaxPatrol.setup();
});


// ACHIEVEMENTS QUICK-FORMATTING
//
//  Author: User:Najzere
//  License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
//  Description: Adds a button to the edit toolbar that attempts to format
//                copy/paste from xbox360achievements.com into SW achievements table.


/* Adding cleanup button */
importScript('User:Najzere/formatachievements.js');
addOnloadHook( function() {
  addPersonalItem('cleanup', '/wiki/StrategyWiki:Cleanup project/Daily tasks', 'Cleanup', 'preferences');
});


/* Add source URL to summary when uploading from URL */
// EDIT COUNTER
if (wgPageName == "Special:Upload") {
//
    addOnloadHook(get_URL);
//  Author: User:Najzere
}
//  License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
//  Description: Adds a button to the toolbox that generates a table of your edit counts by namespace.


function get_URL() {
var editPage = 'Edit count';              // Page in userspace where table is written to
    var URL_form=document.getElementById('wpUploadFileURL');
var tableClass = 'collapsible collapsed';  // Class for the table
    addHandler(URL_form, 'change', insert_URL);
var tableStyle = 'width:100%';             // Styles for the table
}
mw.loader.load('http://strategywiki.org/w/index.php?title=User:Najzere/edit_counter.js&action=raw&ctype=text/javascript');


function insert_URL(event) {
// test
  var URL = document.getElementById('wpUploadFileURL').value;
importScript('User:Najzere/spoilerimage.js');
  var summary = document.getElementById('wpUploadDescription');
  var re = /\[http.*? Source URL\]/;
  if(summary.value.match(re)) {
    summary.value = summary.value.replace(re, '[' + URL + ' Source URL]');
  } else {
    summary.value = summary.value + '\n\n[' + URL + ' Source URL]';
  }
}


/*** ACHIEVEMENTS QUICK-FORMATTING ***/
// CUSTOM STUFF ON PAGE LOAD
/*  Note: this script only works    */
//
/*        with achievements from    */
//   Author: User:Najzere
/*        xbox360achievements.org.  */
//   License: Public Domain
/*************************************/
//   Description: Add some links


if (wgAction == 'edit') {
// Add stuff on page load
  addOnloadHook(addFormatAchievementsButton);
$(document).ready(function() {
};
   // Add link directly to sub-pages of the current page
 
   mw.util.addPortletLink('p-tb','/w/index.php?title=Special:PrefixIndex&prefix='+mw.config.get('wgTitle')+'/'+'&namespace='+mw.config.get('wgNamespaceNumber'),'Sub-pages','t-subpages','View sub-pages',false,'#t-recentchangeslinked');
function addFormatAchievementsButton() {
  mw.util.addPortletLink('p-personal','/wiki/User:Najzere/Cleanup','Cleanup','p-cleanup','Personal cleanup stuff',false,'#pt-preferences');
   var image = document.createElement('img');
});
   image.width = 23;
  image.height = 22;
  image.className = 'mw-toolbar-editbutton';
  image.id = 'format-achievements-button';
  image.src = 'http://media.strategywiki.org/images/b/b2/Achievement_unlocked.png';
  image.border = 0;
  image.title = 'Format achievements';
  image.style.cursor = 'pointer';
  image.onclick = function() {
    formatAchievements();
    return false;
  };
  document.getElementById('toolbar').appendChild(image);
  return false;
}
 
function formatAchievements() {
  var txtarea = document.editform.wpTextbox1;
  if (txtarea.value != '') {
    var endPos;
    var endLine;
    var endLine2;
    var aName;
    var aDesc;
 
    var startPos = txtarea.value.search(/\n /g) + 2;
    while (startPos != 1) {
      endPos = txtarea.value.search(/[^\n] /g) + 1 - startPos;
      aName = txtarea.value.substr(startPos, endPos).replace(/([\|\?#!%\.,=…])/g,'');
      endLine = txtarea.value.substr(startPos + 2, txtarea.value.length).search(/\n/g) + startPos + 2;
      aDesc = txtarea.value.substr(endLine + 1, txtarea.value.substr(endLine + 1,txtarea.value.length).search(/\n/g));
      txtarea.value = txtarea.value.substr(0, endLine).replace(/\n /g, '\n| [[Image:**NAME** ' + aName + ' achievement.jpg]] || ') + txtarea.value.substr(endLine, txtarea.value.length);
      txtarea.value = txtarea.value.substr(0, txtarea.value.search(/ /g)) + ' || ' + aDesc + ' || {{G|' + txtarea.value.substr(txtarea.value.search(/ /g) + 1, txtarea.value.length);
      endLine = txtarea.value.substr(startPos + 2, txtarea.value.length).search(/\n/g) + startPos + 2;
      endLine2 = txtarea.value.substr(endLine + 1,txtarea.value.length).search(/\n/g) + endLine + 1;
      txtarea.value = txtarea.value.substr(0, endLine) + '}}\n|-' + txtarea.value.substr(endLine2, txtarea.value.length);
      startPos = txtarea.value.search(/\n /g) + 2;
    };
  alert('Done.');
  };
}
 
/*** END - ACHIEVEMENTS QUICK-FORMATTING ***/

Latest revision as of 14:22, 11 April 2013

// FIND AND REPLACE (modified)
//
//   Author: User:Zocky @ en.wikipedia.org
//   License: (c) 2006, released under GPL
//   Desc: Adds a dropdown utility under the edit toolbar for search and replace terms.

importScript('User:Najzere/zockys SearchBox.js');

// AJAX PATROL V1.1 (modified)
//
//   Author: User:Ryan Schmidt
//   License: Unstated (CC-BY-SA)
//   Description: Moves to next diff when you patrol and edit, or removes link if you're on the last one.

var AjaxPatrolAutoNext = true; // set to "true" to turn on, or "false" to turn off
importScript('User:Najzere/ajaxpatrol.js');

// URL SOURCE ON UPLOAD
//
//   Author: User:Najzere
//   License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
//   Description: Adds image source to upload summary when uploading from URL

importScript('User:Najzere/adduploadurl.js');

// ACHIEVEMENTS QUICK-FORMATTING
//
//   Author: User:Najzere
//   License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
//   Description: Adds a button to the edit toolbar that attempts to format
//                copy/paste from xbox360achievements.com into SW achievements table.

importScript('User:Najzere/formatachievements.js');

// EDIT COUNTER
//
//   Author: User:Najzere
//   License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
//   Description: Adds a button to the toolbox that generates a table of your edit counts by namespace.

var editPage = 'Edit count';               // Page in userspace where table is written to
var tableClass = 'collapsible collapsed';  // Class for the table
var tableStyle = 'width:100%';             // Styles for the table
mw.loader.load('http://strategywiki.org/w/index.php?title=User:Najzere/edit_counter.js&action=raw&ctype=text/javascript');

// test
importScript('User:Najzere/spoilerimage.js');

// CUSTOM STUFF ON PAGE LOAD
//
//   Author: User:Najzere
//   License: Public Domain
//   Description: Add some links

// Add stuff on page load
$(document).ready(function() {
  // Add link directly to sub-pages of the current page
  mw.util.addPortletLink('p-tb','/w/index.php?title=Special:PrefixIndex&prefix='+mw.config.get('wgTitle')+'/'+'&namespace='+mw.config.get('wgNamespaceNumber'),'Sub-pages','t-subpages','View sub-pages',false,'#t-recentchangeslinked');
  mw.util.addPortletLink('p-personal','/wiki/User:Najzere/Cleanup','Cleanup','p-cleanup','Personal cleanup stuff',false,'#pt-preferences');
});