<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
var englishItalic = 0;
var multipleMode = false;
function italic () {
    let selectedElements = getSelected();
    for(var idx=0; idx &lt; selectedElements.length; idx++) {
        let target = selectedElements[idx];
        addItalic(target);
    }
}

function addItalic (target, addOnly = false) {
    if (target.textContent.replace(/\u00a0/g, "") == "" || target.textContent == " ") {
        return false;
    }
    let currentStyle = window.getComputedStyle(target);
    $(".btn-save").prop("disabled", false);
    if (target.getAttribute("italic") == null) {
        target.setAttribute("origin-italic", currentStyle.fontStyle);
    }
    if (currentStyle.fontStyle == "italic" &amp;&amp; addOnly == false) {
        target.style.fontStyle = "normal";
        target.setAttribute("italic", false);
        if (multipleMode == false) {
            addHistory(historyVar["italic"], [target.id], ["italic", true]);
        }
        // if (target.getAttribute("origin-italic") == "normal") target.removeAttribute("style-change");
        // else target.setAttribute("style-change", true);
    } else if (currentStyle.fontStyle == "normal"){
        target.style.fontStyle = "italic";
        target.setAttribute("italic", true);
        addHistory(historyVar["italic"], [target.id], ["normal", false]);
        if ( target.classList.contains("greentxt") ) {
            englishItalic++;
            if (englishItalic == 2) {
                Swal.fire({
                    // title: 'Are you sure?',
                    html: "&lt;div style='font-size: 16px'&gt;Apakah kamu ingin mengubah semua bahasa inggris menjadi italic?&lt;/div&gt;",
                    icon: 'warning',
                    showCancelButton: true,
                    heightAuto: false,
                    focusConfirm: true,
                    scrollbarPadding: false,
                    allowOutsideClick: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: 'rgb(183 180 180)',
                    cancelButtonText: '&lt;div style="font-size: 16px"&gt;Cancel&lt;/div&gt;',
                    confirmButtonText: '&lt;div style="font-size: 16px"&gt;Ok&lt;/div&gt;'
                }).then((result) =&gt; {
                    if (result.value) {
                        let changeCount = 0;
                        let failCount = 0;
                        let elements = $(".greentxt");
                        let eleLen = elements.length;
                        multipleMode = true;
                        let allId = []
                        for (let eleIdx =0; eleIdx &lt; eleLen; eleIdx++ ) {
                            if (addItalic(elements[eleIdx], true)) {
                                allId.push(elements[eleIdx].id)
                                changeCount++;
                            } else {
                                failCount++;
                            }
                        };
                        addHistory(historyVar["italic"], ids, ["normal", false]);
                        multipleMode = false;
                        console.log("result is success", changeCount, "fail", failCount);
                        show_toast("success", changeCount + " bahasa ingggris telah berhasil diubah menjadi italic");
                    }
                });
            }
        }
    } else {
        return false;
    }
    return true;
}

