User:MarsRover/scripts/api.js
function show_sizes(){
langs=['aa', 'ab', 'af', 'ak', 'als', 'am', 'an', 'ang', 'ar', 'arc', 'arz', 'as', 'ast', 'av',
'ay', 'az', 'ba', 'bar', 'bat-smg', 'bcl', 'be', 'be-x-old', 'bg', 'bh', 'bi', 'bm', 'bn', 'bo',
'bpy', 'br', 'bs', 'bug', 'bxr', 'ca', 'cbk-zam', 'cdo', 'ce', 'ceb', 'ch', 'cho', 'chr', 'chy',
'closed-zh-tw', 'co', 'cr', 'crh', 'cs', 'csb', 'cu', 'cv', 'cy', 'cz', 'da', 'de', 'diq', 'dk',
'dsb', 'dv', 'dz', 'ee', 'el', 'eml', 'en', 'eo', 'epo', 'es', 'et', 'eu', 'ext', 'fa', 'ff',
'fi', 'fiu-vro', 'fj', 'fo', 'fr', 'frp', 'fur', 'fy', 'ga', 'gan', 'gd', 'gl', 'glk', 'gn',
'got', 'gu', 'gv', 'ha', 'hak', 'haw', 'he', 'hi', 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hy',
'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'ilo', 'io', 'is', 'it', 'iu', 'ja', 'jbo', 'jp', 'jv',
'ka', 'kaa', 'kab', 'kg', 'ki', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ksh', 'ku',
'kv', 'kw', 'ky', 'la', 'lad', 'lb', 'lbe', 'lg', 'li', 'lij', 'lmo', 'ln', 'lo', 'lt', 'lv',
'map-bms', 'mdf', 'mg', 'mh', 'mi', 'minnan', 'mk', 'ml', 'mn', 'mo', 'mr', 'ms', 'mt', 'mus',
'my', 'myv', 'mzn', 'na', 'nah', 'nan', 'nap', 'nb', 'nds', 'nds-nl', 'ne', 'new', 'ng', 'nl',
'nn', 'no', 'nomcom', 'nov', 'nrm', 'nv', 'ny', 'oc', 'om', 'or', 'os', 'pa', 'pag', 'pam',
'pap', 'pdc', 'pi', 'pih', 'pl', 'pms', 'pnt', 'ps', 'pt', 'qu', 'rm', 'rmy', 'rn', 'ro',
'roa-rup', 'roa-tara', 'ru', 'rw', 'sa', 'sah', 'sc', 'scn', 'sco', 'sd', 'se', 'sg', 'sh', 'si',
'simple', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'srn', 'ss', 'st', 'stq', 'su', 'sv', 'sw',
'szl', 'ta', 'te', 'tet', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tokipona', 'tp', 'tpi',
'tr', 'ts', 'tt', 'tum', 'tw', 'ty', 'udm', 'ug', 'uk', 'ur', 'uz', 've', 'vec', 'vi', 'vls',
'vo', 'wa', 'war', 'wo', 'wuu', 'xal', 'xh', 'yi', 'yo', 'za', 'zea', 'zh', 'zh-cfr',
'zh-classical', 'zh-min-nan', 'zh-yue', 'zu']
// fetch
params = {"titles": wgPageName,
"prop": "revisions",
"rvprop": "size|content",
"indexpageids": "1"}
api_url = wgServer + '/w/api.php?format=json&action=query&'
api_url += QueryString.create(params)
api_req = topaz.comm.doreq(api_url);
api_data = api_req.responseText
api_data = eval('(' + api_data + ')');
alert(api_url);
alert(api_data);
// handle response
if (api_data["query"] != "undefined"){
page_data = api_data["query"]["pages"]
page_id= api_data["query"]["pageids"][0]
rev = page_data[page_id]["revisions"][0]
bytes= rev["size"]
text= rev["*"]
text_without_iw = text
text_without_cmt = text
//remove interwiki links
reInterwikis=new RegExp("\\[\\[.*\\:\[^\\]\\n\\|\]+\\]\\] *\\r?\\n?", "gi")
iw=0
do {
skip = String(reInterwikis.exec(text))
sep_idx = skip.indexOf(":")
cur_lang = skip.substring(2,sep_idx)
for (lang in langs) {
if (langs[lang] == cur_lang) {
++iw
text_without_iw = text_without_iw.replace(skip,"")
//alert(langs[lang]+" :: "+cur_lang+" :: "+skip)
}
}
} while (skip!="null")
//remove comments
reComments=new RegExp("<!--\[^>\]*--> *\\r?\\n?", "gi")
do {
skip = String(reComments.exec(text))
text_without_cmt = text_without_cmt.replace(skip,"")
} while (skip!="null")
text_length = text.length
iw_chars_number = text.length - text_without_iw.length
cmt_chars_number = text.length - text_without_cmt.length
valid_chars_number= text.length - (iw_chars_number+cmt_chars_number)
function carrega_mides(){
var primer="content", segon="bodyContent";
primerObj = document.getElementById(primer)
segonObj = document.getElementById(segon)
var divSizes = document.createElement("div");
avis = wgAction == "edit" || wgAction == "submit" ? "<b>No heu desat l'article!</b><br/>" : ""
divSizes.innerHTML = '<div class="veSizes" id="sizes" style="position:fixed; right:5px; '+
'bottom:420px; float:right; padding:6px; background-color:#FFFFE0; '+
'border:1px solid orange" ><a onclick="tanca_mides()">'+avis+
'octets:\t'+bytes+'<br/>'+
'caràcters:\t'+valid_chars_number+
'</a></div>';
primerObj.insertBefore(divSizes, segonObj);
sizes=document.getElementById("sizes")
setTimeout("tanca_mides()",10000)
}; addOnloadHook (carrega_mides);
}
}
function tanca_mides(){sizes.style.display="None";clearTimeout()};
if (wgNamespaceNumber == 0 ) show_sizes()
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.