Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Dario Giovannetti committed Nov 29, 2011
0 parents commit af0a26d
Show file tree
Hide file tree
Showing 8 changed files with 929 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JavaScript - Wiki Monkey</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Wiki Monkey is a Greasemonkey script that helps editing wiki pages by letting
you create Javascript functions to automatize repetitive operations.

License: GPLv3 (see LICENSE).

Currently the documentation is at
https://wiki.archlinux.org/index.php/User:Kynikos/Wiki_Monkey
61 changes: 61 additions & 0 deletions src/user-functions/archWikiNewTemplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function UF_archWikiNewTemplates() {
var s = readSource();

var re1 = /\{\{ *(?:[Cc]odeline|[Ff]ilename) *\|([^\|\=\{\n]+?)\}\}/g;
var re2 = /\{\{ *[Cc]li *\|([^\|\=\{]+?)\}\}/g;
var re3 = /\{\{ *[Cc]ommand *\|(?: *(?:command|name) *\=)?([^\|\=\{]+?)\|(?: *output *\=)?([^\|\=\{]+?)\| *prompt *\= *([\$#]) *\}\}/g;
var re4 = /\{\{ *[Cc]ommand *\| *prompt *\= *([\$#]) *\|(?: *(?:command|name) *\=)?([^\|\=\{]+?)\|(?: *output *\=)?([^\|\=\{]+?)\}\}/g;
var re5 = /\{\{ *[Cc]ommand *\|(?: *(?:command|name) *\=)?([^\|\=\{]+?)\|(?: *output *\=)?([^\|\=\{]+?)\}\}/g;
var re6 = /\{\{ *[Ff]ile *\|(?: *name *\=)?([^\|\=\{]+?)\|(?: *content *\=)?([^\|\=\{]+?)\}\}/g;
var re7 = /&lt;pre&gt;([^\|\=\{]+?)&lt;\/pre&gt;/g;
var re8 = /&lt;code&gt;([^\|\=\{\n]+?)&lt;\/code&gt;/g;
var re9 = /&lt;tt&gt;([^\|\=\{\n]+?)&lt;\/tt&gt;/g;
var re10 = /\{\{ *[Pp]ackage Official *\|([^\|\=\{\n]+?)\}\}/g;
var re11 = /\{\{ *[Pp]ackage AUR *\|([^\|\=\{\n]+?)\}\}/g;

s = s.replace(re1, '{{ic|$1}}');
s = s.replace(re2, '{{bc|$1}}');
s = s.replace(re3, '{{hc|$3 $1|$2}}');
s = s.replace(re4, '{{hc|$1 $2|$3}}');
s = s.replace(re5, '{{hc|\$ $1|$2}}');
s = s.replace(re6, '{{hc|$1|$2}}');
s = s.replace(re7, '{{bc|$1}}');
s = s.replace(re8, '{{ic|$1}}');
s = s.replace(re9, '{{ic|$1}}');
s = s.replace(re10, '{{Pkg|$1}}');
s = s.replace(re11, '{{AUR|$1}}');

writeSource(s);

var tests = new Array();
tests[0] = s.match(/\{\{ *[Cc]odeline/g);
tests[1] = s.match(/\{\{ *[Ff]ilename/g);
tests[2] = s.match(/\{\{ *[Cc]li/g);
tests[3] = s.match(/\{\{ *[Ff]ile(?!name)/g);
tests[4] = s.match(/\{\{ *[Cc]ommand/g);
tests[5] = s.match(/&lt;pre/g);
tests[6] = s.match(/&lt;code/g);
tests[7] = s.match(/&lt;tt/g);
tests[8] = s.match(/\{\{ *[Pp]ackage Official/g);
tests[9] = s.match(/\{\{ *[Pp]ackage AUR/g);

var ab = false;
for each (var test in tests)
if (test)
ab = true;

if (ab) {
alert('Migration to new templates:\n' +
((tests[0]) ? (tests[0].length + ' Codeline instances\n') : '') +
((tests[1]) ? (tests[1].length + ' Filename instances\n') : '') +
((tests[2]) ? (tests[2].length + ' Cli instances\n') : '') +
((tests[3]) ? (tests[3].length + ' File instances\n') : '') +
((tests[4]) ? (tests[4].length + ' Command instances\n') : '') +
((tests[5]) ? (tests[5].length + ' <pre> instances\n') : '') +
((tests[6]) ? (tests[6].length + ' <code> instances\n') : '') +
((tests[7]) ? (tests[7].length + ' <tt> instances\n') : '') +
((tests[8]) ? (tests[8].length + ' Package Official instances\n') : '') +
((tests[9]) ? (tests[9].length + ' Package AUR instances\n') : '') +
'require manual intervention.');
}
}
14 changes: 14 additions & 0 deletions src/user-functions/botOperations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function EF_botOperations() {
// Remember a value
GM_setValue('foo' + 'bar');

// Alert all stored values
for each (var val in GM_listValues()) {
alert(val + ' : ' + GM_getValue(val));
}

// Reset array
for each (var key in GM_listValues()) {
GM_deleteValue(key);
}
}
10 changes: 10 additions & 0 deletions src/user-functions/getBacklinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function UF_getBacklinks() {
parser = new DOMParser();
xml = parser.parseFromString(getBacklinks(), "text/xml");
var bls = new Array();
var L = xml.getElementsByTagName('bl');
for (var i = 0; i < L.length; i++) {
bls.push(L[i].getAttribute('title'));
}
alert(bls);
}
7 changes: 7 additions & 0 deletions src/user-functions/multipleLineBreaks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function UF_multipleLineBreaks() {
var s = readSource();

s = s.replace(/[\n]{3,}/g, '\n\n');

writeSource(s);
}
145 changes: 145 additions & 0 deletions src/wikiMonkey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Wiki Monkey - Perform automatic actions when editing wiki pages.
* Copyright (C) 2011 Dario Giovannetti <dev@dariogiovannetti.com>
*
* Wiki Monkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wiki Monkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wiki Monkey. If not, see <http://www.gnu.org/licenses/>.
*/

// ==UserScript==
// @name Wiki Monkey
// @namespace wikimonkey
// @description Perform automatic actions when editing wiki pages
// @version 1.1.0
// @icon http://www.dariogiovannetti.com/files/wiki-monkey.png
// @match http://*.wikipedia.org/*
// @match https://wiki.archlinux.org/*
// ==/UserScript==

/*
* === USER FUNCTIONS ===
*
* Define here your functions, then add their names to the array at the bottom
* of the file
* To keep the namespace tidy, all user function names should be prefixed with "UF_"
*/

function UF_example() {
alert('This is a demonstration function');
}

/*
* === CORE FUNCTIONS ===
*
* These are the standard functions, you don't need to modify them
*/

function _getQueryString() {
var qa = location.search.substr(1).split('&');

var qd = new Object();
var s = new Array();
for each (var p in qa) {
s = p.split('=');
qd[s[0]] = s[1];
}

return qd;
}

// Get query string parameters only once
var querystring = _getQueryString();

var xmlhttp;

function _sendAsyncRequest(url, cfunc) {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
cfunc();
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}

function _sendSyncRequest(url) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, false);
xmlhttp.send();
}

function getTitle() {
return querystring['title'];
}

function isSection() {
return (querystring['section']) ? true : false;
}

function readSource() {
return document.getElementById('wpTextbox1').innerHTML;
}

function writeSource(text) {
document.getElementById('wpTextbox1').innerHTML = text;
}

function readSummary() {
return document.getElementById('wpSummary').innerHTML;
}

function writeSummary(text) {
document.getElementById('wpSummary').innerHTML = text;
}

function appendToSummary(text) {
document.getElementById('wpSummary').innerHTML += text;
}

function getBacklinks() {
_sendSyncRequest("api.php?action=query&list=backlinks&bltitle=" + getTitle() + "&format=xml");
return xmlhttp.responseText;
}

function main(functions) {
if (document.getElementById('editform')) {
var bcorrect = document.createElement('input');
bcorrect.setAttribute('type', 'button');
bcorrect.setAttribute('value', 'Correct source');
bcorrect.style.marginRight = '0.33em';
for each (var f in functions) {
bcorrect.addEventListener("click", f, false);
}

var buttons = document.getElementById('wpSave').parentNode;
buttons.insertBefore(bcorrect, buttons.getElementsByTagName('span')[0]);
}
}

/*
* Add user functions to the array passed to main(), they will be executed in
* the same order.
* For example:
*
* main([
* UF_myFunction1,
* UF_myFunction2,
* UF_myFunction3,
* ]);
*
*/

main([
UF_example,
]);

0 comments on commit af0a26d

Please sign in to comment.