function getSelected() {
    var sel = "";
    if (window.getSelection) {
      sel = window.getSelection();
    } else if (document.getSelection) {
      sel = document.getSelection();
    } else if (document.selection) {
      sel = document.selection.createRange().text;
    }
    var selectedNodes = [];
    // console.log("count", sel, sel.childNodes);
    if (sel.rangeCount == 0) return false;
    for (var i = 0; i &lt; sel.rangeCount; ++i) {
        let range = sel.getRangeAt(i);
        // console.log("sel start", range, range.startContainer.parentNode, range.startContainer);
        // console.log("sel end", range, range.endContainer.parentNode, range.endContainer);
        startIdPart = range.startContainer.parentNode.id.split("_");
        endIdPart = range.endContainer.parentNode.id.split("_");
        if (startIdPart.length == 3 &amp;&amp; endIdPart.length == 3) {
            if (startIdPart[2] == endIdPart[2]) {
                selectedNodes.push($("#"+startIdPart.join("_"))[0]);
                continue;
            }
            // console.log("trigger");
            let idx = startIdx = parseInt(startIdPart[2].replace("K","").replace("O","").replace("R",""));
            let endIdx = parseInt(endIdPart[2].replace("K","").replace("O","").replace("R",""));

            // Start area
            // console.log(startIdPart, startIdPart[2][0]);
            if (startIdPart[2][0] == "R") {
              ele = $("[id$='"+"R" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            } else if (startIdPart[2][0] == "K") {
              ele = $("[id$='"+"R" + startIdx + "']");
            //   console.log("start part ", "[id$='"+"R" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='"+"K" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            } else if (startIdPart[2][0] == "O") {
              ele = $("[id$='"+"O" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='" + "K" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='" + "R" + startIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            } 

            // Middle Area
            for (idx = idx + 1; idx &lt; endIdx; idx++) {
              let char = ["O", "K", "R"];
              for (charIdx = 0; charIdx &lt; 3; charIdx++) {
                ele = $("[id$='" + char[charIdx] + idx + "']");
                // console.log("ele get", ele[0]);
                if (ele[0]) selectedNodes.push(ele[0]);
              }
            }

            // End Area
            if (endIdPart[2][0] == "O") {
              ele = $("[id$='" + "O" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            } else if (endIdPart[2][0] == "K") {
              ele = $("[id$='" + "O" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='" + "K" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            } else if (endIdPart[2][0] == "R") {
              ele = $("[id$='" + "O" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='" + "K" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
              ele = $("[id$='" + "R" + endIdx + "']");
              if (ele[0]) selectedNodes.push(ele[0]);
            }
        }

        // selectedNodes = selectedNodes.concat(sel.getRangeAt(i).getNodes());
    }
    return selectedNodes;
}

function bold() {
    let selectedElements = getSelected();
    for(var idx=0; idx &lt; selectedElements.length; idx++) {
        let target = selectedElements[idx];
        if (target.textContent.replace(/\u00a0/g, "") == "" || target.textContent == " ") {
            continue;
        }
        let currentStyle = window.getComputedStyle(target);
        let fontWeight = currentStyle.fontWeight;
        console.log("font weigth", currentStyle.fontWeight);
        $(".btn-save").prop("disabled", false);
        if (currentStyle.fontWeight &gt;= 500) {
            fontWeight = "bold";
        }
        
        if (target.getAttribute("bold") == null) {
            target.setAttribute("origin-bold", fontWeight);
        }
        if (fontWeight == "bold") {
            target.style.fontWeight = "normal";
            target.setAttribute("bold", false);
            addHistory(historyVar["bold"], [target.id], ["bold", true]);
            // if (target.getAttribute("origin-bold") != "bold") target.removeAttribute("style-change");
            // else target.setAttribute("style-change", true);
        } else {
            console.log("font style before");
            target.style.fontWeight = "bold";
            target.setAttribute("bold", true);
            addHistory(historyVar["bold"], [target.id], ["normal", false]);
            // if (target.getAttribute("origin-bold") == "bold") target.removeAttribute("style-change");
            // else target.setAttribute("style-change", true);
        }
    }
}

let tmp_find_index = -1;
let tmp_find_text = "";
let tmp_highlight;
$(".find-word").on("keydown", function(e) {
    if (e.keyCode == 13) {
        let elements = $("[origin='" + $(this).val().toLowerCase() + "']");
        let target;
        if ($(this).val() != tmp_find_text) {
            tmp_find_index = 0;
            tmp_find_text = $(this).val();
        } else {
            if (tmp_find_index+1 &lt; elements.length)
                tmp_find_index++;
            else
                tmp_find_index = 0;
        }

        if (tmp_highlight) tmp_highlight.classList.remove("find-target");
        target = elements[tmp_find_index];
        if (!target) return false;
        target.classList.add("find-target");
        tmp_highlight = target;
        $("html, body").animate({ scrollTop: target.offsetTop-250 }, 240);
    }
});

function findAndReplace() {
    let elements = $(
        "[origin='" + $(".find-word").val().toLowerCase() + "']"
    );
    let target;

    if ($(".find-word").val() != tmp_find_text) {
        tmp_find_index = 0;
        tmp_find_text = $(".find-word").val();
    } else {
        tmp_highlight.textContent = $(".replace-word").val();
        textChanged(tmp_highlight, $(".find-word").val(), true);
        elements.splice(tmp_find_index, 1);
    }
    target = elements[tmp_find_index];
    console.log("target", target);
    if (tmp_highlight) tmp_highlight.classList.remove("find-target");

    if (!target) return false;
    target.classList.add("find-target");
    tmp_highlight = target;
    $("html, body").animate({ scrollTop: target.offsetTop - 250 }, 240);
}

$(".replace-word").on("keydown", function(e) {
    if (e.keyCode == 13) {
        findAndReplace();
    }
});
$(".replace-single").on("mousedown", function(e) {
    findAndReplace();
});

$(".replace-all").on("mousedown", function(e) {
    changetext($(".find-word").val(), $(".replace-word").val());
});

function toggleSearch() {
    $(".find-replace").toggle();
    $(".find-target").removeClass("find-target");
    tmp_find_index = "";
    tmp_find_text = "";
}</pre></body></html>