ผู้ใช้:Jutiphan/Scripts/cleanup/monobook.js

จากวิกิพีเดีย สารานุกรมเสรี

หมายเหตุ: หลังจากบันทึกแล้ว, คุณต้องล้างแคชของเบราว์เซอร์เสียก่อน จึงจะเห็นการเปลี่ยนแปลง: Mozilla/Safari/Konqueror: กด Shift ค้าง แล้วกด Reload (หรือ Ctrl-Shift-R), IE: กด Ctrl-F5, Opera: กด F5

/* <pre><nowiki> */

// ========== จัดรูปแบบ+เก็บกวาด ==========
// สคริปต์นี้ เปลี่ยนคำสั่งเก่า เช่น Category, Image, และข้อความเก่า
function doCleanupTag() {
  text = document.editform.wpTextbox1.value;

  //Format
  text = text.replace(/<br\/>|<br>/gi, "<br />");                                          //<br/> -> <br />
  text = text.replace(/([^\[]|^)\[([^\[^\]]*?)\]\]/gm, "$1[[$2]]");                   //[ลิงก์ใน]] -> [[ลิงก์ใน]]
  text = text.replace(/\[\[([^\[^\]].*?)[$[^\]]?]/gm, "[[$1]]");                      //[[ลิงก์ใน] -> [[ลิงก์ใน]]
  text = text.replace(/\[\[ ?([^\]\|]*?) \s*([\|\s|\]\]])/g, "[[$1$2");               //[ ลิงก์ใน ]] -> [[ลิงก์ใน]]

  text = text.replace(/^([\*#]+) /gm, "$1");                                           
  text = text.replace(/^([\*#]+)/gm, "$1 ");                                        
  text = text.replace(/^= ?([^=].*?) ?=/gm,"== $1 ==");                                //= หัวข้อ =  -> == หัวข้อ ==
  text = text.replace(/^(={1,4}) *(.*?) ?(={1,4})$/gm, "$1 $2 $3");                   //==หัวข้อ== -> == หัวข้อ ==
  text = text.replace(/&nbsp;/g, " ");
  text = text.replace(/&prime;/g, "'");
  text = text.replace(/&amp;/g, "&");
  text = text.replace(/&minus;/g, "−");
  text = text.replace(/&times;/g, "×");
  text = text.replace(/&mdash;/g, "—");
  text = text.replace(/&ndash;/g, "-");
  
  //Spellings
  text = text.replace(/\sกฏ/g," กฎ");
  text = text.replace(/กิติมศักดิ์/g,"กิตติมศักดิ์");
  text = text.replace(/ขาดดุลย์/g,"ขาดดุล");
  text = text.replace(/คลีนิก/g,"คลินิก");
  text = text.replace(/คำนวน/g,"คำนวณ");
  text = text.replace(/โครงการณ์/g,"โครงการ");
  text = text.replace(/เซ็นติเมตร/g,"เซนติเมตร");
  text = text.replace(/ฑูต/g,"ทูต");
  text = text.replace(/ธุระกิจ/g,"ธุรกิจ");
  text = text.replace(/ปรากฎ/g,"ปรากฏ");
  text = text.replace(/ปราถนา/g,"ปรารถนา");
  text = text.replace(/ฝรั่งเศษ/g,"ฝรั่งเศส");
  text = text.replace(/ลายเซ็นต์/g,"ลายเซ็น");
  text = text.replace(/เวทย์มนตร์|เวทมนต์/g,"เวทมนตร์");
  text = text.replace(/ดอทเน็ท|ดอตเน็ท|ด็อตเน็ต|ด็อทเน็ต/g,"ดอตเน็ต");
  text = text.replace(/ซอฟท์แวร์/g,"ซอฟต์แวร์");
  text = text.replace(/ไมโครซอฟต์/g,"ไมโครซอฟท์");
  text = text.replace(/ปฎิบัติ/g,"ปฏิบัติ");
  text = text.replace(/สคริปท์|สครปต์/g,"สคริปต์");
  text = text.replace(/อินเตอร์เน็ต/g,"อินเทอร์เน็ต");
  text = text.replace(/อัพเด็ต|อัพเดต|อัพเดท|อัปเด็ต/g,"อัปเดต");
  text = text.replace(/ปฏิกริยา/g,"ปฏิกิริยา");
  text = text.replace(/นิวยอร์ค/g, "นิวยอร์ก");
  text = text.replace(/อิเล็กโทรนิกส์/g, "อิเล็กทรอนิกส์");
  text = text.replace(/อลูมิเนียม/g, "อะลูมิเนียม");
  text = text.replace(/อนุญาติ/g,"อนุญาต");
  text = text.replace(/อิสระภาพ/g,"อิสรภาพ");
  text = text.replace(/เอ็กซเรย์/g, "เอกซเรย์");
  text = text.replace(/เซอร์เวอร์/g,"เซิร์ฟเวอร์");
  text = text.replace(/แอปพลิเคชั่น|แอพพลิเคชัน|แอพพลิเคชั่น/g, "แอปพลิเคชัน"),
  text = text.replace(/เซ็นติ/g,"เซนติ");
  text = text.replace(/เอ็กซ์/g,"เอกซ์");
  text = text.replace(/อโดบี/g,"อะโดบี");

  //Cleanup
  text = text.replace(/\[\[category:/gi,'[[หมวดหมู่:');
  text = text.replace(/image:/gi,'ภาพ:');
  text = text.replace(/(== ?) ?(แหล่งอ้างอิง|หนังสืออ้างอิง|เอกสารอ้างอิง|ข้อมูลอ้างอิง|แหล่งข้อมูลอ้างอิง|อ้างอิงจาก) *==/g,'$1อ้างอิง ==');
  text = text.replace(/(== ?) ?(ดูเพิ่มเติม|ดูเพื่มเติม|ดูเพิ่มที่|อ่านเพิ่ม|อ่านเพิ่มเติม|หัวข้ออื่นที่เกี่ยวข้อง) *==/g,'$1ดูเพิ่ม ==');
  text = text.replace(/(== ?) ?(เว็บไซต์|เว็บไซต์ภายนอก|เว็บไซต์์์อื่น|เว็บไซต์์์์์์อื่น|เว็บไซต์อื่น|เว็บไซต์ที่เกี่ยวข้อง|ข้อมูลภายนอก|โยงภายนอก|เว็บลิงก์ภายนอก|ลิงก์ภายนอก|ลิงค์ภายนอก|ดูลิงก์ภายนอก|แหล่งข้อมูลภายนอก|แหล่งข้อข้อมูลอื่น) *==/g,"$1แหล่งข้อมูลอื่น ==");
  text = text.replace(/(== ?) ?(Link\s?ภายนอก|link\s?ภายนอก) *==/g,"$1แหล่งข้อมูลอื่น ==");
  text = text.replace(/(== ?) ?(ประวัติความเป็นมา|ประวัติส่วนตัว|ความเป็นมา|ชีวประวัติ) *==/g,"$1ประวัติ ==");

  document.editform.wpTextbox1.value = text;
  if(document.editform.wpSummary.value.indexOf("เก็บกวาดด้วย[[ผู้ใช้:Jutiphan/Scripts|สคริปต์จัดให้]]") == -1) {
  if(document.editform.wpSummary.value.length == 0) {
      document.editform.wpSummary.value = "จัดรูปแบบ +เก็บกวาดด้วย[[ผู้ใช้:Jutiphan/Scripts|สคริปต์จัดให้]]";
    } else {
      document.editform.wpSummary.value = document.editform.wpSummary.value + " +เก็บกวาดด้วย[[ผู้ใช้:Jutiphan/Scripts|สคริปต์จัดให้]]";
    }
  }
}


// ========== เพิ่มปุ่มเก็บกวาดบน Toolbar ==========
addOnloadHook( function() {

  var tooly = document.getElementById('toolbar');
  if (tooly != null) {
    var cleanupButton = "<a href=\"javascript:doCleanupTag();\"><img src=\"http://upload.wikimedia.org/wikipedia/th/9/96/Button_cleanup.png\" alt=\"เก็บกวาด\"></a>";
    tooly.innerHTML = tooly.innerHTML + cleanupButton;
  }
});

/*
function addCleanupButton() {
  tooly= document.getElementById('toolbar');
  if (tooly != null) {
    cleanupButton = "<a href=\"javascript:doCleanupTag();\"><img src=\"http://upload.wikimedia.org/wikipedia/th/9/96/Button_cleanup.png\" alt=\"เก็บกวาด\"></a>";
    tooly.innerHTML = tooly.innerHTML + cleanupButton;
    akeytt();
  }
}

if (document.title.indexOf("แก้ไข ") == 0) {
  //This code needs a cleanup
  window.onload = addCleanupButton;

  //Code below doesn't work in Firefox for unknown reasons
  //if (window.addEventListener) window.addEventListener("load", addCleanupButton, false);
  //else if (window.attachEvent) window.attachEvent("onload", addCleanupButton);
}
*/


// ========== เก็บกวาดทันใจ(แสดงที่หน้าบทความ) ==========
addOnloadHook(function() {
  //Add tab if it is an article
  if(wgIsArticle) {
    addTab("javascript:doSpeedyCleanup()", "เก็บกวาด", "ca-scleanup", "เก็บกวาดทันใจ", "");
  }

  if (document.title.indexOf("แก้ไข") != -1) {
    if (document.URL.lastIndexOf("&fakeaction=speedycleanup") == -1)
      return;
    if (wgArticleId == 0)
      return;

    doCleanupTag();
    document.editform.submit();
    return;
  }
});

function doSpeedyCleanup() {
  //edit page
  var title = document.title.substr(0, document.title.lastIndexOf(' - วิกิพีเดีย'));
  location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=speedycleanup");
}

/* </nowiki></pre> */