หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
// ========================================================
// สคริปต์จัดให้: editor module
//
// Copyright (C) 2006-2021, Jutiphan Mongkolsuthree
// 2021, Bebiezaza
// Certain functions are copyrighted by their
// respective copyright holders
//
// Created: 10/12/2006
// Rewritten: 27/10/2021
// Replaced: copyvio
//
// Additional Credits Information:
// ==============================================================
// Deluxe Summary:
//   * Author: Dake
//   * Contributions: Pabix, Tieno
//   * Revision: 12 November 2006
//   * Source: http://fr.wikipedia.org/wiki/Utilisateur:Huster/monobook.js
//   * Recommended by: User:Passawuth
//   * Rewritten: 27/10/2021
// ========================================================
/* <pre><nowiki> */

var resumedeluxeTitles = [];
var resumedeluxeInputs = [];

if (iScriptConfig.Edition == Editions.Wikipedia) {
    resumedeluxeTitles.push(
        "เก็บกวาด",
        "แจ้งต้องการอ้างอิง",
        "ใส่อ้างอิง",
        "ใส่เว็บย่อ",
        "ใส่กล่องข้อมูล",
        "ใส่ภาพ",
        "ปรับแก้ ขยายความ",
        "จัดหมวดหมู่",
        "ใส่โครง",
        "ใส่ลิงก์ข้ามภาษา");
    resumedeluxeInputs.push(
        "เก็บกวาด",
        "แจ้งต้องการอ้างอิง",
        "อ้างอิง",
        "เว็บย่อ",
        "กล่องข้อมูล",
        "ภาพ",
        "ปรับแก้ +เนื้อหา",
        "จัดหมวดหมู่",
        "โครง",
        "ลิงก์ข้ามภาษา");
} else if (iScriptConfig.Edition == Editions.Uncyclopedia) {
    resumedeluxeTitles.push(
        "เก็บกวาด",
        "แจ้งไม่ใช่เรื่องจริง",
        "ใส่เว็บย่อ",
        "ใส่กล่องข้อมูล",
        "ใส่ภาพ",
        "ปรับแก้ ขยายความ",
        "จัดหมวดหมู่",
        "ใส่โครง",
        "ใส่ลิงก์ข้ามภาษา");
    resumedeluxeInputs.push(
        "เก็บกวาด",
        "แจ้งไม่ใช่เรื่องจริง",
        "เว็บย่อ",
        "กล่องข้อมูล",
        "ภาพ",
        "ปรับแก้ +เนื้อหา",
        "จัดหมวดหมู่",
        "โครง",
        "ลิงก์ข้ามภาษา");
}

function addToSummary(summaryText, tagline) {
    var summary = document.editform.wpSummary.value;
    if (summary.length != 0) {
        if (tagline) {
            var taglineCheck = document.editform.wpSummary.value.indexOf(iScriptConfig.Tagline);
            if (taglineCheck != -1) {
                document.editform.wpSummary.value = summary.substring(0, taglineCheck) + " +" + summaryText + iScriptConfig.Tagline + summary.substring(taglineCheck + iScriptConfig.Tagline.length);
            } else document.editform.wpSummary.value += " +" + summaryText + iScriptConfig.Tagline;
        } else document.editform.wpSummary.value += " +" + summaryText;
    } else {
        if (tagline) document.editform.wpSummary.value += summaryText + iScriptConfig.Tagline
        else document.editform.wpSummary.value += summaryText;
    }
}

function deluxeSummary() {
    if (document.querySelector(".editOptions div") != document.getElementById("wpSummaryLabel")) return;
    var parent = document.getElementById("wpSummaryLabel");
    if (!parent) return;
    var content = "สรุปสิ่งที่คุณทำ: ";
    var container = createElement('div', content, {
    	'id': "deluxeSummary"
    });

    for (var i in resumedeluxeTitles) {
        var item = createElement('a', "", {
            'href': "javascript:addToSummary('" + resumedeluxeInputs[i] + "')",
            'title': "ใส่ \"" + resumedeluxeInputs[i] + "\" ในกล่องคำอธิบายอย่างย่อ"
        });
        item.innerHTML = resumedeluxeTitles[i];

        container.appendChild(item);
        container.innerHTML += " ";
    }
    
    parent.insertBefore(container, parent.firstChild);
}

