ผู้ใช้:Willwill/monobook.js - วิกิพีเดีย

# ผู้ใช้:Willwill/monobook.js

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

< ผู้ใช้:Willwill

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

    /* <nowiki> */
    function addlilink(tabs, url, name, id, title, key){
        var na = document.createElement('a');
        na.href = url;
        na.appendChild(document.createTextNode(name));
        var li = document.createElement('li');
        if(id) li.id = id;
        li.appendChild(na);
        tabs.appendChild(li);
        na.accesskey = key;
        var pref = 'alt-';
        if(((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1)) || navigator.userAgent.toLowerCase().indexOf( 'mac' ) != -1 ) pref = 'control-';
        if(clientPC.indexOf('opera')!=-1) pref = 'shift-esc-';
        if(key && title) na.title = title + ' [' + pref + key + ']';
        else if(title) na.title = title;
        else if(key) na.title = '[' + pref + key + ']';
        return li;
    }

    function addTab(url, name, id, title, key){
        var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
        addlilink(tabs, url, name, id, title, key);
    }

    function getPname() {
      z=document.getElementById("content").childNodes;
      for (var n=0;n<z.length;n++) {
        if (z[n].className=="firstHeading") return z[n].textContent;
      };
    }

    // ========== ลิงก์ข้าม ==========
    function doENlink() {
      document.editform.wpTextbox1.value = "{{ลิงก์ไปภาษาอื่น}}\n\n" + document.editform.wpTextbox1.value;
      document.editform.wpSummary.value = "มีลิงก์ไปภาษาอื่นแทรกไว้";
      document.editform.wpMinoredit.checked = true;
      document.editform.submit();
    }
    function addENlink() {
      addTab("javascript:doENlink()", "ลิงก์ข้าม", "ca-ENlink", "แจ้งว่ามีลิงก์ข้ามไปภาษาอื่น", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addENlink, false);
      else if (window.attachEvent) window.attachEvent("onload", addENlink);
    }

    // ========== Need Section 0 ==========
    function doSum() {
      document.editform.wpTextbox1.value = "{{ต้องการสรุป}}\n\n" + document.editform.wpTextbox1.value;
      document.editform.wpSummary.value = "ต้องการสรุปย่อหน้าแรก";
      document.editform.submit();
    }
    function addSum() {
      addTab("javascript:doSum()", "+สรุป", "ca-sum", "ต้องการสรุปย่อหน้าแรก", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addSum, false);
      else if (window.attachEvent) window.attachEvent("onload", addSum);
    }

    // ========== Wikicartoon ==========
    function doQwikicartoon() {
      document.editform.wpTextbox1.value = "{{วิกิการ์ตูน}}" + document.editform.wpTextbox1.value;
      document.editform.wpSummary.value = "กำหนดเป็นวิกิการ์ตูน";
      document.editform.submit();
    }
    function addQwikicartoon() {
      addTab("javascript:doQwikicartoon()", "การ์ตูน", "ca-cartoon", "คำสั่งเป็นวิกิการ์ตูน", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addQwikicartoon, false);
      else if (window.attachEvent) window.attachEvent("onload", addQwikicartoon);
    }

    // ========== Edit Section 0 ==========
    function addEditSection0() {
      ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
      if (!document.getElementById) return;
      x = document.getElementById('ca-edit');
      if(!x) return;
      y = document.createElement('LI');
      y.id = 'ca-edit-0';
      if (x.className == 'selected') {
        if (/&action=edit&section=0$/.test(window.location.href)) {
          x.className = 'istalk';
          y.className = 'selected';
        } else {
          x.className = 'selected istalk';
        }
      } else if (x.className == 'selected istalk') {
        if (/&action=edit&section=0$/.test(window.location.href)) {
          x.className = 'istalk';
          y.className = 'selected istalk';
        } else {
          y.className = 'istalk';
        }
      } else {
        y.className = x.className;
        x.className = 'istalk';
      }
      z = document.createElement('A');
      if (x.children) {
        z.href = x.children[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
      } else {
        z.href = x.childNodes[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
      }
    }

    if (document.title.indexOf("Editing ") == -1) {
      if (window.addEventListener) window.addEventListener("load", addEditSection0, false);
      else if (window.attachEvent) window.attachEvent("onload", addEditSection0);
    }

    // ========== Add Last Diff ==========

    function doLastDiff() {
      var nurl="http://th.wikipedia.org/w/index.php?title=" + getPname() + "&diff=cur&oldid=prev";
      document.location=nurl
    }
    function addLastDiff() {
        var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
        var l=addlilink(tabs, "javascript:doLastDiff()", 'ล่าสุด', '');
        l.lastChild.title="Show most recent diff";
    }

    if (window.addEventListener) window.addEventListener("load", addLastDiff, false);
    else if (window.attachEvent) window.attachEvent("onload", addLastDiff);
    /* </nowiki> */

    // ========== Replace string ==========
    // Javascript from http://www.irt.org/script/242.htm
    function replace(string,text,by) {
    // Replaces text with by in string
        var strLength = string.length, txtLength = text.length;
        if ((strLength == 0) || (txtLength == 0)) return string;

        var i = string.indexOf(text);
        if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;

        var newstr = string.substring(0,i) + by;

        if (i+txtLength < strLength)
            newstr += replace(string.substring(i+txtLength,strLength),text,by);

        return newstr;
    }

    // ========== Thai to Arabic Numbers ==========
    // This script converts all Thai numbers (๑ ๒ ๓) to Arabic numbers (1 2 3)
    function doConvertNumber() {
      text = document.editform.wpTextbox1.value;
      text = replace(text,'๑','1');
      text = replace(text,'๒','2');
      text = replace(text,'๓','3');
      text = replace(text,'๔','4');
      text = replace(text,'๕','5');
      text = replace(text,'๖','6');
      text = replace(text,'๗','7');
      text = replace(text,'๘','8');
      text = replace(text,'๙','9');
      text = replace(text,'๐','0');
      document.editform.wpTextbox1.value = text;
      document.editform.wpSummary.value = "เปลี่ยนเลขไทยเป็นอารบิก";
    }
    function addConvertNumber() {
      addTab("javascript:doConvertNumber()", "๒ ->2", "ca-tanum", "เปลี่ยนเลขไทยเป็นอารบิก", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addConvertNumber, false);
      else if (window.attachEvent) window.attachEvent("onload", addConvertNumber);
    }

    // ========== Arabic to Thai Numbers ==========
    // This script converts all Arabic numbers (1 2 3) to Thai numbers (๑ ๒ ๓)
    function doConvertToThaiNumber() {
      text = document.editform.wpTextbox1.value;
      text = replace(text,'1','๑');
      text = replace(text,'2','๒');
      text = replace(text,'3','๓');
      text = replace(text,'4','๔');
      text = replace(text,'5','๕');
      text = replace(text,'6','๖');
      text = replace(text,'7','๗');
      text = replace(text,'8','๘');
      text = replace(text,'9','๙');
      text = replace(text,'0','๐');
      document.editform.wpTextbox1.value = text;
      document.editform.wpSummary.value = "เปลี่ยนเลขอารบิกเป็นไทย";
    }
    function addConvertToThaiNumber() {
      addTab("javascript:doConvertToThaiNumber()", "2 ->๒", "ca-atnum", "เปลี่ยนเลขอารบิกเป็นไทย", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addConvertToThaiNumber, false);
      else if (window.attachEvent) window.attachEvent("onload", addConvertToThaiNumber);
    }

    // ========== ไม้ยมก จัดชิดตัวหน้า  ==========
    // สคริปต์นี้ จัดไม้ยมก จาก "ก ๆ ก" เป็น "กๆ ก"
    function doConvertYamok() {
      text = document.editform.wpTextbox1.value;
      text = replace(text,' ๆ','ๆ');
      text = replace(text,'&nbsp;ๆ','ๆ');
      document.editform.wpTextbox1.value = text;
      document.editform.wpSummary.value = "แก้ไม้ยมก";
    }
    function addConvertYamok() {
      addTab("javascript:doConvertYamok()", "ๆ", "ca-yamok", "เปลี่ยนไม้ยมกจัดชิด", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addConvertYamok, false);
      else if (window.attachEvent) window.attachEvent("onload", addConvertYamok);
    }

    //========== Quick B+C+==========
    function doCreateBC() {
      var pagename;
      var opname;
      var textTemplate;
      var yearBC;
      var yearBC2;
      var yearBC3;
      var yearBC4;

      opname = getPname();
      pagename= opname.substring(11, opname.length);
      pagename = parseInt(pagename);

    yearBC = pagename;
    textTemplate = "{{กล่องปี พุทธศตวรรษที่ 1 |" + yearBC + "|" + (yearBC+1) + "|" + (yearBC+2) + "|" + (yearBC+3) + "|" + "0|" + (yearBC-1) + "|" + (yearBC-2) + "|" + (yearBC-3) + "|" + "0|0|";

    // BC decades
    yearBC2 = Math.floor(yearBC/10)*10;

    textTemplate = textTemplate + yearBC2 + "|" + (yearBC2+10) + "|" + (yearBC2+20) + "|" + (yearBC2+30) + "|" + "0|" + (yearBC2-10) + "|" + (yearBC2-20) + "|" + (yearBC2-30) + "|" + "0|0|";

    //AD decades
    yearBC2 = Math.floor((yearBC-543)/10)*10;
    textTemplate = textTemplate + yearBC2 + "|" + (yearBC2+10) + "|" + (yearBC2+20) + "|" + (yearBC2+30) + "|" + "0|" + (yearBC2-10) + "|" + (yearBC2-20) + "|" + (yearBC2-30) + "|" + "0|0|";

    // yearBC 3 Shortcut
    yearBC3 = Math.floor((yearBC-1)/100)+1;

    // BC century
    textTemplate = textTemplate + yearBC3 + "|" + (yearBC3+1) + "|" + "0|" + (yearBC3-1) + "|" + "0|";

    // AD century

    yearBC3 = Math.floor((543-yearBC)/100)+1;
    textTemplate = textTemplate + (yearBC3) + "|" + (yearBC3-1) + "|" + "0|" + (yearBC3+1) + "}}\n";

    /* yearBC3 = Math.floor((yearBC-543-1)/100)+1;
    textTemplate = textTemplate + (yearBC3) + "|" + (yearBC3+1) + "|" + "0|" + (yearBC3-1) + "}}\n";
    */

    //-------------------- DESCRIPTION ----------------------
    textTemplate = textTemplate + "'''พุทธศักราช " + yearBC + "''' ใกล้เคียงกับ ก่อน ค.ศ. " + (544 - yearBC);
    if (yearBC >= 621) {
     textTemplate = textTemplate +  "\n* [[มหาศักราช]] " + (yearBC -621);
    }

    //------------------ OTHER TOPIC -----------------------
    textTemplate = textTemplate + "\n\n==เหตุการณ์==\n\n==วันเกิด==\n\n==วันถึงแก่กรรม==\n\n{{โครงปี}}";

    //--cat
    textTemplate = textTemplate + "\n[[Category:พ.ศ. " + yearBC + "| ]]\n";

    //-- interlang
    yearBC4 = 544 - yearBC;
    textTemplate = textTemplate + "\n[[en:" + yearBC4 + " BC]]";

    /* interlang for year greater than 543 AD
    yearBC4 = yearBC - 543;
    textTemplate = textTemplate + "\n[[af:" + yearBC4 + "]]\n[[ast:" + yearBC4 + "]]\n[[bg:" + yearBC4 + "]]\n[[bs:" + yearBC4 + "]]\n[[ca:" + yearBC4 + "]]\n[[cv:" + yearBC4 + "]]\n[[cs:" + yearBC4 + "]]\n[[cy:" + yearBC4 + "]]\n[[da:" + yearBC4 + "]]\n[[de:" + yearBC4 + "]]\n[[en:" + yearBC4 + "]]\n[[et:" + yearBC4 + "]]\n[[el:" + yearBC4 + "]]\n[[es:" + yearBC4 + "]]\n[[eo:" + yearBC4 + "]]\n[[eu:" + yearBC4 + "]]\n[[fr:" + yearBC4 + "]]\n[[hr:" + yearBC4 + "]]\n[[io:" + yearBC4 + "]]\n[[it:" + yearBC4 + "]]\n[[lb:" + yearBC4 + "]]\n[[hu:" + yearBC4 + "]]\n[[mk:" + yearBC4 + "]]\n[[nl:" + yearBC4 + "]]\n[[no:" + yearBC4 + "]]\n[[nn:" + yearBC4 + "]]\n[[os:" + yearBC4 + "]]\n[[pl:" + yearBC4 + "]]\n[[pt:" + yearBC4 + "]]\n[[ro:" + yearBC4 + "]]\n[[ru:" + yearBC4 + "]]\n[[sk:" + yearBC4 + "]]\n[[sl:" + yearBC4 + "]]\n[[sr:" + yearBC4 + "]]\n[[fi:" + yearBC4 + "]]\n[[sv:" + yearBC4 + "]]\n[[tt:" + yearBC4 + "]]\n[[tr:" + yearBC4 + "]]\n[[uk:" + yearBC4 + "]]";
    */

     return (textTemplate);
    }

    function doQwikiBC() {
      document.editform.wpTextbox1.value =doCreateBC()+document.editform.wpTextbox1.value;
      document.editform.wpSummary.value = "สร้าง ปี พ.ศ. จาก [[วิกิพีเดีย:โครงการวันและปีอ้างอิง|สคริปต์]]";
    //  document.editform.submit();
    }

    function addQwikiBC() {
      addTab("javascript:doQwikiBC()", "สร้าง พ.ศ.", "ca-wikird", "สร้าง  พ.ศ.", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addQwikiBC, false);
      else if (window.attachEvent) window.attachEvent("onload", addQwikiBC);
    }

    // ========== Quick Redirect A.D. --> B.C.==========
    function doQwikirdadbc() {
      var pagename;
      var opname;
      opname = getPname(); //Ex "แก้ไข ค.ศ. 32"
      pagename= opname.substring(11, opname.length);
      pagename = parseInt(pagename);
      document.editform.wpTextbox1.value = "#REDIRECT [[พ.ศ. " + (pagename + 543) + "]]" + document.editform.wpTextbox1.value;
      document.editform.wpSummary.value = "Add redirect from ค.ศ. " + pagename + " to พ.ศ. " + (pagename + 543);
      document.editform.submit();
    }
    function addQwikirdadbc() {
      addTab("javascript:doQwikirdadbc()", "ค.ศ. -> พ.ศ.", "ca-wikird", "โยงค.ศ. ไปหา พ.ศ.", "");
      akeytt();
    }

    if (document.title.indexOf("แก้ไข ") == 0) {
      if (window.addEventListener) window.addEventListener("load", addQwikirdadbc, false);
      else if (window.attachEvent) window.attachEvent("onload", addQwikirdadbc);
    }

ดึงข้อมูลจาก "http://th.wikipedia.org../../../w/i/l/%E0%B8%9C%E0%B8%B9%E0%B9%89%E0%B9%83%E0%B8%8A%E0%B9%89%7EWillwill_monobook.js_86b3.html".

##### Views

- หน้าผู้ใช้
- อภิปราย
- รุ่นปัจจุบัน

##### ค้นหา