User:Serpicozaure/monobook.js
Jump to navigation
Jump to search
Note – after saving, you may have to bypass your browser’s cache to see the changes.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
This JavaScript is executed for Serpicozaure on every page load, when User:Serpicozaure is using the Monobook skin.
/**
Adds a feedback to to the bottom of the page on the left. This has only been tested with Monobook as it is intended for IPs only.
**/
var fb_comment_url = wgScript+
"?title=Wiktionary:Feedback"+
"&action=edit§ion=new"+
"&preload=Wiktionary:Feedback%2Fpreload"+
"&editintro=Wiktionary:Feedback%2Fintro"+
"&preloadtitle="+
encodeURIComponent("[[:"+wgPageName.replace(/_/g, ' ')+"]]");
var fb_thanks = "Thank you for giving us some of your time.";
var fb_comment = "If you have time, leave us a note.";
var fb_questions = new Array();
fb_questions[0] =
["Submit anonymous feedback about Wiktionary:",
['Good',
'Bad',
'Messy',
'Mistake in definition',
'Confusing',
'Could not find the word I want',
'Incomplete',
'Entry has inaccurate information',
'Definition is too complicated']
];
var fb_options;
var fb_text;
var fb_sent = false;
var fb_sent2= false;
function fb_init(){
var index = Math.floor(Math.random()*(fb_questions.length));
fb_text = fb_questions[index][0];
fb_options = fb_questions[index][1];
fb_buildBox();
}
function fb_buildBox(){
var sidebar = document.getElementById('column-one');
if(!sidebar) return false;
var list = newNode('ul',{'id':'fb_list'});
for(var i=0;i<fb_options.length;i++){
list.appendChild(
newNode('li',
newNode('a',{'click':fb_click,'id':"FB"+i},fb_options[i])
)
);
}
sidebar.appendChild(
newNode('div',{'class':"portlet",'id':"p-feedback"},
newNode('a',{'name':"feedback"}),
newNode('h5',"feedback"),
newNode('div',{'class':"pBody"},
newNode('p',{'style':'font-size: 90%'},fb_text),
list,
newNode('p',{'style':'font-size: 80%'},
newNode('a',{'href':fb_comment_url},fb_comment)
)
)
)
);
}
$(fb_init);
function fb_click(e){
var fb = false;
var fbi = false;
try{
fb = e.target.childNodes[0].nodeValue;
fbi = e.target.getAttribute('id').replace("FB",'');
}catch(e){ try{
fb = window.event.srcElement.childNodes[0].nodeValue;
fbi = window.event.srcElement.getAttribute('id').replace("FB",'');
} catch(e){ }}
if(fb){
fb_send(fb);
fb_send2(fb,fbi);
}
var list = document.getElementById('fb_list');
list.parentNode.insertBefore(
newNode('p',fb_thanks),list
);
list.parentNode.removeChild(list);
return false;
}
//Send to ~cmackenzie
function fb_send(string){
if(fb_sent) return false;
fb_sent=true;
var wiki = wgServer.replace(/https?:\/\/([^\.]*)\.([^\.]*)\.org/,"$1$2").replace(/pedia$/,'');
var page = wgPageName;
if(wgPageName == 'Special:Search'){
var sb = document.getElementById('lsearchbox');
if(sb) page+='/'+sb.value;
}
var url = "http://tools.wikimedia.de/~cmackenzie/feedback.php"+
"?fb_wiki="+wiki+
"&fb_page="+encodeURI(page)+
"&fb_revid="+encodeURI(wgCurRevisionId)+
"&fb_comment="+encodeURI(string);
document.body.appendChild(
newNode('iframe',{'src':url,'style':'display:none'})
);
}
//Send to ~daveross
function fb_send2(string,indx){
if(fb_sent2) return false;
fb_sent2 =true;
var lang = wgServer.replace(/^https?:\/\/([^\.]*).*$/,"$1");
var wiki = wgServer.replace(/https?:\/\/[^\.]*\.([^\.]*)\.org/,"$1");
var page = wgPageName;
if(wgPageName == 'Special:Search'){
var sb = document.getElementById('lsearchbox');
if(sb) page+='/'+sb.value;
}
var url = 'http://tools.wikimedia.de/~daveross/feedback.php'
+ '?mode=submit'
+ '&lang='+encodeURI(lang)
+ '&wiki='+encodeURI(wiki)
+ '&page='+encodeURI(page)
+ '&revid='+encodeURI(wgCurRevisionId)
+ '&comment='+encodeURI(string)
+ '&comment_index='+encodeURI(indx*1+1);
document.body.appendChild(
newNode('iframe',{'src':url,'style':'display:none'})
);
}
/* DOM abbreviation function */
function newNode(tagname){
var node = document.createElement(tagname);
for( var i=1;i<arguments.length;i++ ){
if(typeof arguments[i] == 'string'){ //Text
node.appendChild( document.createTextNode(arguments[i]) );
}else if(typeof arguments[i] == 'object'){
if(arguments[i].nodeName){ //If it is a DOM Node
node.appendChild(arguments[i]);
}else{ //Attributes (hopefully)
for(var j in arguments[i]){
if(j == 'class'){ //Classname different because...
node.className = arguments[i][j];
}else if(j == 'style'){ //Style is special
node.style.cssText = arguments[i][j];
}else if(typeof arguments[i][j] == 'function'){ //Basic event handlers
try{ node.addEventListener(j,arguments[i][j],false); //W3C
}catch(e){try{ node.attachEvent('on'+j,arguments[i][j],"Language"); //MSIE
}catch(e){ node['on'+j]=arguments[i][j]; }}; //Legacy
}else{
node.setAttribute(j,arguments[i][j]); //Normal attributes
}
}
}
}
}
return node;
}