משתמשת:נעה/monobook.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* A helper function to add a button to one of the toolbars in the interface.  

Took it from [[:en:User:Omegatron/monobook.js/addlink.js]] */

function addLink(where, url, name, id, title, key, after){
    //* where is the id of the toolbar where the button should be added;
    //   i.e. one of "p-cactions", "p-personal", or "p-navigation".
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //* name is what will appear as the name of the button.
    //* id is the id of the button; it's best to define one.  
    //   Use a prefix to make sure its unique. Optional.
    //* title is the tooltip title that gives a longer description 
    //   of the button; if you define a accesskey, mention it here. Optional.
    //* key is the char you want for the accesskey. Optional.
    //* after is the id of the button you want to follow this one. Optional.
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
	tabs.insertBefore(li,document.getElementById(after));
    } else {
	tabs.appendChild(li);
    }
    if(id) {
	if(key && title) { ta[id] = [key, title]; }
	else if(key) { ta[id] = [key, '']; }
	else if(title) { ta[id] = ['', title];} 
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}


// From [[en:User:Lupin/autoedit.js]]
function getParamValue(paramName) {
 var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
 var h=document.location;
 var m=cmdRe.exec(h);
 if (m) {
   try {
     return decodeURIComponent(m[1]);
   } catch (someError) {}
 }
 return null;
}

// From [[en:User:Lupin/autoedit.js]], translated by [[user:ערן]], edited by [[User:Yonidebest]]

// String constants
ns_text = "חסר מקור";
ns_tooltip = "סמן תמונה זו כחסרה מקור";
nl_text = "חסר רישיון";
nl_tooltip = "סמן תמונה זו כחסרה פרטי רישיון";
nsl_text = "חסר מקור ורישיון";
nsl_tooltip = "סמן תמונה זו כחסרה מקור ופרטי רישיון";
c_text = "ויקישיתוף";
c_tooltip = "הודע למשתמש על ויקישיתוף";
p_text = "שימוש אישי";
p_tooltip = "סמן תמונה זו כשימוש אישי";
v_text = "אומת";
v_tooltip = "סמן תמונה זו כמאומתת";

// Site info
scriptPath = "/w/index.php";
prettyPath = "/wiki/";
wikiHostname = "he.wikipedia.org";

function openWindow(url) {
  var res = window.open(url, '_blank');
  if (!res) alert("openWindow: window.open() returned null");
}

function getUploader() {
  // Get uploader from first point in the list under "File history"
  // Uploader is stored in second A tag in UL tag under "File history"
  // Returns title of user page (without name space) in URL form
  var el = document.getElementById('filehistory')
  if (!el) {
    alert("תקלה: לא נמצאה היסטורית העלאה ... משימה נכשלה");
    return null;
  }
  while (el.nextSibling) {
    el = el.nextSibling;
    if (el.tagName && el.tagName.toLowerCase() == 'ul') 
      break;
  }
  if (!el) {
    alert("תקלה: לא הצלחתי למצוא רשימת מעלים ... נטשתי אותך, ביי!");
    return null;
  }
  var el = el.getElementsByTagName('li')[0];
  if (!el) {
    alert("לא הצלחתי למצוא את הפריט הדרוש לי ברשימה ... הפסקתי את המשימה");
    return null;
  }
  var as = el.getElementsByTagName('a');

  var re1 = new RegExp('http://' + (wikiHostname + prettyPath).replace(/\./g, '\\.') + '%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:(.*)$');
  var re2 = new RegExp('http://' + (wikiHostname + scriptPath).replace(/\./g, '\\.') + '\\?title=%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:([^&]*)');
  var m;
  for (var k=0; k<as.length; k++) {
     m = re1.exec(as[k].href);
     if (m) return m[1];
     m = re2.exec(as[k].href);
     if (m) return m[1];
  }
  alert("תקלה: לא נמצא מעלה ... משימה נכשלה");
  return null;
}

// Function that help idenfity what action must be taken
function mnx_mark(imagepage_fakeaction, usertalk_fakeaction) {

  if (imagepage_fakeaction != 'v_temp' && imagepage_fakeaction != 'p_temp') {
    var pagename = encodeURIComponent(mw.config.get('wgPageName'));
    var uploader = getUploader();
 
    if (!uploader) return;
    // Open new window for the user page
    openWindow(scriptPath + '?title=User_talk:' + uploader + '&action=edit&fakeaction=' + usertalk_fakeaction + '&target=' + pagename + '&template_type=' + imagepage_fakeaction);
  }
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk + '&fakeaction=' + imagepage_fakeaction;
}

