User:Jdrowlands/monobook.js: Difference between revisions
From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search
Jdrowlands (talk | contribs) (just a small test...) |
Jdrowlands (talk | contribs) (and...) |
||
Line 75: | Line 75: | ||
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=delete&user=" + username, "Deletions", "", "Deletions by this user"); | addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=delete&user=" + username, "Deletions", "", "Deletions by this user"); | ||
} | } | ||
var rcp_http; | |||
var rcp_enabled; | |||
var rcp_num_pages; | |||
var rcp_refresh; | |||
addOnloadHook( rcp_init ); | |||
/* initalise */ | |||
function rcp_init() { | |||
// allow user settings through | |||
if(rcp_enabled == null) { | |||
rcp_enabled = false; | |||
} | |||
if(rcp_num_pages == null) { | |||
rcp_num_pages = 10; | |||
} | |||
if(rcp_refresh == null) { | |||
rcp_refresh = 5; | |||
} | |||
// A few limits to be nice to the servers | |||
if (rcp_num_pages > 50) { | |||
rcp_num_pages = 50; | |||
} | |||
if (rcp_num_pages < 1) { | |||
rcp_num_pages = 1; | |||
} | |||
if (rcp_refresh < 2) { | |||
rcp_refresh = 2; | |||
} | |||
// get our cookie | |||
if (document.cookie.length > 0) { | |||
var c_start = document.cookie.indexOf("rcp_show_box="); | |||
if (c_start != -1) { | |||
c_start = c_start + 13; | |||
var c_end = document.cookie.indexOf(";", c_start); | |||
if (c_end == -1) { | |||
c_end = document.cookie.length; | |||
} | |||
if (document.cookie.substring(c_start, c_end) == "yes") { | |||
rcp_enabled = true; | |||
} else { | |||
rcp_enabled = false; | |||
} | |||
} | |||
} | |||
// Either make a request or show nothing | |||
if (rcp_enabled == true) { | |||
rcp_ajax_request(); | |||
} else { | |||
rcp_draw_disabled_box(); | |||
} | |||
} | |||
/* init ajax */ | |||
function rcp_create_request() { | |||
try { | |||
rcp_http = new XMLHttpRequest(); | |||
} catch (e) { | |||
try { | |||
rcp_http = new ActiveXObject("Msxml2.XMLHTTP"); | |||
} catch (e) { | |||
try { | |||
rcp_http = new ActiveXObject("Microsoft.XMLHTTP"); | |||
} catch (e) { | |||
alert("Your browser does not support AJAX!"); | |||
return false; | |||
} | |||
} | |||
} | |||
rcp_http.onreadystatechange = function() { | |||
if(rcp_http.readyState == 4) rcp_ajax_response(); | |||
} | |||
return true; | |||
} | |||
/* make a request */ | |||
function rcp_ajax_request() { | |||
// check we are enabled | |||
if (rcp_enabled == false) return; | |||
// firstly, inform the user | |||
var cur_box = document.getElementById('p-recentchanges'); | |||
if (cur_box != null) { | |||
cur_box.firstChild.firstChild.data = 'Recent Changes (updating)'; | |||
} | |||
if (rcp_create_request () == false) { | |||
if (cur_box != null) { | |||
cur_box.firstChild.firstChild.data = 'Recent Changes (update failed)'; | |||
} else { | |||
alert ("There seems to be a problem using the RecentChangePatrol script. I can't make AJAX objects, so I'm just going to complain. God Bless!"); | |||
} | |||
} | |||
// Then make the request | |||
rcp_http.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=recentchanges&format=xml&rcnamespace=0&rcshow=!bot&rcshow=!minor&rclimit=" + rcp_num_pages, true); | |||
rcp_http.send(null); | |||
} | |||
/* we have received a response */ | |||
function rcp_ajax_response() { | |||
var items = rcp_http.responseXML.getElementsByTagName('rc'); | |||
// create the div that holds all the recentchanges links | |||
var link_div = document.createElement('div'); | |||
link_div.className = 'pBody'; | |||
var list = document.createElement('ul'); | |||
link_div.appendChild(list); | |||
// populate the list with 10 links. | |||
for (var i = 0; i < items.length; i++) { | |||
var item_name = items[i].getAttribute('title'); | |||
var item_url = 'http://www.mariowiki.com/index.php?diff=cur&oldid=prev&title=' + escape(item_name); | |||
a = document.createElement('a'); | |||
a.setAttribute('href', item_url); | |||
a.appendChild(document.createTextNode(item_name)); | |||
var li = document.createElement('li'); | |||
li.appendChild(a); | |||
list.appendChild(li); | |||
} | |||
// Container div | |||
var div = document.createElement('div'); | |||
div.setAttribute('id', 'p-recentchanges'); | |||
div.className = 'portlet'; | |||
var heading = document.createElement('h5'); | |||
heading.appendChild(document.createTextNode('Recent Changes')); | |||
div.appendChild(heading); | |||
div.appendChild(link_div); | |||
// disable link | |||
var p = document.createElement('p'); | |||
p.style.fontSize = 'x-small'; | |||
p.style.margin = '0px'; | |||
p.style.textAlign = 'right'; | |||
a = document.createElement('a'); | |||
a.appendChild(document.createTextNode('disable this box')); | |||
a.onclick = rcp_disable_box; | |||
p.appendChild(a); | |||
link_div.appendChild(p); | |||
// now replace the div | |||
var old_div = document.getElementById('p-recentchanges'); | |||
var side_col = document.getElementById('column-one'); | |||
if (old_div != null) { | |||
side_col.replaceChild(div, old_div); | |||
} else { | |||
var node = document.getElementById('p-search'); | |||
side_col.insertBefore(div, node); | |||
} | |||
// and do it again in 5 secs | |||
setTimeout("rcp_ajax_request()", rcp_refresh * 1000); | |||
} | |||
function rcp_disable_box() { | |||
rcp_enabled = false; | |||
rcp_draw_disabled_box(); | |||
document.cookie = "rcp_show_box=no; path=/"; | |||
} | |||
function rcp_enable_box() { | |||
rcp_enabled = true; | |||
document.cookie = "rcp_show_box=yes; path=/"; | |||
rcp_ajax_request(); | |||
} | |||
function rcp_draw_disabled_box() { | |||
// Container div | |||
var link_div = document.createElement('div'); | |||
link_div.className = 'pBody'; | |||
var div = document.createElement('div'); | |||
div.setAttribute('id', 'p-recentchanges'); | |||
div.className = 'portlet'; | |||
var heading = document.createElement('h5'); | |||
heading.appendChild(document.createTextNode('Recent Changes')); | |||
div.appendChild(heading); | |||
div.appendChild(link_div); | |||
// enable link | |||
var p = document.createElement('p'); | |||
p.style.fontSize = 'x-small'; | |||
p.style.margin = '0px'; | |||
var a = document.createElement('a'); | |||
a.appendChild(document.createTextNode('enable this box')); | |||
a.onclick = rcp_enable_box; | |||
p.appendChild(a); | |||
link_div.appendChild(p); | |||
// now replace the div | |||
var old_div = document.getElementById('p-recentchanges'); | |||
var side_col = document.getElementById('column-one'); | |||
if (old_div != null) { | |||
side_col.replaceChild(div, old_div); | |||
} else { | |||
var node = document.getElementById('p-search'); | |||
side_col.insertBefore(div, node); | |||
} | |||
} | |||
/* </nowiki> </pre> */ | /* </nowiki> </pre> */ |
Revision as of 10:12, March 23, 2008
/* <pre> <nowiki> */
/* WikEd text editor */
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
function addTab(id, after, caption, url) {
if (!document.getElementById(id)) {
var edit = document.getElementById(after);
if (!edit) return; //If the previous tab doesn't exist, don't add this one
var editparent = edit.parentNode;
var aseclinkcaption = document.createTextNode(caption)
var aseclink = document.createElement('a');
aseclink.setAttribute('href',url);
var addsectionlinkcaption = aseclink.appendChild(aseclinkcaption);
var asec = document.createElement('li');
asec.setAttribute('id',id);
var addsectionlink = asec.appendChild(aseclink);
var addsection = editparent.insertBefore(asec,edit.nextSibling);
}
}
//source: http://en.wikipedia.org/wiki/User:Flex/welcome_newuser.js
function welcome() {
// Find the edit box
var txt = document.editform.wpTextbox1;
//The welcome *template* you want to use
var welcome_user = 'Jdrowlands';
var welcome_summary = 'Welcome';
var welcome_watch = false;
var tag = '{{welcome|'+ welcome_user +'}}';
if (txt.value.indexOf(tag) == -1) {
txt.value += tag;
document.editform.wpSummary.value = welcome_summary;
document.editform.wpWatchthis.checked = welcome_watch;
document.editform.submit();
}
else {
document.getElementById('ca-unverified').firstChild.style.backgroundColor = "#ff4444";
document.getElementById('ca-unverified').style.backgroundColor = "#ff4444";
}
}
addOnloadHook(
function ()
{
if(document.title.indexOf("Editing User talk:") == 0)
{
addPortletLink('p-cactions', 'javascript:welcome()', 'welcome', 'ca-welcome', 'Adds a welcome note to the new user', '', '');
}
}
);
// [[user:Where/usertabs]]
// This is a good one!
addOnloadHook(function() {
if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1) //no subpages or history
return;
if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
var username = encodeURIComponent( wgTitle );
addPortletLink("p-cactions", wgServer + "/Special:Contributions/" + username, "Edits", "ca-contrib", "User contributions");
addPortletLink("p-cactions", "/index.php?title=Special:EditCount&target="+ username + "&doeditcount=Show+count", "Edit count", "ca-editcount", "Get this user's edit count.");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=move&user=" + username, "Moves", "ca-pagemoves", "Page moves by this user");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=block&page=User:" + username, "Blocks", "ca-blog", "Blocks received by this user");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Prefixindex&from=" + username + "&namespace=2", "Userspace", "", "List of pages in this user's userspace");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=block&user=" + username, "Block Log", "", "Blocks by this user");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=protect&user=" + username, "Protections", "", "Protections by this user");
addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Log&type=delete&user=" + username, "Deletions", "", "Deletions by this user");
}
var rcp_http;
var rcp_enabled;
var rcp_num_pages;
var rcp_refresh;
addOnloadHook( rcp_init );
/* initalise */
function rcp_init() {
// allow user settings through
if(rcp_enabled == null) {
rcp_enabled = false;
}
if(rcp_num_pages == null) {
rcp_num_pages = 10;
}
if(rcp_refresh == null) {
rcp_refresh = 5;
}
// A few limits to be nice to the servers
if (rcp_num_pages > 50) {
rcp_num_pages = 50;
}
if (rcp_num_pages < 1) {
rcp_num_pages = 1;
}
if (rcp_refresh < 2) {
rcp_refresh = 2;
}
// get our cookie
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf("rcp_show_box=");
if (c_start != -1) {
c_start = c_start + 13;
var c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
if (document.cookie.substring(c_start, c_end) == "yes") {
rcp_enabled = true;
} else {
rcp_enabled = false;
}
}
}
// Either make a request or show nothing
if (rcp_enabled == true) {
rcp_ajax_request();
} else {
rcp_draw_disabled_box();
}
}
/* init ajax */
function rcp_create_request() {
try {
rcp_http = new XMLHttpRequest();
} catch (e) {
try {
rcp_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
rcp_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
rcp_http.onreadystatechange = function() {
if(rcp_http.readyState == 4) rcp_ajax_response();
}
return true;
}
/* make a request */
function rcp_ajax_request() {
// check we are enabled
if (rcp_enabled == false) return;
// firstly, inform the user
var cur_box = document.getElementById('p-recentchanges');
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Recent Changes (updating)';
}
if (rcp_create_request () == false) {
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Recent Changes (update failed)';
} else {
alert ("There seems to be a problem using the RecentChangePatrol script. I can't make AJAX objects, so I'm just going to complain. God Bless!");
}
}
// Then make the request
rcp_http.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=recentchanges&format=xml&rcnamespace=0&rcshow=!bot&rcshow=!minor&rclimit=" + rcp_num_pages, true);
rcp_http.send(null);
}
/* we have received a response */
function rcp_ajax_response() {
var items = rcp_http.responseXML.getElementsByTagName('rc');
// create the div that holds all the recentchanges links
var link_div = document.createElement('div');
link_div.className = 'pBody';
var list = document.createElement('ul');
link_div.appendChild(list);
// populate the list with 10 links.
for (var i = 0; i < items.length; i++) {
var item_name = items[i].getAttribute('title');
var item_url = 'http://www.mariowiki.com/index.php?diff=cur&oldid=prev&title=' + escape(item_name);
a = document.createElement('a');
a.setAttribute('href', item_url);
a.appendChild(document.createTextNode(item_name));
var li = document.createElement('li');
li.appendChild(a);
list.appendChild(li);
}
// Container div
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portlet';
var heading = document.createElement('h5');
heading.appendChild(document.createTextNode('Recent Changes'));
div.appendChild(heading);
div.appendChild(link_div);
// disable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
p.style.textAlign = 'right';
a = document.createElement('a');
a.appendChild(document.createTextNode('disable this box'));
a.onclick = rcp_disable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-recentchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
// and do it again in 5 secs
setTimeout("rcp_ajax_request()", rcp_refresh * 1000);
}
function rcp_disable_box() {
rcp_enabled = false;
rcp_draw_disabled_box();
document.cookie = "rcp_show_box=no; path=/";
}
function rcp_enable_box() {
rcp_enabled = true;
document.cookie = "rcp_show_box=yes; path=/";
rcp_ajax_request();
}
function rcp_draw_disabled_box() {
// Container div
var link_div = document.createElement('div');
link_div.className = 'pBody';
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portlet';
var heading = document.createElement('h5');
heading.appendChild(document.createTextNode('Recent Changes'));
div.appendChild(heading);
div.appendChild(link_div);
// enable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
var a = document.createElement('a');
a.appendChild(document.createTextNode('enable this box'));
a.onclick = rcp_enable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-recentchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
}
/* </nowiki> </pre> */