Szerkesztő:Opa/monobook.js

A Wikipédiából, a szabad enciklopédiából

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
//navigáció menü
$(function() {addPortletLink('p-navigation', 'http://hu.wikipedia.org/wiki/User:Opa/Sz%C3%B3cikkek', 'Szócikkeim', 'n-szocikkeim')});

//figyelőlista tuning
document.write('<script type="text/javascript" src="' 
      + 'http://hu.wikipedia.org/w/index.php?title=User:Opa/watchlist.js' 
      + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// oldschool szerk linkek - thx to Tgr
var oldEditsectionLinks = true;

// cikkértékelés-gomb; köszönet: Tgr
function assess(templateName) {  
  var quality = prompt('Minőség:');
  if(quality == null) return false;
  var importance = prompt('Fontosság:');
  if(importance == null) return false;

  var today = new Date();
  var dateString = 
    today.getFullYear() + "-" + 
    (today.getMonth() + 1) + "-" +
    today.getDate();
  var template = 
    "{{" + templateName + 
    "|besorolás=" + quality + 
    "|fontosság=" + importance + 
    "|felhasználó=" + wgUserName + 
    "|dátum=" + dateString + 
    "}}";

  var textarea = document.editform.wpTextbox1;
  textarea.value = textarea.value.replace("{{WPZENE|besorolás=|fontosság=|szerkesztő=|dátum=}}", template);

  var summary = document.editform.wpSummary;
  summary.value = "cikk értékelése";

  return false;
}

function addAssessButton(templateName, image, tip) {
  // FIXME néha eltünteti a többi gombot (wikEd miatt?)
  var toolbar = document.getElementById('toolbar');
  if (!toolbar) { return false; }

  mwInsertEditButton(toolbar, {
    "imageId": "editbutton-assess-" + templateName,
    "imageFile": image,
    "speedTip": tip,
    "tagOpen": "",
    "tagClose": "",
    "sampleText": ""
  });
  var button = document.getElementById("editbutton-assess-" + templateName);
  button.onclick = function() {assess(templateName);};
}

$(function() {
  addAssessButton("WPZENE", "http://upload.wikimedia.org/wikipedia/commons/5/5b/Button_check.png", "Cikkértékelés");
}); //cikkértékelés-end


// edit section 0 (text until the first section title)
function addEditSection0(){
    if(!document.getElementById) return;
    var edit = document.getElementById('ca-edit');
    if(!edit) return;
    var link = ((edit.children) ? edit.children : edit.childNodes)[0].href + '&section=0';
    var edit0 = mw.util.addPortletLink('p-cactions', link, '0', 'ca-edit-0', 
                               'Bevezető szerkesztése', '0', edit.nextSibling);
    if(/selected/.test(edit.className) && /section=0$/.test(window.location.href)) 
        edit0.className = 'selected';
    if(/istalk/.test(edit.className)) 
        edit0.className += (edit0.className.length ? ' istalk' : 'istalk');
}
$(addEditSection0);


//laptörténet-karakterszámláló
if(document.location.href.indexOf("action=history") != -1) {
$(function() {
   spanList = document.getElementsByTagName("span");
   var sizeList = new Array();
   for(var i=0; i<spanList.length; i++) {
      if(spanList[i].className=="history-size")
         sizeList.push(spanList[i]);
   }
   for(i=0; i<sizeList.length-1; i++) {
      var diff = parseInt(sizeList[i].innerHTML.slice(1,-6).replace("&nbsp;", "")) - parseInt(sizeList[i+1].innerHTML.slice(1,-6).replace("&nbsp;", ""));
      var changeString;
      if(diff > 0)
         changeString = ' <span class="mw-plusminus-pos">(+' + diff + ')</span>';
      else if(diff == 0)
         changeString = ' <span class="mw-plusminus-null">(0)</span>';
      else if(diff < -500)
         changeString = ' <strong class="mw-plusminus-neg">(' + diff + ')</strong>';
      else 
         changeString = ' <span class="mw-plusminus-neg">(' + diff + ')</span>';
      sizeList[i].innerHTML = changeString;
   }
})}


// -*- mode:java; coding:utf-8 -*-
//  Generates the box element containing the spec chars.
function createCustomBar() {
  var boxDiv = document.createElement('div');
  boxDiv.setAttribute('id', 'customBar');
  boxDiv.setAttribute('style', 'margin-bottom:2px;border:1px solid #aaaaaa;padding:3px');
  boxDiv.innerHTML =
    "<a href=\"javascript:insertTags('%7B%7Bsubst:anonüdv','%7D%7D','')\"><b>anonüdv</b></a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bsubst:üdvözlet|– ~~\~~','%7D%7D','')\"><b>üdv</b></a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bátdolgozni%7D%7D','','')\">átdolgozni</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bnincs bevezető%7D%7D','','')\">nincs bevezető</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bnincs szöveg%7D%7D','','')\">nincs szöveg</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bszubcsonk|~~\~~\~%7D%7D','','')\">szubcsonk</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bazonnali|1=' + prompt() + ' -~\~\~\~%7D%7D','','')\">azonnali</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bjogsértő|url=','%7D%7D','')\">jogsértő</a> · " +
    "<a href=\"javascript:customReplaceForm()\">regexp csere</a> <br>" +
    "<a href=\"javascript:insertTags('%7B%7Bsubst:netörölj','%7D%7D – ~~\~~','')\">ne törölj</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bsubst:teszt','%7D%7D – ~~\~~','')\">véletlen teszt</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bsubst:teszt2','%7D%7D – ~~\~~','')\">értelmetlen tartalom</a> · " + 
    "<a href=\"javascript:insertTags('%7B%7Bsubst:teszt4rögtön','%7D%7D – ~~\~~','')\">ártó szándék, azonnal hagyd abba!</a> · " + 
    "<a href=\"javascript:insertTags('%7B%7Bsubst:teszt4','%7D%7D – ~~\~~','')\">utolsó figy</a> · " +
    "<a href=\"javascript:insertTags('%7B%7Bsubst:blokkolva|' + prompt() + ' időtartamra','%7D%7D','')\">blokkolva</a>";
  return boxDiv;
}

function replaceRegexp(replaceWhat, replaceWith, modifiers) {
  if (modifiers == null) {
    modifiers = "";
  }
  var txtarea = document.editform.wpTextbox1;
  // IE
  if(document.selection  && !is_gecko) {
    var theSelection = document.selection.createRange().text;           
    txtarea.focus();
    theSelection = theSelection.replace(replaceWhat, replaceWith);
    document.selection.createRange().text = theSelection;
    // Mozilla
  } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
    // This is probably more complicated than it needs to be
    var startPos = txtarea.selectionStart;
    var endPos = txtarea.selectionEnd;
    var scrollTop=txtarea.scrollTop;

    var pattern = new RegExp(replaceWhat, modifiers);
    var myText = (txtarea.value).replace(pattern, replaceWith);

    txtarea.value = myText;             

    txtarea.focus();

    var cPos=startPos;
    txtarea.selectionStart=cPos;
    txtarea.selectionEnd=cPos;
    txtarea.scrollTop=scrollTop;

    // All others
  } else {
    alert("No support for this browser yet");
    return;
  }
  // reposition cursor if possible
  if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}