// Add template to image description page
function mnx_addTemplate(template) {
  var comment = "תמונה חשודה";
  if (template == 'ns_temp') template = 'ס:תמונה חשודה|סיבה=חסר מקור'; //no source
  if (template == 'nl_temp') template = 'ס:תמונה חשודה|סיבה=חסר רישיון'; //no license
  if (template == 'nsl_temp') template = 'ס:תמונה חשודה|סיבה=חסר מקור ורישיון'; //no source and license
  if (template == 'c_temp') { //commons
    template = 'העברה לוויקישיתוף';
    comment = 'העברה לוויקישיתוף';
  }
  if (template == 'v_temp') { //verified
    template = 'אומת';
    comment = 'אומת';
  }
  if (template == 'p_temp') { //private
    template = 'תמונה לשימוש אישי}}{{אומת';
    comment = 'שימוש אישי';
  }
  var txt = '{{' + template + '}}';
  document.editform.wpTextbox1.value += '\n' + txt;
  document.editform.wpSummary.value = comment;
  document.editform.wpSave.click();
}

// Add warning template to uploader's talk page
function mnx_addUserWarningTemplate(imagetarget, template_type) {
  var imageName = imagetarget.substring(6,imagetarget.length);
  var txt = '==[[:תמונה:' + imageName + '|' + imageName + ']]==\n';
  var comment = '';
  if (template_type == 'ns_temp') { // source
     txt += 'במסגרת הטיפול בתמונות בעייתיות ב[[וק:מה|מיזם התמונות]], שמתי לב כי העלית את התמונה הנ"ל שלא בהתאם להנחיות הברורות המופיעות ב[[מיוחד:Upload|דף העלאת קובץ לשרת]] ובדפי העזרה בנושא תמונות. אנא פעל על פי ה\'\'\'[[משתמש:Yonidebest/מקור|הנחיות בדף זה]]\'\'\', אחרת התמונה עלולה להימחק בשבוע הקרוב. בהמשך לשיחה זו אני לרשותך לשם מתן מידע ועזרה. לחלופין, ניתן ואף רצוי לפנות ל[[ויקיפדיה:דלפק ייעוץ|דלפק הייעוץ]] שכן שם יש סיכוי טוב יותר לקבל תשובה מהירה יותר. ';
     comment = 'חסר מקור';
  }
  if (template_type == 'nl_temp') { // license
     txt += 'במסגרת הטיפול בתמונות בעייתיות ב[[וק:מה|מיזם התמונות]], שמתי לב כי העלית את התמונה הנ"ל שלא בהתאם להנחיות הברורות המופיעות ב[[מיוחד:Upload|דף העלאת קובץ לשרת]] ובדפי העזרה בנושא תמונות. אנא פעל על פי ה\'\'\'[[משתמש:Yonidebest/רישיון|הנחיות בדף זה]]\'\'\', אחרת התמונה עלולה להימחק בשבוע הקרוב. בהמשך לשיחה זו אני לרשותך לשם מתן מידע ועזרה. לחלופין, ניתן ואף רצוי לפנות ל[[ויקיפדיה:דלפק ייעוץ|דלפק הייעוץ]] שכן שם יש סיכוי טוב יותר לקבל תשובה מהירה יותר. ';
     comment = 'חסר רישיון';
  }
  if (template_type == 'nsl_temp') { // source and license
     txt += 'במסגרת הטיפול בתמונות בעייתיות ב[[וק:מה|מיזם התמונות]], שמתי לב כי העלית את התמונה הנ"ל שלא בהתאם להנחיות הברורות המופיעות ב[[מיוחד:Upload|דף העלאת קובץ לשרת]] ובדפי העזרה בנושא תמונות. אנא פעל על פי ה\'\'\'[[משתמש:Yonidebest/מקור ורישיון|הנחיות בדף זה]]\'\'\', אחרת התמונה עלולה להימחק בשבוע הקרוב. בהמשך לשיחה זו אני לרשותך לשם מתן מידע ועזרה. לחלופין, ניתן ואף רצוי לפנות ל[[ויקיפדיה:דלפק ייעוץ|דלפק הייעוץ]] שכן שם יש סיכוי טוב יותר לקבל תשובה מהירה יותר. ';
     comment = 'חסר מקור ורישיון';
  }
  if (template_type == 'c_temp') { // commons
     txt += 'במסגרת הטיפול בתמונות חופשיות ב[[וק:מה|מיזם התמונות]], ברצוני להזכיר לך כי תמונות חופשיות יש להעלות ל[[ויקישיתוף|וויקישיתוף]]. תודה, ';
     comment = 'ויקישיתוף';
  }
  document.editform.wpTextbox1.value += '\n' + txt + '~~' + '~~\n';
  document.editform.wpSummary.value = comment;
  document.editform.wpSave.click();
}