function convertNumber() {
    text = document.editform.wpTextbox1.value;
    text = text.replace(/๑/ig, "1").replace(/๒/ig, "2").replace(/๓/ig, "3").replace(/๔/ig, "4").replace(/๕/ig, "5")
    .replace(/๖/ig, "6").replace(/๗/ig, "7").replace(/๘/ig, "8").replace(/๙/ig, "9").replace(/๐/ig, "0");
    
    if (text != document.editform.wpTextbox1.value) {
        document.editform.wpTextbox1.value = text;
        addToSummary("เปลี่ยนไปใช้เลขอารบิก", true);
    } else mw.notify('ยกเลิกการเปลี่ยนไปใช้เลขอารบิก เนื่องจากไม่จำเป็นที่จะต้องปรับเพิ่มเติม หรือไม่มีเลขไทยในหน้านี้');
}

function convertThaiNumber() {
    text = document.editform.wpTextbox1.value;
    text = text.replace(/1/ig, "๑").replace(/2/ig, "๒").replace(/3/ig, "๓").replace(/4/ig, "๔").replace(/5/ig, "๕")
    .replace(/6/ig, "๖").replace(/7/ig, "๗").replace(/8/ig, "๘").replace(/9/ig, "๙").replace(/0/ig, "๐");

    if (text != document.editform.wpTextbox1.value) {
        document.editform.wpTextbox1.value = text;
        addToSummary("เปลี่ยนไปใช้เลขไทย", true);
    } else mw.notify('ยกเลิกการเปลี่ยนไปใช้เลขไทยแล้ว เนื่องจากไม่จำเป็นที่จะต้องปรับเพิ่มเติม หรือไม่มีเลขอารบิกในหน้านี้');
}

function convertYamok() {
    var text = document.editform.wpTextbox1.value;
    text = text.replace(/([^\ ])ๆ/ig, "$1 ๆ"); // detect if no whitespaces before ๆ
    text = text.replace(/ๆ([^\ ])/ig, "ๆ $1"); // detect if no whitespaces after ๆ
    text = text.replace(/( {2,})ๆ/ig, " ๆ");   // detect if two or more whitespaces before ๆ
    text = text.replace(/ๆ( {2,})/ig, "ๆ ");   // detect if two or more whitespaces after ๆ
    
    if (text != document.editform.wpTextbox1.value) {
        document.editform.wpTextbox1.value = text;
        addToSummary("จัดรูปแบบไม้ยมก", true);
    } else mw.notify('ยกเลิกการจัดห่างไม้ยมกแล้ว เนื่องจากไม่จำเป็นที่จะต้องจัดเพิ่มเติม หรือไม่มีไม้ยมกในหน้านี้');
}

function lawSection(link) {
    var text = document.editform.wpTextbox1.value;
    if (link) text = text.replace(/\nมาตรา (.{1,5}) ?/ig, "\n{{กม|ม1|$1}}"); // capture up to five numbers in the section, it shouldn't be over that anyways
    else if (!link) text = text.replace(/\nมาตรา (.{1,5}) ?/ig, "\n{{กม|ม|$1}}"); // capture up to five numbers in the section, it shouldn't be over that anyways
    if (text != document.editform.wpTextbox1.value) {
        document.editform.wpTextbox1.value = text;
        addToSummary("จัดรูปแบบมาตราในเอกสารกฎหมาย", true);
    } else mw.notify('ยกเลิกการจัดรูปแบบมาตราในเอกสารกฎหมายแล้ว เนื่องจากไม่จำเป็นที่จะต้องจัดเพิ่มเติม หรือไม่มีมาตราในหน้านี้');
}