// Replace all occurences of a user-entered regexp with a user entered replacement
function customReplaceForm() {
  var form =
    'Cseréld ezt a reguláris kifejezést: <input id="customReplaceThis" type="text" size="30"> ' +
    'erre: <input id="customReplaceWith" type="text" size="30"> ' +
    '<input id="customReplaceCS" type="checkbox"> méretérzékeny <b>::</b> ' +
    '<a href="javascript:performCustomReplace()">csere</a>';
  insertCustomForm(form);
  document.getElementById('customReplaceThis').focus();
}

function performCustomReplace() {
  var replaceThis = document.getElementById('customReplaceThis');
  var replaceWith = document.getElementById('customReplaceWith');
  var cs = document.getElementById('customReplaceCS');
  var flags = "gm";
  if (!cs.checked) {
    flags += "i";
  }
  replaceRegexp(replaceThis.value, replaceWith.value, flags);
}

function insertCustomForm(formText) {
  var customBar = document.getElementById('customBar');
  if (customBar == null) return;

  var customForm = document.createElement('div');
  customForm.setAttribute('id', 'customForm');
  customForm.setAttribute('style', 'margin-bottom:2px;border:1px solid #aaaaaa;padding:3px');
  customForm.innerHTML = 
    '<img id="customFormClose" src="http://upload.wikimedia.org/wikipedia/hu/b/bd/Close.png" ' +
    'align="right" style="margin:2px" onClick="deleteCustomForm()" ' +
    'onmouseover="document.images.namedItem(\'customFormClose\').src=\'http://upload.wikimedia.org/wikipedia/hu/c/cf/Close-hl.png\'" ' +
    'onmouseout="document.images.namedItem(\'customFormClose\').src=\'http://upload.wikimedia.org/wikipedia/hu/b/bd/Close.png\'"' +
    'onmousedown="document.images.namedItem(\'customFormClose\').src=\'http://upload.wikimedia.org/wikipedia/hu/e/eb/Close-dn.png\'">' +
    formText;
  
  var oldForm = document.getElementById('customForm');
  if (oldForm != null) {
    customBar.parentNode.replaceChild(customForm, oldForm);
  } else {
    customBar.parentNode.insertBefore(customForm, customBar);
  }
}

function deleteCustomForm() {
  var customForm = document.getElementById('customForm');
  if (customForm != null)
    customForm.parentNode.removeChild(customForm);
}

// Initializes edit box
function myOnloadHook() {
  // Textarea positioning doesn't work in Opera
  if (is_opera) return;

  // Find the element that comes right after the special character box
  var textArea = document.getElementsByName('wpTextbox1');
  if (textArea.item(0) != null) {
    var insertPos = textArea.item(0).nextSibling.nextSibling; // this is a <br/>
    var customBar = createCustomBar();
    insertPos.parentNode.replaceChild(customBar, insertPos);

    // Remove global spec char bar
//    var specChars = document.getElementById('specChar');
//    if (specChars != null) {
//      specChars.parentNode.removeChild(specChars);
//    }
  }
}

if (window.addEventListener != null)
  window.addEventListener("load", myOnloadHook, false);
else if (window.attachEvent)
  window.attachEvent("onload", myOnloadHook);