为方便MediaWiki 的编辑,2017年前后,我在网上找到Mr.Gidot 开发的排版助手Web 程序,但加载较慢,我便将整个程序下载并部署到自己的站点,美化界面,保留原作者的信息。

经常使用的功能:

  1. 段间空一行/段间无空行;
  2. 删着尾空格;
  3. 修定标点;

昨天发现作者网站已经无法打开,跳转之后的内容甚不健康,遂修定页面,顺手修正默认选项,增加一键复制内容。

标点修正的选项,通过HTML 定义无效,因为JavaScript 中重新设置了。

//gt.js
this.minceOption_0('xx_bd', 'option0', true);
this.minceOption_0('xx_blx', 'option1', true);

复制textarea 内容的代码,也是从网上找的:

function copyToClipboard(elem) {
    // create hidden text element, if it doesn't already exist
    var targetId = "_hiddenCopyText_";
    var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
    var origSelectionStart, origSelectionEnd;
    if (isInput) {
        // can just use the original source element for the selection and copy
        target = elem;
        origSelectionStart = elem.selectionStart;
        origSelectionEnd = elem.selectionEnd;
    } else {
        // must use a temporary form element for the selection and copy
        target = document.getElementById(targetId);
        if (!target) {
            var target = document.createElement("textarea");
            target.style.position = "absolute";
            target.style.left = "-9999px";
            target.style.top = "0";
            target.id = targetId;
            document.body.appendChild(target);
        }
        target.textContent = elem.textContent;
    }
    // select the content
    var currentFocus = document.activeElement;
    target.focus();
    target.setSelectionRange(0, target.value.length);

    // copy the selection
    var succeed;
    try {
        succeed = document.execCommand("copy");
    } catch (e) {
        succeed = false;
    }
    // restore original focus
    if (currentFocus && typeof currentFocus.focus === "function") {
        currentFocus.focus();
    }

    if (isInput) {
        // restore prior selection
        elem.setSelectionRange(origSelectionStart, origSelectionEnd);
    } else {
        // clear temporary content
        target.textContent = "";
    }
    return succeed;
}


function copy() {
    copyToClipboard(document.getElementById("textbox"));
    //alert("复制成功!");
    tip(128, "复制成功!");
}

默认alert 提示,改为模拟tip:

function tip(pWidth, content) {
    $("#msg").remove();
    var html = '<div id="msg" style="position:fixed;top:50%;width:100%;height:30px;line-height:30px;margin-top:-15px;"><p style="background:#666;opacity:0.8;width:' + pWidth + 'px;color:#fff;text-align:center;padding:10px 10px;margin:0 auto;font-size:12px;border-radius:4px;">' + content + '</p></div>'
    $("body").append(html);
    var t = setTimeout(next, 2000);
    function next() {
        $("#msg").remove();

    }
}

最终效果:这里,我就是个代码裁缝。

最后修改:2022 年 11 月 02 日
如果觉得我的文章对你有用,请随意赞赏