function mnx_onload() {
  if (wgNamespaceNumber == 6) { // image name space
    addLink('p-tb', 'javascript:mnx_mark(\'ns_temp\', \'warn\')', ns_text, 'mark-no-source', ns_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'nl_temp\', \'warn\')', nl_text, 'mark-no-license', nl_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'nsl_temp\', \'warn\')', nsl_text, 'mark-no-license-source', nsl_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'c_temp\', \'warn\')', c_text, 'mark-commons', c_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'v_temp\', \'no_warn\')', v_text, 'mark-verified', v_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'p_temp\', \'no_warn\')', p_text, 'mark-private', p_tooltip, null, null);
  }
  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type');   // Fetch what template to add

  if (fakeaction == 'ns_temp'){ // מקור
    mnx_addTemplate('ns_temp');
  }
  if (fakeaction == 'nsl_temp'){ // מקור ורישיון
    mnx_addTemplate('nsl_temp');
  }
  if (fakeaction == 'nl_temp'){ // רישיון
    mnx_addTemplate('nl_temp');
  }
  if (fakeaction == 'v_temp'){ // אומת
    mnx_addTemplate('v_temp');
  }
  if (fakeaction == 'p_temp'){ // שימוש אישי
    mnx_addTemplate('p_temp');
  }
  if (fakeaction == 'c_temp'){ // ויקישיתוף
    mnx_addTemplate('c_temp');
  }
  if (fakeaction == 'warn') {
   mnx_addUserWarningTemplate(decodeURIComponent(getParamValue('target')), template_type);
  }
}

$(mnx_onload);

/* Add links to diff pages */
/* Created by [[User:Yonidebest]]; */

// String constants
wrn_text = "אזהרה";
wrn_tooltip = "הוסף תבנית אזהרה";
try_text = "ניסויים";
try_tooltip = "הוסף תבנית ניסויים";
cpy_text = "העתקה";
cpy_tooltip = "הוסף תבנית העתקה";
del_text = "נמחק";
del_tooltip = "הוסף תבנית נמחק";
tnx_text = "תודה";
tnx_tooltip = "הוסף תבנית תודה";
wel_text = "בה";
wel_tooltip = "הוסף תבנית ברוך הבא";

function openNewWindow(userName, previousTitle, template_name) {
  var url = 'http://he.wikipedia.org/w/index.php?title=' + encodeURIComponent('שיחת_משתמש:') + userName + '&action=edit&template_name=' + template_name + '&title_name=' + previousTitle;
  var win = window.open(url, '_blank');
}
  
// Add template to talk page
function addTemplate(template, title) {
  var txt = '\n==[[:' + decodeURIComponent(title).replace(/_/g, ' ') + ']]==\n';
  var comment = '';
  if (template == 'wrn') { // אזהרה
    template = 'אזהרה';
    comment = 'אזהרה';
  }
  if (template == 'try') { // ניסויים
    template = 'ניסויים';
    comment = 'ניסויים';
  }
  if (template == 'tnx') { // תודה
    template = 'תודה';
    comment = 'תודה';
  }
  if (template == 'cpy') { // העתקה
    template = 'העתקה';
    comment = 'העתקה';
  }
  if (template == 'del') { // נמחק
    template = 'נמחק';
    comment = 'נמחק';
  }
  if (template == 'wel') { // ברוכים הבאים
    txt = '';
    template = 'ברוך הבא';
    comment = 'ברוך הבא';
  }
  txt += '{{' + template + '}} ';
  document.editform.wpTextbox1.value += txt + '~~' + '~~\n';
  document.editform.wpSummary.value = comment;
  document.editform.wpSave.click();
}