function lawBracket() {
    var text = document.editform.wpTextbox1.value;
    text = text.replace(/\n\((.{1,4})\) ?/ig, "\n{{กม|วล|$1}}"); // capture up to four numbers in the bracket, it shouldn't be over that anyways
    if (text != document.editform.wpTextbox1.value) {
        document.editform.wpTextbox1.value = text;
        addToSummary("จัดรูปแบบวงเล็บในเอกสารกฎหมาย", true);
    } else mw.notify('ยกเลิกการจัดรูปแบบวงเล็บในเอกสารกฎหมายแล้ว เนื่องจากไม่จำเป็นที่จะต้องจัดเพิ่มเติม หรือไม่มีวงเล็บในหน้านี้');
}

function copyViolated() {
    var source = prompt("กรุณาระบุแหล่งที่ถูกละเมิดลิขสิทธิ์:", "");
    if (source == "" || source == null) return mw.notify($('<span style="color: red">ยกเลิกการละเมิดลิขสิทธิ์แล้ว เนื่องจากไม่ได้ระบุแหล่งที่ถูกละเมิดลิขสิทธิ์</span>'));
    document.editform.wpTextbox1.value = "{{ละเมิดลิขสิทธิ์|url=" + source + "|วันที่={{subst:LOCALDAY2}}/{{subst:LOCALMONTH}}/" + getBEYear() + "}}";
    document.editform.wpSummary.value = "แจ้งละเมิดลิขสิทธิ์" + iScriptConfig.Tagline;
    document.editform.submit();
}

