Участник:Lockal/prepend.js

Материал из Википедии — свободной энциклопедии
var templs, prompts; // Произвольный массив с шаблонами можно создать в monobook.js

if(templs === null) {
  var templs = ['\{\{db-anon}}', '\{\{db-attack}}', '\{\{db-catempty}}', '\{\{db-empty}}', '\{\{db-foreign}}', '\{\{db-move}}', '\{\{db-nn}}', '\{\{db-nonsense}}', '\{\{db-redirnone}}', '\{\{db-redirflect}}', '\{\{db-redirsense}}', '\{\{db-redirtypo}}', '\{\{db-repost}}', '\{\{db-spam}}', '\{\{db-talk}}', '\{\{db-test}}', '\{\{db-vand}}', '\{\{subst:dd}}'];
}
if(prompts === null) {
  var prompts = ['\{\{db-copyvio|url=', '\{\{duplicate|', '\{\{db-fork|'];
}

function prompter(qwe) {
 var reply = prompt(qwe+'?', '');
 var actoken = (typeof autoClickToken == 'function') ? '&actoken='+autoClickToken() : '';
 document.location.href = mw.config.get('wgServer')+mw.config.get('wgScript')+'?title='+mw.config.get('wgPageName')+'&action=edit&autoedit=s~^~'+qwe+reply+'}}\\n~g;&autoclick=wpSave'+actoken+'&autosummary='+qwe+reply+'}}';
}

function addvariants(){
 style = 'background:#C2F2FF none repeat scroll 0% 0%;border:1px solid #9BD5F5;color:#5B5B5B;cursor:pointer;font-size:80%;line-height:17px;margin:2px;padding:0px 2px;';
 var text = '';
 var j;

 for (j = 0; j < templs.length; j++) {
  var actoken = (typeof autoClickToken == 'function') ? '&actoken='+autoClickToken() : '';
  text+='<a href="'+mw.config.get('wgServer')+mw.config.get('wgScript')+'?title='+mw.config.get('wgPageName')+'&action=edit&autoedit=s~^~'+templs[j]+'\\n~g;&autoclick=wpSave'+actoken+'&autosummary='+templs[j]+'" style="'+style+'">'+templs[j]+'</a>';
 }
 text+='<br />';
 for (j = 0; j < prompts.length; j++) {
  text+='<input type="button" onclick="prompter(\''+prompts[j]+'\')" value="'+prompts[j]+'">';
 }

 jsMsg(text, 'prepend');
}

$(function(){
 if (mw.config.get('wgNamespaceNumber') >= 0){
  addPortletLink ('p-cactions', '#', 'в начало…', 'prepend');
  document.getElementById('prepend').setAttribute('onclick', 'addvariants()');
 }
});