User:Wolfman~enwikisource/monobook.js

// /*********** 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'); // 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. /************* CODE ************/ var url; var edit_url; var welcomer=null; var special; var hit=false;

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 {                                           // what to do? url = location.href; if (in_url('&tag=true')) { tag_handler; return; } var add = new adder; if (in_url('&action=edit') && special_tab) {               // show-hide specials edit_url = 'javascript:special.toggle'; special = new special_toggler( add.link('','a-special') ); } // auto-welcomer if (in_url('Special:Log') && in_url('newusers') && welcome_all==true) { edit_url=url + '?&tag=true&';                          // '?' is a kludge add.link('auto=Welcome:Welcome everybody'); } edit_url = url; var die = false; if (in_url('&action=edit')) { if (!copywarn) { var warn=document.getElementById('editpage-copywarn').getElementsByTagName('p'); warn[warn.length-1].style.display = 'none'; } } else { var tmp=document.getElementById('ca-edit'); if (tmp) {edit_url = getElementsByTagName('a')[0].href; } else {die=true;} } edit_url += '&tag=true&'; // ignore these pages for (var i=0; i < exclude.length; i++) { if (in_url(exclude[i])) {die=true;} } if (die && !hit && placement=='topleft') {                  // kill the javascript bar document.getElementById('p-javascript').style.display = 'none'; } if (die) {return;} 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 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 ( '', '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 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; } // >