function replacetxt() {
    var a = getSelText();
    if (a == null || a.length == undefined || a.length == 0) {
        a = prompt("ระบุข้อความที่ต้องการจะแทนที่:" + "\n" + "(รองรับ Regex โดยให้ใส่ // นำหน้าและหลังสุด)", "")
    }
    if (a == null || a.length == 0) {
        return
    }
    var what_GUI = a;
    if (a.replace(/^\/\/(.*?)\/\/$/g, "$1") == a.split('//')[1]) {
        a = a.split('//')[1];
        replacetxtdone(a.split('//')[0], 1, a)
    } else {
        a = a.replace(/\\/g, "\\\\");
        a = a.replace(/\(/g, "\\(").replace(/\)/g, "\\)");
        a = a.replace(/\{/g, "\\{").replace(/\}/g, "\\}");
        a = a.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
        a = a.replace(/\|/g, "\\|");
        a = a.replace(/\./g, "\\.");
        a = a.replace(/\$/g, "\\$");
        a = a.replace(/\+/g, "\\+");
        a = a.replace(/\^/g, "\\^");
        a = a.replace(/\?/g, "\\?");
        a = a.replace(/\*/g, "\\*");
        a = a.replace(/\//g, "\\/");
        replacetxtdone(a, 0, what_GUI)
    }
}

function replacetxtdone(s, a, b) {
    var c = document.editform.wpTextbox1.value;
    if (s) {
        if (a == 1) {
            var r = prompt('ระบุคำที่จะแทนที่ "' + b + '" (ให้ใช้ Regex)', b)
        } else {
            var r = prompt('ระบุคำที่จะแทนที่ "' + b + '"', b)
        }
        if (!r && r != '') {
            return
        }
        if (r == '') {
            var d = confirm('ข้อความ "' + b + '" จะถูกลบทิ้งทั้งหมด คุณแน่ใจว่าต้องการทำเช่นนั้น?');
            if (!d) {
                return
            }
        }
        var e = document.editform.wpTextbox1;
        var f = RegExp(s, "g");
        e.value = e.value.replace(f, r).replace(/\\n/g, "\n");
        form = document.getElementById('bodyContent');
        l = form.getElementsByTagName('input');
        for (i = 0; i < l.length; i++) {
            if (l[i].name == 'wpMinoredit') {
                l[i].value = '1';
                l[i].checked = true
            }
        }
        if (document.editform.wpTextbox1.value == c) {
            alert('ขออภัย ข้อความที่ระบุไม่เจอในบทความ');
            return
        }
        if (document.editform.wpSummary.value.length == 0) {
            document.editform.wpSummary.value = 'แทนที่ "' + b + '" → "' + r + '" ' + iScriptConfig.Tagline
        } else {
            var g = document.editform.wpSummary.value.lastIndexOf(iScriptConfig.Tagline);
            if (g != -1) {
                var h = document.editform.wpSummary.value;
                document.editform.wpSummary.value = h.substring(0, g) + ' +แทนที่ "' + b + '" → "' + r + '" ' + iScriptConfig.Tagline
            } else {
                document.editform.wpSummary.value += ' +แทนที่ "' + b + '" → "' + r + '" ' + iScriptConfig.Tagline
            }
        }
    }
}

function convertYear() {
    var content = document.editform.wpTextbox1.value;
    var range = {
        start: document.editform.wpTextbox1.selectionStart,
        end: document.editform.wpTextbox1.selectionEnd
    }
    var selection = content.slice(range.start, range.end);
    var manual = false;

    if (selection == null || selection.length == 0) {
        selection = prompt("ระบุปี ค.ศ.:");
        manual = true;
    }
    if (selection == null || selection.length == 0) return;
    selection = selection.trim();

    // 1) ask for AD, return BE
    if (manual == true) {
        var year = parseInt(selection) + 543;
        var yearLegacy = parseInt(selection) + 542;
        if (year <= 2483) return alert("ค.ศ. " + selection + " เท่ากับ พ.ศ. " + yearLegacy + " สำหรับช่วงเดือนมกราคม - มีนาคม\nค.ศ. " + selection + " เท่ากับ พ.ศ. " + year + " สำหรับช่วงเดือนเมษายน - ธันวาคม");
        else return alert("ค.ศ. " + selection + " เท่ากับ พ.ศ. " + year);
    }

    // 5) convert months
    selection = selection.replace(/(January|February|March|April|May|June|July|August|September|October|November|December) (\d{1,2}(?!\d{1}))/ig, "$2 $1");
    selection = selection
                    .replace(/January/ig, "มกราคม")
                    .replace(/February/ig, "กุมภาพันธ์")
                    .replace(/March/ig, "มีนาคม")
                    .replace(/April/ig, "เมษายน")
                    .replace(/May/ig, "พฤษภาคม")
                    .replace(/June/ig, "มิถุนายน")
                    .replace(/July/ig, "กรกฎาคม")
                    .replace(/August/ig, "สิงหาคม")
                    .replace(/September/ig, "กันยายน")
                    .replace(/October/ig, "ตุลาคม")
                    .replace(/November/ig, "พฤศจิกายน")
                    .replace(/December/ig, "ธันวาคม");
    selection = selection.replace(/,/g, "");

    // helper
    selection = selection
                    .replace(/พ\.ศ\. ?(\d{1,4})/ig, "$1BE")
                    .replace(/ค\.ศ\. ?(\d{1,4})/ig, "$1AD")
                    .replace(/(\d{1,4}) ?(?:BC|BCE)/ig, "$1BC")
                    .replace(/(\d{1,4}) ?(?:AD|CE)/ig, "$1AD")
                    .replace(/BC\|\d{1,4}/ig, "LBC")
                    .replace(/(?:AD|CE)\|\d{1,4}/ig, "LAD")
                    .replace(/BE\|\d{1,4}/ig, "LBE")
                    .replace(/(\d{3,4}(?!AD|BC|BE|LAD|LBC|LBE|\d{1}))/ig, "$1AD");

    // convert AD to BE, check for precise conversion if possible
    var match = selection.match(/(\d{1,4})AD/ig);
    if (match) {
        for (var i in match) {
            var yearChrist = match[i];
            var year = parseInt(yearChrist) + 543;
            var yearLegacy = parseInt(yearChrist) + 542;
            var replacer = new RegExp(match[i], "ig");
            if (year <= 2483) {
                var monthCheck = new RegExp("(มกราคม|กุมภาพันธ์|มีนาคม) " + match[i], "ig");
                if (selection.match(monthCheck)) selection = selection.replace(monthCheck, "$1 พ.ศ. " + yearLegacy);
                selection = selection.replace(replacer, "พ.ศ. " + year);
            } else selection = selection.replace(replacer, "พ.ศ. " + year);
        }
    }
    
    // convert AD to BE with label
    match = selection.match(/(\d{1,4})LAD/ig);
    if (match) {
        for (var i in match) {
            var yearChrist = match[i];
            var year = parseInt(yearChrist) + 543;
            var replacer = new RegExp(match[i], "ig");
            selection = selection.replace(replacer, "พ.ศ. " + year + "|" + year);
        }
    }

    // change code style to normal for BE
    match = selection.match(/(\d{1,4})BE/ig);
    if (match) {
        for (var i in match) {
            var year = parseInt(match[i]);
            var replacer = new RegExp(match[i], "ig");
            selection = selection.replace(replacer, "พ.ศ. " + year);
        }
    }

    // change code style to normal for BE with label
    match = selection.match(/(\d{1,4})LBE/ig);
    if (match) {
        for (var i in match) {
            var year = parseInt(match[i]);
            var replacer = new RegExp(match[i], "ig");
            selection = selection.replace(replacer, "พ.ศ. " + year + "|" + year);
        }
    }
    
    // convert BC to BE
    match = selection.match(/(\d{1,4})BC/ig);
    if (match) {
        for (var i in match) {
            var yearChrist = match[i];
            var year = (parseInt(yearChrist) - 544) * -1;
            var replacer = new RegExp(match[i], "ig");
            if (year >= 0) {
                selection = selection.replace(replacer, "พ.ศ. " + year);
            } else {
                year *= -1;
                selection = selection.replace(replacer, year + " ปีก่อนพุทธศักราช");
            }
        }
    }

    // convert BC to BE with label
    match = selection.match(/(\d{1,4})LBC/ig);
    if (match) {
        for (var i in match) {
            var yearChrist = match[i];
            var year = (parseInt(yearChrist) - 544) * -1;
            var replacer = new RegExp(match[i], "ig");
            if (year >= 0) {
                selection = selection.replace(replacer, "พ.ศ. " + year + "|" + year);
            } else {
                year *= -1;
                selection = selection.replace(replacer, year + " ปีก่อนพุทธศักราช|" + year);
            }
        }
    }

    if (manual == false) {
        var text = content.slice(0, range.start) + selection + content.slice(range.end);
        document.editform.wpTextbox1.value = text;
    } else alert("การใช้งาน พ.ศ. อะไร มีปัญหาและไม่สามารถดำเนินการเสร็จสิ้นได้ กรุณาแจ้งที่ คุยกับผู้ใช้:Bebiezaza");
    return;
}

function transliterateWord() {
    var content = document.editform.wpTextbox1.value;
    var range = {
        start: document.editform.wpTextbox1.selectionStart,
        end: document.editform.wpTextbox1.selectionEnd
    }
    var selection = content.slice(range.start, range.end);
    var manual = false;
    
    if (selection == null || selection.length == 0) {
        selection = prompt("ระบุคำที่คุณต้องการทับศัพท์:");
        manual = true;
    }
    if (selection == null || selection.length == 0) return;
    selection = selection.trim();
    
    // API content fetch starts
    var translitList;
    $.ajax({
        url: "//th.wikipedia.org" + mw.util.wikiScript('api'),
        dataType: 'json',
        async: false,
        data: {
            format: 'json',
            action: 'query',
            prop: 'revisions',
            indexpageids: true,
            titles: "วิกิพีเดีย:โครงการคำทับศัพท์/คำทับศัพท์หมวด " + selection.charAt(0).toUpperCase(),
            rvprop: 'content',
            rvslots: 'main',
            origin: '*'
        },
        success: function(data) {
            var id = data.query.pageids[0];
            if (id == -1) {
                translitList = "";
            } else {
                translitList = data.query.pages[id].revisions[0].slots.main['*'];
            }
        }
    });
    // API content fetch end
    if (typeof translitList == "undefined") return mw.notify($('<span style="color: red">ขออภัย มีปัญหาในการดึงข้อมูลคำทับศัพท์ กรุณารอสักครู่และลองใหม่อีกครั้ง หากยังมีปัญหา กรุณาติดต่อผู้ใช้:Bebiezaza</span>'));
    
    var searcher = new RegExp("\n\\| ?" + selection + " ?\\|\\| ?\\[?\\[?(.*?)\\]?\\]? ?\\|\\|", "ig");
    var searchArray = searcher.exec(translitList);
    if (searchArray == null) return mw.notify($('<span style="color: red">ขออภัย คำที่คุณเรียกไม่ได้มีการระบุคำทับศัพท์ไว้บนวิกิพีเดียภาษาไทย<br>แก้ไขเพิ่มเติมได้ที่ WP:RFT</span>'));
    var searchResult = searchArray[1];
    if (manual == true) return alert(selection + " ทับศัพท์เป็น " + searchResult);
    else if (manual == false) {
        var text = content.slice(0, range.start) + searchResult + content.slice(range.end);
        document.editform.wpTextbox1.value = text;
    } else {
        alert("การใช้งานทับศัพท์ มีปัญหาและไม่สามารถดำเนินการเสร็จสิ้นได้ กรุณาแจ้งที่ คุยกับผู้ใช้:Bebiezaza");
    }
    return;
}

function customizeToolbar() {
    $('#wpTextbox1').wikiEditor('addToToolbar', {
        'section': 'main',
        'group': 'format',
        'tools': {
            'underline': {
                label: 'ขีดเส้นใต้',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/a/a1/OOjs_UI_icon_underline-a.svg',
                action: {
                    type: 'encapsulate',
                    options: { pre: "<u>", peri: "ข้อความขีดเส้นใต้", post: "</u>" }
                }
            }
        }
    });

    $('#wpTextbox1').wikiEditor('addToToolbar', {
        'section': 'main',
        'groups': {
            'iScript': {
                'label': ''
            }
        },
        
        'section': 'main',
        'group': 'iScript',
        'tools': {
            'cleanup': {
                label: 'เก็บกวาด',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/th/a/ab/VectorButton_Cleanup.png',
                action: {
                    type: 'callback',
                    execute: function(a) {
                        doCleanupTag()
                    }
                }
            },
            'replace': {
                label: 'แทนที่คำ',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/th/3/39/VectorButton_Replace.png',
                action: {
                    type: 'callback',
                    execute: function(a) {
                        replacetxt()
                    }
                }
            },
            'porsor': {
                label: 'พ.ศ.',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/th/6/6e/VectorButton_Porsor.png',
                action: {
                    type: 'callback',
                    execute: function(a) {
                        convertYear()
                    }
                }
            },
            'transliteration': {
                label: 'ทับศัพท์',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/th/c/cb/VectorButton_Transcribe.png',
                action: {
                    type: 'callback',
                    execute: function(a) {
                        transliterateWord()
                    }
                }
            }
        }
    });
};

$(document).ready(function() {
    if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) !== -1) {
        deluxeSummary();

        addTab("javascript:convertNumber()", "๒ → 2", "ca-tanum", "เปลี่ยนเลขไทยเป็นอารบิก");
        addTab("javascript:convertThaiNumber()", "2 → ๒", "ca-atnum", "เปลี่ยนเลขอารบิกเป็นไทย");
        addTab("javascript:convertYamok()", "ๆ", "ca-yamok", "จัดรูปแบบไม้ยมก");
        addTab("javascript:copyViolated()", "ละเมิด", "ca-vio", "แจ้งละเมิดลิขสิทธิ์");

        if(iScriptConfig.Edition == Editions.Wikisource) {
            addTab("javascript:lawSection(false)", "จัดกฎหมาย → มาตรา", "ca-lawsection", "จัดรูปแบบมาตราในเอกสารกฎหมาย");
            addTab("javascript:lawSection(true)", "จัดกฎหมาย → มาตรา+ลิงก์", "ca-lawsectionL", "จัดรูปแบบมาตราในเอกสารกฎหมาย พร้อมลิงก์ไปยังสารบัญ");
            addTab("javascript:lawBracket()", "จัดกฎหมาย → วงเล็บ", "ca-lawbracket", "จัดรูปแบบวงเล็บในเอกสารกฎหมาย");
        }
        
        /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
        mw.loader.using('user.options').then( function () {
            // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
            if (mw.user.options.get('usebetatoolbar') == 1 ) {
                $.when(
                    mw.loader.using('ext.wikiEditor'), $.ready
                ).then(customizeToolbar);
            }
        });
    }
});

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