משתמש:ערן/monobook.js

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

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

  • במוזילה, פיירפוקס או ספארי, לחצו על מקש ה־Shift בעת לחיצתכם על העלה מחדש (Reload), או הקישו Ctrl+Shift+R (או Cmd+Shift+R במקינטוש של אפל).
  • באינטרנט אקספלורר, לחצו על מקש ה־Ctrl בעת לחיצתכם על רענן (Refresh), או הקישו על Ctrl+F5.
  • ב־Konqueror, פשוט לחצו על העלה מחדש (Reload), או הקישו על F5.
  • באופרה, ייתכן שתצטרכו להשתמש בכלים (Tools) > העדפות (Preferences) כדי לנקות לחלוטין את זכרון המטמון.
/* <div style="direction: ltr;"><pre> */
/* זהו דף הmonobook.js שלי- כאן אני מוסיף סקריפטים שונים. בדף זה מספר סקריפטים- כל אחד רשאי להעתיקם. */

/* הקוד מוסיף כפתור Html2Wiki שבלחיצה עליו אמור לשנות תגי HTML לויקי. כרגע הופך תגי b וi כמו שעשו בויקי הרוסית (רק בקצרה) וממיר טבלאות (ולפעמים גם מוסיף כל מיני רווחים מיותרים).
שימו לב! הפונקציה תחליף את כל הטקסט, גם אם הוא בתוך nowiki. עלולות להיות בעיות כשהקוד שגוי.
יש לבדוק שלא הורסים טקסט שצריך להשאר בhtml. ראו הוזהרתם */

