User:Crower/Dictionary2.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Based on the Dictionary.js (ThomasV)
author: Crower
*/
function dict_entry_callback(res) {
var res2 = eval("0,"+res);
var txt = res2.parse.text['*'];
var item = document.getElementById("dict_entry");
if(item) { item.innerHTML = txt;
self.pagenum_ml = get_elements_by_classname( 'pagenum', 'span' );
for(var i=self.pagenum_ml.length-1; i>=0; i--) {
var a = self.pagenum_ml[i];
var num = decodeURI( a.id ); //.replace(/\./g,'%')
if(num==".CE.9E") num="Ξ";
var page = a.title;
pagetitle = decodeURI( page ); //.replace('?','%3F').replace(/\.2/g,'%2').replace("%2F","/")
pagekey = pagetitle.replace(/ /g,"_");
var page_url = wgArticlePath.replace("$1", pagekey );
var ll = a.parentNode.nextSibling;
if(ll && ll.tagName=="A" && ll.className=="new") class_str=" class=\"new\" "; else class_str="";
var link_str = "<a href=\""+page_url+"\"" + class_str + " title=\""+pagetitle+"\">"+num+"</a>"
a.innerHTML = " <span class=\"pagenumber noprint\" style=\"color:#666666; display:inline; margin:0px; padding:0px;\">[<b>"+link_str+"</b>]</span> ";
}
}
}
function show_dict_entry2( index, frompage, topage, fromsection, tosection) {
var item = document.getElementById("dict_entry");
if(!item) return;
item.innerHTML="…";
var url = mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/api.php?format=json&action=parse&text=<pages index="'+index+'"';
if (frompage != undefined){
url = url + ' from=' + frompage;
}
if (topage != undefined){
url = url + ' to=' + topage;
}
if (fromsection != undefined){
url = url + ' fromsection="' + fromsection + '"';
}
if (tosection != undefined){
url = url + ' tosection="' + tosection + '"';
}
url = url + ' /> <references/>';
/* temporary disabled
var api=s*/ /*ajax_init_object();
api.open("GET",url,true);
api.onreadystatechange=function(){
/&asterisk; if(api.readyState!=4) return;
if(api.status==200)
&asterisk;/
dict_entry_callback(api.responseText);
};
api.send(null);
*/
location.href = document.URL.split('#')[0] + '#'+ escape(encodeURI( fromsection.replace(/ /g,'_')).replace(/%/g,'.') ).replace(/%/g,'.');
}
function dl_links2() {
var mlist = document.getElementById("dynamic_links");
if(!mlist) return;
var file_name = mlist.title.split(";");
var url_title = document.URL.split('#')[1];
var elements = mlist.getElementsByTagName("a");
for(var i=0; i<elements.length; i++ ) {
var item = elements.item(i);
if ((item.title == "DL") || (item.title == wgPageName) || (item.title == "")) {
var title = item.innerHTML;
var frompage = undefined;
var topage = undefined;
var fromsection = title;
var tosection = title;
var file_name_idx = 1;
var dl_ref = item.href.replace(/\.3D/g,'=').split('#')[1];
var params = dl_ref.split(":");
for(var j=0; j<params.length; j++){
var param = params[j].split("=");
switch (param[0]) {
case 'tom':
file_name_idx = ( param[1] != undefined ? parseInt(param[1]) : 1 );
break;
case 'nosection':
fromsection = undefined;
tosection = undefined;
break;
case 'section':
fromsection = ( param[1] != undefined ? param[1] : undefined );
tosection = ( param[1] != undefined ? param[1] : undefined );
break;
case 'frompage':
frompage = ( param[1] != undefined ? param[1] : undefined );
break;
case 'topage':
topage = ( param[1] != undefined ? param[1] : undefined );
break;
case 'fromsection':
fromsection = ( param[1] != undefined ? param[1] : undefined );
break;
case 'tosection':
tosection = ( param[1] != undefined ? param[1] : undefined );
break;
default:
switch (j) {
case 0:
frompage = parseInt(param[0]);
break;
case 1:
topage = parseInt(param[0]);
break;
} // switch (j)
break;
} // switch param[0]
} // for j
item.href = "javascript:show_dict_entry2(\""+file_name[file_name_idx-1]+"\","+frompage+","+topage+",\""+fromsection+"\",\""+tosection+"\");";
item.title = title;
if(url_title == escape(encodeURI( title.replace(/ /g,'_')).replace(/%/g,'.') ).replace(/%/g,'.')) show_dict_entry2(file_name[file_name_idx-1],frompage,topage,fromsection,tosection);
}
}
}
$(dl_links2);