משתמש:ערן/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 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 || txt.indexOf("מחריד",0)!=-1 || txt.indexOf("נהדר",0)!=-1){
   comstr=comstr+"\nיתכן שהערך כולל סופרלטיבים מיותרים";
 }
 if(txt.indexOf(" ז\"ל ",0)!=-1){
   comstr=comstr+"\nאין להצמיד לאדם את התואר ז\"ל (מידע נוסף ב ויקיפדיה:עקרונות מיוחדים לשפה העברית)";
 }
 if(comstr!=""){
  alert(comstr);
 }
}



// פונקציה להוספת רשימת אזהרות כשמפעיל מערכת עורך דף שיחה של אנונימי
function talkIPTool()
{
//בדיקה אם מופיעה אפשרות מחיקה
 blkAcc=document.getElementById('t-blockip');
 if (blkAcc != null) {
  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].value + \' ~~~~\';document.getElementById(\'editform\').submit();">';
   warList += '<option value="" title="">בחרו מהרשימה כדי להוסיף</option>'
   warList += '<option title="אזהרה" value="{{אזהרה}}">אזהרה</option>'
   warList += '<option title="הזמנה" value="{{הזמנה}}">הזמנה</option>'
   warList += '<option title="ניסויים" value="{{ניסויים}}">ניסויים</option>'
   warList += '<option title="תודה" value="{{תודה}}">תודה</option>'
   warList += '<option title="ויקיזציה" value="{{ויקיזציה}}">ויקיזציה</option>'
   warList += '<option title="לך" value="{{לך}}">לך</option>'
   warList += '<option title="תלונה" value="{{תלונה}}">תלונה</option>'
   warList += '<option title="טעות" value="{{טעות}}">טעות</option>'
   warList += '<option title="נייטרליות" value="{{נייטרליות}}">נייטרליות</option>'
   warList += '<option title="נחסמת" value="{{נחסמת}}">נחסמת</option>'
   warList += '<option title="מילון" value="{{מילון}}">מילון</option>'
   warList += '<option title="כבר קיים" value="{{כבר קיים}}">כבר קיים</option>'
   warList += '<option title="שגיאה" value="{{שגיאה}}">שגיאה</option>'
   warList += '<option title="העתקה" value="{{העתקה}}">העתקה</option>'
   warList += '<option title="פרסומת" value="{{פרסומת}}">פרסומת</option>'
   warList += '<option title="נמחק" value="{{נמחק}}">נמחק</option>'
   warList += '<option title="הסבר" value="{{הסבר}}">הסבר</option>'
   warList += '<option title="בוטל" value="{{בוטל}}">בוטל</option>'
   warList += '<option title="סגנון" value="{{סגנון}}">סגנון</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();" />';

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

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