function yeshuviYonibot(){
 if (document.getElementById('edit-templates')!=null){
txt = document.editform.wpTextbox1.value;
inscode= '<!-- שימו לב: בערך זה טקסט המשמש את בוט היישובים על מנת שיוכל לבצע עדכון אוטומטי. אין לשנות את הנתונים בתבנית "עיר בישראל", ואין לשנות את עיצובה, כולל הוספת רווחים מיותרים. אין לשנות או להסיר את ההערות הנסתרות שבערך, כולל הטקסט שמופיע בין ההערות. לפרטים נוספים ראו [[ויקיפדיה:בוט/בוט היישובים]]. תודה. -->\n{{עיר בישראל\n|בוט יישובים=כן|\n|שם= ';
atab = txt.indexOf('<th colspan=2 bgcolor=#ffe2e2>',0);
btab = txt.indexOf('</th>',atab);
str=txt.substring(atab+30,btab);
inscode +=str+'|\n|שם באנגלית='
atab = txt.indexOf('תעתיק לאנגלית</td><td>',0);
btab = txt.indexOf('</td>',atab+22);
str=txt.substring(atab+22,btab);
inscode +=str+'|<!-- לתשומת לבכם, התעתיק לאנגלית הוא התעתיק הרשמי לפי הלמ"ס -->\n|סמל=|\n|דגל=|\n|תמונה=|\n|מחוז='
atab = txt.indexOf('ב[[מחוז ',0);
btab = txt.indexOf(']]',atab);
str=txt.substring(atab+8,btab);
inscode +=str+'|\n|תאריך יסוד='
atab = txt.indexOf('שנת יסוד</td><td>',0);
btab = txt.indexOf('</td>',atab+17);
str=txt.substring(atab+17,btab);
if(str=='&nbsp;') str='';
inscode +=str+'|\n|אוכלוסייה='
atab = txt.indexOf('סה"כ תושבים</td><td>',0);
btab = txt.indexOf('</td>',atab+20);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|צפיפות אוכלוסייה=|\nשטח='
atab = txt.indexOf('שטח שיפוט</td><td>',0);
btab = txt.indexOf('</td>',atab+18);
str=txt.substring(atab+18,btab);
inscode +=str+'|\n|ראש העיר=|\n|אתר אינטרנט=|\n|דירוג חברתי-כלכלי='
atab = txt.indexOf('מדורגת בדרוג חברתי-כלכלי ',0);
if(atab==-1) atab=txt.indexOf('מדורגת בדרוג [[חברתי]]-[[כלכלי]] ',0)+8;
if(atab==-1) atab=txt.indexOf('מדורגת בדרוג [[חברה|חברתי]]-[[כלכלה|כלכלי]] ',0)+19;
btab = txt.indexOf(')',atab);
str=txt.substring(atab+25,btab+1);
inscode +=str+'|\n|גילאי 0 - 4='
atab = txt.indexOf('גילאי   4-0</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 5 - 9='
atab = txt.indexOf('גילאי   9-5</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 10 - 14='
atab = txt.indexOf('גילאי 14-10</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 15 - 19='
atab = txt.indexOf('גילאי 19-15</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 20 - 29='
atab = txt.indexOf('גילאי 29-20</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 30 - 44='
atab = txt.indexOf('גילאי 44-30</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 45 - 59='
atab = txt.indexOf('גילאי 59-45</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|גילאי 60 - 64='
atab = txt.indexOf('גילאי 64-60</td><td>',0);
btab = txt.indexOf('</td>',atab+16);
str=txt.substring(atab+20,btab);
inscode +=str+'|\n|65 ומעלה='
atab = txt.indexOf('65 ומעלה</td><td>',0);
btab = txt.indexOf('</td>',atab+13);
str=txt.substring(atab+17,btab);
inscode +=str+'|\n|בתי ספר='
atab = txt.indexOf('סה"כ בתי ספר</td><td>',0);
btab = txt.indexOf('</td>',atab+17);
str=txt.substring(atab+21,btab);
if (str=='-') str='';
inscode +=str+'|\n|ב-יסודיים='
atab = txt.indexOf('יסודיים</td><td>',0);
btab = txt.indexOf('</td>',atab+12);
str=txt.substring(atab+16,btab);
if (str=='-') str='';
inscode +=str+'|\n|ב-על-יסודיים='
atab = txt.indexOf('על-יסודיים</td><td>',0);
btab = txt.indexOf('</td>',atab+15);
str=txt.substring(atab+19,btab);
if (str=='-') str='';
inscode +=str+'|\n|תלמידים='
ctab = txt.indexOf('תלמידים</td><td>',0);
btab = txt.indexOf('</td>',ctab+12);
str=txt.substring(ctab+16,btab);
if (str=='-') str='';
inscode +=str+'|\n|ת-יסודיים='
atab = txt.indexOf('יסודיים</td><td>',ctab);
btab = txt.indexOf('</td>',atab+12);
str=txt.substring(atab+16,btab);
if (str=='-') str='';
inscode +=str+'|\n|ת-על-יסודיים='
atab = txt.indexOf('על-יסודיים</td><td>',ctab);
btab = txt.indexOf('</td>',atab+15);
str=txt.substring(atab+19,btab);
if (str=='-') str='';
inscode +=str+'|\n|מספר כיתות='
atab = txt.indexOf('מספר כיתות</td><td>',0);
btab = txt.indexOf('</td>',atab+15);
str=txt.substring(atab+19,btab);
if (str=='-') str='';
inscode +=str+'|\n|ממוצע תלמידים לכיתה='
atab = txt.indexOf('ממוצע תלמידים<BR>לכיתה</td><td>',0);
btab = txt.indexOf('</td>',atab+24);
str=txt.substring(atab+31,btab);
inscode +=str+'|\n|שנת עדכון=2001|\n}}'
atab = txt.indexOf('<!--ההערות',0);
btab = txt.indexOf('DynamicTable-->',atab);
str=txt.substring(0,atab)+inscode+ txt.substring(btab+15,txt.length);
document.editform.wpTextbox1.value=str;
document.editform.wpSummary.value+='המרת הטבלה לתבנית באמצעות סקריפט';
}
}

function Html2Wiki()
{
txt = document.editform.wpTextbox1.value;

/* הפיכת התגיות b וstrong וi וem לתגי ויקי באמצעות החלפה. אזהרה: ההחלפה מתבצעת על כל הטקסט, גם אם רשום nowiki לפני */
txt = txt.replace(/\<\/?(b|strong)\>/g, "\'\'\'");
txt = txt.replace(/\<\/?(i|em)\>/g, "\'\'");

/* פונקציה להפיכת תגי table לתגי ויקי */
atab = txt.indexOf("<table",0);
while(atab!=-1){
btab = txt.indexOf(">",atab);
str1=txt.substring(0,btab);
str2=txt.substring(btab+1,txt.length);
txt=str1+str2;
atab = txt.indexOf("<table",btab);
if (btab==-1) atab=-1;
}
txt = txt.replace(/\<table/g, "\n{|");
txt = txt.replace(/\<\/table\>/g, "\n|}");

/* פונקציה להפיכת תגי tr לתגי ויקי */
atab = txt.indexOf("<tr",0);
while(atab!=-1){
btab = txt.indexOf(">",atab);
str1=txt.substring(0,btab);
str2=txt.substring(btab+1,txt.length);
txt=str1+"\n"+str2;
atab = txt.indexOf("<tr",btab);
if (btab==-1) atab=-1;
}
txt = txt.replace(/\<tr/g, "|-");
txt = txt.replace(/\<\/tr\>/g, "");

/* פונקציה להפיכת תגי td לתגי ויקי */
atab = txt.indexOf("<td",0);
while(atab!=-1){
btab = txt.indexOf(">",atab);
str1=txt.substring(0,btab);
str2=txt.substring(btab+1,txt.length);
txt=str1+"|"+str2;
atab = txt.indexOf("<td",btab);
if (btab==-1) atab=-1;
}
txt = txt.replace(/\<td/g, "|");
txt = txt.replace(/\<\/td\>/g, "");

/* פונקציה להפיכת תגי th לתגי ויקי */
atab = txt.indexOf("<th",0);
while(atab!=-1){
btab = txt.indexOf(">",atab);
str1=txt.substring(0,btab);
str2=txt.substring(btab+1,txt.length);
txt=str1+"|"+str2;
atab = txt.indexOf("<th",btab);
if (btab==-1) atab=-1;
}
txt = txt.replace(/\<th/g, "!");
txt = txt.replace(/\<\/th\>/g, "");

/* החלפת תוכן תיבת הקוד בקוד שעבר טיפול בפונקציה. */
document.editform.wpTextbox1.value = txt;
}

/* הוספת כפתור שמבצע החלפות שונות ומתריע על בעיות סגנון שונות */
function CheckTy()
{
 txt = document.editform.wpTextbox1.value;
 txt = txt.replace(/\ היתה/g, " הייתה");
 txt = txt.replace(/\איזור/g, "אזור");
 txt = txt.replace(/\אירגון/g, "ארגון");
 txt = txt.replace(/\גיאוגרפיה/g, "גאוגרפיה");
 txt = txt.replace(/\גיאולוגיה/g, "גאולוגיה");
 txt = txt.replace(/\דוגמא /g, "דוגמה ");
 txt = txt.replace(/\ ישוב /g, " יישוב ");
 txt = txt.replace(/\כנסיה/g, "כנסייה");
 txt = txt.replace(/\מוסיקה/g, "מוזיקה");
 txt = txt.replace(/\פיסיולוגיה/g, "פיזיולוגיה");
 txt = txt.replace(/\פיסיקה/g, "פיזיקה");
 txt = txt.replace(/\צלסיוס/g, "צלזיוס");
 txt = txt.replace(/\ שניה /g, " שנייה ");
 txt = txt.replace(/\תיאוריה/g, "תאוריה");
 txt = txt.replace(/\[Category:/gi, "[קטגוריה:");
 txt = txt.replace(/\[Image:/gi, "[תמונה:");
 txt = txt.replace(/\|thumb\|/gi, "|ממוזער|");
 txt = txt.replace(/\|right\|/gi, "|ימין|");
 txt = txt.replace(/\|left\|/gi, "|שמאל|");
 txt = txt.replace(/ראה גם/g, "ראו גם");
 txt = txt.replace(/\במידה ו/g, "במידה ש");
 txt = txt.replace(/\  /g, " ");
 document.editform.wpTextbox1.value = txt;
comstr="";
 if(txt.indexOf("בגלל ש",0)!=-1){
   comstr=comstr+"\nיתכן שבערך מופיע הצירוף בגלל ש. אם מופיע מומלץ להחליפו בכיוון ש, משום ש, מאחר ש או מפני ש (מידע נוסף ב ויקיפדיה:לשון)";
 }
 if(txt.indexOf("עובדה מעניינת היא",0)!=-1 || txt.indexOf("יש לציין",0)!=-1){
   comstr=comstr+"\nאל תעיד אל עיסתך! מומלץ להימנע מהביטוים עובדה מעניינת היא או יש לציין. יש לתת לקורא להחליט אם העובדה ראויה לציון. (מידע נוסף ב ויקיפדיה:לשון)";
 }
 if(txt.indexOf("למרות ש",0)!=-1) comstr=comstr+"\nיתכן שבערך מופיע הצירוף למרות ש. אם מופיע מומלץ להחליפו באף על פי ש (מידע נוסף ב ויקיפדיה:לשון)";
 if(txt.indexOf("בגלל ש",0)!=-1) comstr=comstr+"\nבערך מופיע הצירוף בגלל ש. רצוי להחליפו במשום ש או מפני ש)";
 if(txt.indexOf("הכי טוב",0)!=-1){
   comstr=comstr+"\nבערך זה מופיע הצירוף הכי טוב, יתכן שכדאי להחליפו לטוב ביותר (מידע נוסף ב ויקיפדיה:שגיאות תרגום נפוצות)";
 }
 if(txt.indexOf("נפלא",0)!=-1 || txt.indexOf("מחריד",0)!=-1 || txt.indexOf("נהדר",0)!=-1) comstr=comstr+"\nיתכן שהערך כולל סופרלטיבים מיותרים";
 if(txt.indexOf(" יכל",0)!=-1) comstr=comstr+"\nבערך מופיע יכל רצוי להחליפו להיה יכול";
 if(txt.indexOf(" ז\"ל ",0)!=-1) comstr=comstr+"\nאין להצמיד לאדם את התואר ז\"ל (מידע נוסף ב ויקיפדיה:עקרונות מיוחדים לשפה העברית)";
 if(comstr!=""){
  alert(comstr);
 }
}

/* סקריפט להוספת רשימת תבניות פניה/אזהרה כשעורכים דף שיחה של משתמש אנונימי */
function talkIPTool()
{
  var title = (document.title.substr(0, document.title.lastIndexOf(" - ")));
  templatesList=document.getElementById('edit-templates');
  if(templatesList!=null && title.indexOf('.')!=title.lastIndexOf('.')){
   warList='אזהרות: <select onchange="document.editform.wpSummary.value+=this[selectedIndex].title; document.editform.wpTextbox1.value += \'{{ס:\' + this[selectedIndex].title + \'}} ~~\' + \'~~\';document.getElementById(\'editform\').submit();">';
   warList += '<option title="">בחרו מהרשימה כדי להוסיף</option>'
   warList += '<option title="אזהרה">אזהרה</option>'
   warList += '<option title="הבל">הבל</option>'
   warList += '<option title="הזמנה">הזמנה</option>'
   warList += '<option title="ניסויים">ניסויים</option>'
   warList += '<option title="תודה">תודה</option>'
   warList += '<option title="ויקיזציה">ויקיזציה</option>'
   warList += '<option title="לך">לך</option>'
   warList += '<option title="תלונה">תלונה</option>'
   warList += '<option title="טעות">טעות</option>'
   warList += '<option title="נייטרליות">נייטרליות</option>'
   warList += '<option title="נחסמת">נחסמת</option>'
   warList += '<option title="מילון">מילון</option>'
   warList += '<option title="כבר קיים">כבר קיים</option>'
   warList += '<option title="שגיאה" >שגיאה</option>'
   warList += '<option title="העתקה">העתקה</option>'
   warList += '<option title="פרסומת">פרסומת</option>'
   warList += '<option title="נמחק">נמחק</option>'
   warList += '<option title="הסבר">הסבר</option>'
   warList += '<option title="בוטל">בוטל</option>'
   warList += '<option title="סגנון">סגנון</option>'
   warList += '</select>'
   templatesList.innerHTML=warList+templatesList.innerHTML;
 }
}

/* תמונות ליד קישורים חיצוניים. */
function externalLIcons(e) 
{
    e = (e) ? e : event;
    var links = document.getElementsByTagName("a");
    var i;
    for (i = 1; i <= links.length; i++)
    {
        if (links[i - 1].className == "external text")
        {
    var extrImg=document.createElement("img");
    if(links[i-1].href.match(".pdf")){
    extrImg.src= 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Icons-mini-file_acrobat.gif/15px-Icons-mini-file_acrobat.gif';
    } else if(links[i-1].href.match(/.(doc|rtf)/)){
    extrImg.src= 'http://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Noia_64_mimetypes_wordprocessing.png/16px-Noia_64_mimetypes_wordprocessing.png';
    } else {
    extrImg.src= 'http://upload.wikimedia.org/wikipedia/he/thumb/0/01/External2.png/10px-External2.png';
    }
         links[i-1].appendChild(extrImg);
        }
    }
}


function replacedash() {
/* This code is based on [[:en:User:Omegatron/monobook.js/dashfixer.js]] */
    var txt = document.editform.wpTextbox1;

    // Convert all html entities into actual dash characters 
  txt.value = txt.value.replace(/(&#x2014;|&#8212;|&mdash;)/g, '—');
    txt.value = txt.value.replace(/(&#x2013|&#8211;|&ndash;)/g, '–');
    txt.value = txt.value.replace(/(&#x2212;|&#8722;|&minus;)/g, '−');

// Convert – and en dashes *with or without* spaces --> en dash character surrounded by spaces
    txt.value = txt.value.replace(/([a-zA-Z\'\"”\s\]\}\)])(---|–|–)([a-zA-Z\'\"“\s\[\{\(])/g, '$1–$3');

    // Convert -- *without* spaces --> Makaf character not surrounded by spaces
    txt.value = txt.value.replace(/([א-ת\'\"”\]\}])(--)([א-תa-zA-Z0-9\'\"“\[\{])/g, '$1־$3');



/*
    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "[[User:Omegatron#Regular expressions|Regex dash fixer]]";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
			txt.value += " | ";
		}
		txt.value += summary;
	}

    // Press the diff button to check it
    document.editform.wpDiff.click()
*/
return(true);
}

/* הוספת כפתורים אישיים: כפתור הפיכת קוד html לוויקי (בעיקר טבלאות), כפתור לביצוע בדיקות שונות וכפתור מיקוף */
function eButtons(){
 if (document.getElementById('edit-templates')!=null){
  for(var i=0; a = document.getElementsByTagName("div")[i]; i++) {
  if(a.className == "editButtons") {
   mCusButtons = '<br/><div style="border-bottom:2px dashed #eeeeee">כפתורים נוספים:</div><input type="button" value="Html2Wiki" onclick="Html2Wiki();" /><input type="button" value="בדיקה" onclick="CheckTy();" /><input type="button" value="מיקוף" onclick="replacedash();" /><input type="button" value="ישוב" onclick="yeshuviYonibot();" />';

   a.innerHTML += mCusButtons;
   }
  }
 }
}
addOnloadHook(eButtons);
addLoadEvent(externalLIcons);
addLoadEvent(talkIPTool);

/* </div></pre> */