משתמש:עשהאל רייטר/monobook.js

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

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

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

/* הקוד מוסיף כפתור Html2Wiki שבלחיצה עליו אמור לשנות תגי HTML לויקי. כרגע הופך תגי b וi כמו שעשו בויקי הרוסית (רק בקצרה) וממיר טבלאות (ולפעמים גם מוסיף כל מיני רווחים מיותרים).
שימו לב! הפונקציה תחליף את כל הטקסט, גם אם הוא בתוך nowiki. עלולות להיות בעיות כשהקוד שגוי.
יש לבדוק שלא הורסים טקסט שצריך להשאר בhtml. ראו הוזהרתם */
function Html2WikiInstallation()
{
 copywarn = document.getElementById('editpage-copywarn');
 if (copywarn != null) {
  var cleaner = "<br style=\\'clear:both;\\' />";
  Wiki2HtmlButton = '<input type="button" value="Html2Wiki" onclick="document.getElementById(\'PreviewBox\').innerHTML = Html2Wiki() + \'' + cleaner + '\';" />';
  copywarn.innerHTML = Wiki2HtmlButton + copywarn.innerHTML;
 }
}

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;
}
atab = txt.indexOf("<table",0);
while(atab!=-1){
txt=txt.replace("<table","\n{|");
atab = txt.indexOf("<table",atab+1);
}
atab = txt.indexOf("</table>",0);
while(atab!=-1){
txt=txt.replace("</table>","\n|}");
atab = txt.indexOf("</table",atab+1);
}

/* פונקציה להפיכת תגי 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;
}
atab = txt.indexOf("<tr",0);
while(atab!=-1){
txt=txt.replace("<tr","|-");
atab = txt.indexOf("<tr",atab+1);
}
atab = txt.indexOf("</tr>",0);
while(atab!=-1){
txt=txt.replace("</tr>","");
atab = txt.indexOf("</tr",atab+1);
}

/* פונקציה להפיכת תגי 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;
}
atab = txt.indexOf("<td",0);
while(atab!=-1){
txt=txt.replace("<td","|");
atab = txt.indexOf("<td",atab+1);
}
atab = txt.indexOf("</td>",0);
while(atab!=-1){
txt=txt.replace("</td>","");
atab = txt.indexOf("</td",atab+1);
}

/* פונקציה להפיכת תגי 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;
}
atab = txt.indexOf("<th",0);
while(atab!=-1){
txt=txt.replace("<th","!");
atab = txt.indexOf("<th",atab+1);
}
atab = txt.indexOf("</th>",0);
while(atab!=-1){
txt=txt.replace("</th>","");
atab = txt.indexOf("</th",atab+1);
}
/* החלפת תוכן תיבת הקוד בקוד שעבר טיפול בפונקציה. */
document.editform.wpTextbox1.value = txt;
}

/* הפעלת הפונקציות. */
window.onload = Main;

function Main()
{
Html2WikiInstallation();
InsertButtonsToToolBar();
}