New script kylebing.cn

1/8/2024, 12:18:59 PM

12.01.2024 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        New script kylebing.cn
// @namespace   Violentmonkey Scripts
// @match       https://kylebing.cn/tools/typepad/*
// @grant       none
// @version     1.0
// @author      -
// @description 1/8/2024, 12:18:59 PM
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    // 定义加载文件的函数
    function loadTextFile() {
        var fileInput = document.createElement('input');
        fileInput.type = 'file';
        fileInput.accept = 'text/plain';
        fileInput.style.display = 'none';

        fileInput.onchange = function(e) {
            var file = e.target.files[0];
            if (file) {
                var reader = new FileReader();
                var filename = e.target.files[0].name;
                console.log(filename);
                reader.onload = function(e) {
                    var editor = document.getElementById('editor');
                    if (editor) {
                        editor.value = e.target.result;
                    }
                    var titleedit = document.getElementsByClassName("editor-title")[0];
                    if (titleedit) {
                        titleedit.value = filename.split(".")[0];
                    }
                };
                reader.readAsText(file, 'UTF-8');
            }
            fileInput.remove();
        };

        document.body.appendChild(fileInput);
        fileInput.click();
    }

    // 创建按钮
    var btn = document.createElement('div');
    btn.className = 'btn';
    btn.id = "selectfile";
    btn.textContent = '加载文本文件';
    btn.addEventListener("click", function(){
      loadTextFile();
    });

    var observer = new MutationObserver(function(mutations, me) {
    var editor = document.getElementById('editor');
    if (editor) {
        var parentCont = document.getElementsByClassName("editor-toolbar")[0];
        var buttonGroup = document.createElement("div");
        buttonGroup.className = "btn-group";
        buttonGroup.appendChild(btn);
        parentCont.appendChild(buttonGroup);
        console.log("injected!!");
        me.disconnect(); // 停止观察
        return;
    }
});
    var config = { childList: true, subtree: true };
    var target = document.body;
    observer.observe(target, config);


    // TODO: 将按钮添加到页面的合适位置
    // 例如:
    // var container = document.querySelector('.your-container-selector');
    // container.appendChild(btn);
})();