מדיה ויקי:סקריפטים/6.js

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

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
//
// סקריפט 6: לקוח מ[[ויקיפדיה:סקריפטים/6]]
// הקוד מוסיף כפתור Html2Wiki בצד שמאל שממיר טבלאות HTML
function Html2WikiInstallation()
{
 editOptionsD = document.getElementById('edit-templates');
 if (editOptionsD !== null) {
  Wiki2HtmlButton = '<input type="button" value="Html2Wiki" onclick="Html2Wiki();" />';
  editOptionsD.innerHTML = Wiki2HtmlButton + editOptionsD.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;
}
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;
}
addLoadEvent(Html2WikiInstallation);
// עד כאן סקריפט 6