User:Wolfbot/monobook.js
Appearance
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
For details and instructions about other browsers, see Wikipedia:Bypass your cache.
Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the central discussion page, Scriptorium. The code will be executed when previewing this page under some skins, including Monobook. You can in the interim if you wish to refresh the content sooner under another skin. |
The accompanying .css page for this skin can be added at User:Wolfbot/monobook.css. |
//<pre>
/*********** CONFIGURATION ************/
// by editing this section, you can automate some basic tasks
// the naming format is: 'name-of-template:name-on-tab'
// the ':name-on-tab' part is optional
// templates for user talk pages
var templates1 = new Array('Welcome','Test:Vandal');
// templates for the bottom of texts
var templates2 = new Array('PD-old:PD old');
// templates for the top of texts
var templates3 = new Array('Cleanup');
// categories
var categories = new Array('Non-English','Texts to be split');
// reports, such as deletion requests
var reports = new Array();
reports['delete:Delete'] =['Proposed deletions'];
reports['copyvio:Copyright']=['Possible copyright violations'];
// welcome everyone at the newuser log with one click
var welcome_all = true;
// where to put the tabs to click
var placement='topleft'; // 'tab_bar', 'toolbox', or 'topleft' (above 'navigation')
var jump_back = 2; // after edit, jump back this many pages in browser history
// no standard tabs on pages whose url's include one of the following
var exclude = new Array('&action=history','&diff=','Wikisource:','Talk:','User:','Special','Category:');
// hide & unhide the "insert special character" map on the edit page
var special_tab = true;
var show_special='Insert special';
var hide_special='Hide special';
var copywarn = false; // hide the copyright warning, to make more space.
var allow_category_removal = true; // allows one to remove a category from all articles
var cat_kill_tag = 'Remove this category';
var confirm_msg = 'Click to confirm';
/************* CODE ************/
var url;
var edit_url;
var welcomer;
var cat_killer;
var special;
var hit=false;
var add;
if (window.addEventListener) { // when the page loads, run this script
window.addEventListener('load', hooks, false); }
else if (window.attachEvent) {
window.attachEvent('onload', hooks); }
function in_url(string) { return (url.search(string) != -1); }
function hooks() {
url = location.href;
if (in_url('&tag=true')) { tag_handler(); return; }
add = new adder();
var done = false;
if (in_url('&action=edit')) {edit_tabs();}
if (in_url('&welcome_all==true')) {autowelcome_tab();}
if (in_url('Category:')) { cat_kill_tab(); }
edit_url = url; // global, don't move
var tmp = document.getElementById('ca-edit');
if (tmp) {edit_url = document.getElementsByTagName('a')[0].href; } else {done=true;}
edit_url += '&tag=true&';
for (var i=0; i < exclude.length; i++) { if (in_url(exclude[i])) {done=true;} }
if (done && !hit && placement=='topleft') { // kill the bar
document.getElementById('p-javascript').style.display = 'none'; }
if (!done) {standard_tabs();}
}
function cat_kill_tab () {
edit_url = 'javascript:cat_kill_tab_confirm()';
var tag_id = add.link('','a-catkill');
document.getElementById('a-catkill').innerHTML=cat_kill_tag;
}
function cat_kill_tab_confirm {
var cat = url.replace(/^.*Category:/,'');
na = document.getElementById('a-catkill');
na.innerHTML = confirm_msg;
na.style.border = 'groove red';
nscript = 'cat_killer = new Cat_killer(' + cat + ');'
nscript +=
na.href = 'javascript:cat_killer = new Cat_killer();
function autowelcome_tab() {
if (!in_url('Special:Log') || !in_url('newusers')) {return;}
edit_url = url + '?&tag=true&'; // '?' is a kludge
add.link('&auto=Welcome:Welcome everybody');
}
function edit_tabs () {
if (special_tab) { // show-hide specials
edit_url = 'javascript:special.toggle()';
var tag_id = add.link('','a-special')
special = new special_toggler( tag_id ); }
edit_url = url;
if (copywarn) { return; } // below we hids copyright boilerplate
var warn=document.getElementById('editpage-copywarn').getElementsByTagName('p');
warn[warn.length-1].style.display = 'none';
}
function standard_tabs() {
if (in_url('User_talk:')) { // ask for tablinks
for (i=0; i < templates1.length; i++) { add.link('template1='+templates1[i]); }
return; }
for (i=0; i < templates2.length; i++) { add.link('template2='+templates2[i]); }
for (i=0; i < templates3.length; i++) { add.link('template3='+templates3[i]); }
for (i=0; i < categories.length; i++) { add.link('category=' +categories[i]); }
for (key in reports) { add.link('report=' +key); }
}
// create a tab box
function create_topleft() {
var spot = document.getElementById('p-navigation');
var div1=document.createElement('div'); div1.className='portlet'; div1.id='p-javascript';
var h5_1=document.createElement('h5'); h5_1.innerHTML='Javascript';
var div2=document.createElement('div'); div2.className='pBody';
var ul_1=document.createElement('ul'); div2.appendChild(ul_1);
div1.appendChild(h5_1);
div1.appendChild(div2);
document.getElementById('column-one').insertBefore(div1,spot);
}
// allocate links for tabs
function adder() { // allocate tabs
var place;
if (placement == 'tab_bar') { place='p-cactions'; }
if (placement == 'toolbox') { place='p-tb'; }
if (placement == 'topleft') { place='p-javascript'; create_topleft();}
place = document.getElementById(place);
var list = place.getElementsByTagName('ul')[0];
this.link = function(tag,tag_id) {
hit = true;
var na = document.createElement('a');
if (tag_id) na.id = tag_id;
na.href= edit_url + tag;
var name = tag.replace(/(.*=)(.*:)?/,'');
na.appendChild( document.createTextNode(name) );
var li = document.createElement('li');
li.appendChild(na);
list.appendChild(li);
}
}
function get_tag (type) { // which tab got pressed?
var is_type=url.search(type);
if (is_type != -1) {
tag = url.substring(is_type + type.length + 1);
return( tag.replace(/:.*/,'') ); }
return false;
}
function tag_handler() { // call for an action based on the tag
var t1 = '}}'; var t0 = '{{';
var c1 = ']]'; var c0 = '[[category:';
var tag;
tag = get_tag('&template1'); if (tag) {add_tag(t0+tag+t1,'bot'); return;}
tag = get_tag('&template2'); if (tag) {add_tag(t0+tag+t1,'top'); return;}
tag = get_tag('&template3'); if (tag) {add_tag(t0+tag+t1,'bot'); return;}
tag = get_tag('&category' ); if (tag) {add_tag(c0+tag+t1,'bot'); return;}
tag = get_tag('&report'); if (tag) {report_page(tag); return;}
for (key in reports) { if (get_tag(key)) {rep_tag(key); return;} }
if (get_tag('&auto')) {welcomer = new Welcomer(); welcomer.next();}
}
function back() {
if (in_url('&child=true')) {opener.welcomer.next(); return;}
window.history.go(-jumpback);
}
function add_tag(tag,pos) { // add categories and templates
var form=document.editform;
var box=form.wpTextbox1;
if (pos == 'bot') {box.value += '\n' + tag;}
if (pos == 'top') {box.value = tag + '\n' + box.value;}
form.wpSummary.value = tag;
window.onunload=back;
form.submit();
}
function del_tag(tag) { // remove categories
var form=document.editform;
var text=form.wpTextbox1.value;
text = text.replace(/tag/,'');
form.wpSummary.value = 'remove ' + tag;
window.onunload=window.opener.Cat_killer.next();
form.submit();
}
function rep_tag(tag, report) { // handle a reporting request
var report = 'Wikisource:' + reports[tag];
var page=escape(url.substring(url.search('title=')+6,url.search('&action=')));
window.open('/w/index.php?title=' + report + '&action=edit&tag=true&report='+page);
add_tag ( '{{' + tag.replace(/:.*/,'') + '}}', 'top' );
}
function report_page(page) { // pop window for report
var form=document.editform;
var box=form.wpTextbox1
var words=page.split('_');
var link='[[' + words.join(' ') + ']]';
box.value += '==' + page + '==';
form.wpSummary.value = 'report ' + link;
window.onunload=window.close;
}
function Welcomer() {
var users = document.body.getElementsByTagName('ul')[0].getElementsByTagName('li');
var child = window.open();
var i = 0;
this.next = function () {
var flg = 1;
while (flg && i < users.length) {
var talk_url = users[i].getElementsByTagName('a')[1].href;
if (talk_url.search('&action=edit') != -1 && talk_url.search('User_talk:') != -1) {
flg = 0;
child.location.replace(talk_url+'&tag=true&child=true&template1=welcome'); }
i++; }
if (flg) {
this.child.close();
window.location.replace('/wiki/Special:Log/newusers');
return; }
}
}
function Cat_killer() {
var table = document.body.getElementsByTagName('table');
var table = table[table.length-1];
var pages = getElementsByTagName('li');
var child = window.open();
var i = 0;
this.next = function () {
while (i < pages.length) {
var page_url = pages[i].getElementsByTagName('a')[0].href;
child.location.replace(page_url+'&tag=true&category='+XX+'&kill=true'); }
i++; }
child.close();
window.location.replace(url);
}
}
function special_toggler() { // for show/hide special character insert-bar
var mode = true;
var bar = document.getElementById('editpage-specialchars').style;
var tab = document.getElementById('a-special');
var orig = bar.display;
this.toggle = function () {
if (mode) { tab.innerHTML = show_special; bar.display = 'none'; }
else { tab.innerHTML = hide_special; bar.display = orig; }
mode = !mode;
}
this.toggle();
}
//</pre>