function templateSC_onload() {
  if (document.location.href.indexOf('diff') != -1) {
    var as = document.getElementById('bodyContent').getElementsByTagName('a');
    var titleName = wgPageName;
    var userName;
    var rx = new RegExp('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}');
    for (var i=0; i < as.length; i++) {
      /* עבור משמשים אנונימיים */
       var m = rx.test(as[i].title);
       if (as[i].title.indexOf("מיוחד:Contributions") == 0 && m) {
         userName = encodeURIComponent(as[i].title.substring(as[i].title.lastIndexOf("Contributions") + 14, as[i].title.length));
        /* tnx */
         var txt1 = document.createTextNode(')');
         var txt2 = document.createTextNode(' | ');
         var a_tnx = document.createElement('a');
         a_tnx.href = 'javascript:openNewWindow(\'' + userName + '\', \'' + titleName + '\', \'' + 'tnx' + '\')';
         a_tnx.appendChild(document.createTextNode(tnx_text));
         a_tnx.title = tnx_tooltip;
         as[i].parentNode.insertBefore(txt1, as[i].nextSibling);
         as[i].parentNode.insertBefore(a_tnx, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt2, as[i].nextSibling);
        /* cpy */
         var txt3 = document.createTextNode(' | ');
         var a_cpy = document.createElement('a');
         a_cpy.href = 'javascript:openNewWindow(\'' + userName + '\', \'' + titleName + '\', \'' + 'cpy' + '\')';
         a_cpy.appendChild(document.createTextNode(cpy_text));
         a_cpy.title = cpy_tooltip;
         as[i].parentNode.insertBefore(a_cpy, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt3, as[i].nextSibling);
        /* del */
         var txt4 = document.createTextNode(' | ');
         var a_del = document.createElement('a');
         a_del.href = 'javascript:openNewWindow(\'' + userName + '\', \'' + titleName + '\', \'' + 'del' + '\')';
         a_del.appendChild(document.createTextNode(del_text));
         a_del.title = del_tooltip;
         as[i].parentNode.insertBefore(a_del, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt4, as[i].nextSibling);
        /* try */
         var txt5 = document.createTextNode(' | ');
         var a_try = document.createElement('a');
         a_try.href = 'javascript:openNewWindow(\'' + userName + '\', \'' + titleName + '\', \'' + 'try' + '\')';
         a_try.appendChild(document.createTextNode(try_text));
         a_try.title = try_tooltip;
         as[i].parentNode.insertBefore(a_try, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt5, as[i].nextSibling);
        /* wrn */
         var txt6 = document.createTextNode(' (');
         var a_wrn = document.createElement('a');
         a_wrn.href = 'javascript:openNewWindow(\'' + userName + '\', \'' + titleName + '\', \'' + 'wrn' + '\')';
         a_wrn.appendChild(document.createTextNode(wrn_text));
         a_wrn.title = wrn_tooltip;
         as[i].parentNode.insertBefore(a_wrn, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt6, as[i].nextSibling);
       }  
    }
  }

  if (wgPageName == 'מיוחד:Recentchanges') {
    var as = document.getElementById('bodyContent').getElementsByTagName('a');
    var userName;
    var rx1 = new RegExp('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}');
    var rx2 = new RegExp('title=%D7%A9%D7%99%D7%97%D7%AA_%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:([^&]*)&action=edit');
    for (var i=0; i < as.length; i++) {
       var m1 = rx1.test(as[i].href);
       var m2 = rx2.exec(as[i].href);
       if (m2 && !m1 && as[i].href.indexOf('history') == -1 && as[i].title.indexOf("/") == -1) {
         userName = decodeURIComponent(m2[1]);
         var a_wel = document.createElement('a');
         a_wel.href = 'javascript:openNewWindow(\'' + userName + '\', \'no_title\', \'' + 'wel' + '\')';
         a_wel.style.backgroundColor = 'pink';
         a_wel.appendChild(document.createTextNode(wel_text));
         a_wel.title = wel_tooltip;
         var txt1 = document.createTextNode(')');
         var txt2 = document.createTextNode(' (');
         as[i].parentNode.insertBefore(txt1, as[i].nextSibling);
         as[i].parentNode.insertBefore(a_wel, as[i].nextSibling);
         as[i].parentNode.insertBefore(txt2, as[i].nextSibling);
       }
    }
  }

  var template_name = getParamValue('template_name');   // Fetch what template to add
  var title_name = getParamValue('title_name');

  if (template_name == 'wrn'){
    addTemplate('wrn', title_name);
  }
  if (template_name == 'try'){
    addTemplate('try', title_name);
  }
  if (template_name == 'tnx'){
    addTemplate('tnx', title_name);
  }
  if (template_name == 'cpy'){
    addTemplate('cpy', title_name);
  }
  if (template_name == 'del'){
    addTemplate('del', title_name);
  }
  if (template_name == 'wel'){
    addTemplate('wel', title_name);
  }
}

$(templateSC_onload);