User:Iceblock/Scripts/Seeking-help.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Iceblock/Scripts/Seeking-help. |
/*
To use the script, add the following line to Special:MyPage/common.js
importScript('User:Iceblock/Scripts/Seeking-help.js'); // Linkback: [[User:Iceblock/Scripts/Seeking-help.js]]
* Documentation: This script adds a tab with information on how
* many Wikipedians currently are looking for help.
* Clicking the tab will open Category:Wikipedians_looking_for_help
*
*
* This script is based on the two scripts
*
* http://no.wikipedia.org/wiki/MediaWiki:Gadget-HurtigSlett.js
* http://en.wikipedia.org/wiki/MediaWiki:Gadget-dropdown-menus.js
*
* The function createTab2 is taken from
* MediaWiki:Gadget-dropdown-menus.js (called createTab there).
* It is modified not to include 'mid' and to include 'link'.
* It is also modified to check the page name and set the class
* name to 'selected' if the page name matches the category name.
* The rest of this script is based on MediaWiki:Gadget-HurtigSlett.js
* and modified to check Category:Wikipedians_looking_for_help
* Under the Vector skin, it places the tab to the left (!) to ensure it is
* being displayed on special pages.
*
* In the function names, 'qd' is replaced with 'seekinghelp'.
*
* An unused function (function displayQuickDelete()) is removed from this script.
*
*/
// Create cactions LI tab
function createTab2(cid,ltxt,link) {
var elements = {
li: document.createElement('li'),
a: document.createElement('a'),
span: document.createElement('span'),
txt: document.createTextNode(ltxt)
};
with (elements) {
if ( wgPageName == 'Category:Wikipedians_looking_for_help' ) {
li.className='selected';
}
li.id = cid;
a.href = link;
span.appendChild(txt); a.appendChild(span); li.appendChild(a);
}
return elements.li;
}
/* Memo to self, den som skal sjekkes mot er denne */
/* http://no.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Kategori:Sider%20som%20er%20foresl%E5tt%20raskt%20slettet&format=xml */
/* Vi har to mulige valg å legge denne på: */
/* <div id="p-cactions" class="portlet"> <-- Brukerside, diskusjon, overvåk, etc. */
/* <div class="portlet" id="p-personal"> <-- Brukernavn, min diskusjonsside, innstillinger, etc. */
/* (function displayQuickDelete() removed) */
/* init ajax */
function seekinghelp_create_request() {
try {
seekinghelp_http = new XMLHttpRequest();
} catch (e) {
try {
seekinghelp_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
seekinghelp_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
seekinghelp_http.onreadystatechange = function() {
if(seekinghelp_http.readyState == 4) seekinghelp_ajax_response();
}
return true;
}
/* make a request */
function seekinghelp_ajax_request() {
var api_link = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&list=categorymembers&cmtitle=Category:Wikipedians%20looking%20for%20help&format=xml&cmlimit=25';
if (seekinghelp_create_request () == false) {
return;
}
// Then make the request
seekinghelp_http.open("GET", api_link, true);
seekinghelp_http.send(null);
}
/* we have received a response */
function seekinghelp_ajax_response() {
var refresh_time = 60;
var link = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Category:Wikipedians_looking_for_help&action=purge';
var items = seekinghelp_http.responseXML.getElementsByTagName('cm');
//items.length;
document.getElementById((skin=='vector')?'left-navigation':'p-cactions').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(createTab2('ca-seekinghelp', items.length + ' seeking help', link));
/* Repeat */
/* Actually, I think we should not repeat, check if it is updated on page refresh, and if that is enough */
// setTimeout("seekinghelp_ajax_request()", refresh_time * 1000);
}
addOnloadHook(seekinghelp_ajax_request);