Greasy Fork

Greasy Fork is available in English.

135编辑器净化助手

用于135编辑器免登录开心使用样式与模板

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         135编辑器净化助手
// @namespace    https://www.qyccc.com/
// @version      0.10
// @description  用于135编辑器免登录开心使用样式与模板
// @author       公众号【干货老周】
// @match        https://www.135editor.com/*
// @grant        GM_xmlhttpRequest
// @connect      www.135editor.com
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (node.tagName === 'SCRIPT' &&
                    node.src.includes('https://www.135editor.com/js/advs/advs.js')) {
                    node.remove();
                }
            }
        }
    });
    observer.observe(document.documentElement, { childList: true, subtree: true });

    function waitForElement(selector, callback) {
        const timer = setInterval(() => {
            const el = document.querySelector(selector);
            if (el) {
                clearInterval(timer);
                callback(el);
            }
        }, 200);
    }

    function appendToIframe(html) {
        const iframe = document.querySelector('#ueditor_0');
        if (!iframe || !iframe.contentDocument) return;
        const body = iframe.contentDocument.body;

        const wrapper = document.createElement("div");
        wrapper.innerHTML = html;
        body.appendChild(wrapper);
    }

    function replaceIframe(html) {
        const iframe = document.querySelector('#ueditor_0');
        if (!iframe || !iframe.contentDocument) return;
        const body = iframe.contentDocument.body;

        body.innerHTML = "";
        const wrapper = document.createElement("div");
        wrapper.innerHTML = html;
        body.appendChild(wrapper);
    }

    function bindEditorTemplateClick() {
        const list = document.querySelector('#editor-template');
        if (!list) return;

        list.addEventListener('click', function(e) {
            const li = e.target.closest("li");
            if (!li) return;

            e.preventDefault();
            e.stopImmediatePropagation();

            const clone = li.cloneNode(true);
            clone.querySelectorAll(".vip-flag, .btns").forEach(x => x.remove());

            appendToIframe(clone.innerHTML);
        }, true);
    }

    function cleanTemplateList() {
        const list = document.querySelector("#template-list");
        if (!list) return;

        list.querySelectorAll(".col-md-6").forEach(col => {
            const actions = col.querySelector(".tpl-mask__actions");
            if (!actions) return;

            const targetDiv = actions.nextElementSibling;
            if (!targetDiv) return;

            const model = targetDiv.querySelector(".model_item");
            if (!model) return;

            const dataId = model.getAttribute("data-id") || "";
            const tuijian = model.getAttribute("data-tuijian") || "";

            targetDiv.innerHTML = "";
            targetDiv.appendChild(model);

            const btn = document.createElement("div");
            btn.className = "tpl_use_btn";
            btn.setAttribute("data-id", dataId);
            btn.setAttribute("data-tuijian", tuijian);
            btn.innerHTML = `
                <a href="javascript:void(0)" style="color:#fff;">
                    <i class="fa">使用</i>
                </a>
            `;
            targetDiv.appendChild(btn);
        });
    }

    function bindTplUseClick() {
        document.addEventListener("click", function(e) {
            const btn = e.target.closest(".tpl_use_btn");
            if (!btn) return;

            e.preventDefault();
            e.stopImmediatePropagation();

            const id = btn.getAttribute("data-id");
            if (!id) return;

            const url = `https://www.135editor.com/editor_styles/view_contribute/${id}.html?inajax=1&team_id=&source=bianjiqi`;
            console.log("正在请求模板内容:", url);

            GM_xmlhttpRequest({
                method: "GET",
                url,
                onload: function(res) {
                    const temp = document.createElement("div");
                    temp.innerHTML = res.responseText;

                    const content = temp.querySelector("#content-item");
                    if (!content) {
                        console.error("content-item未找到");
                        return;
                    }
                    replaceIframe(content.innerHTML);
                }
            });

        }, true);
    }

    function bindCopyIframeHTML() {
        waitForElement('#copy-editor-html', (btn) => {
            btn.id = "copy-tpl-html";
            btn.innerText = "复制使用";

            btn.addEventListener("click", function (e) {
                e.preventDefault();
                e.stopImmediatePropagation();

                const iframe = document.querySelector('#ueditor_0');
                if (!iframe) return alert('iframe 未找到');

                const doc = iframe.contentDocument || iframe.contentWindow.document;
                const html = doc.body.innerHTML;
                const text = doc.body.innerText;

                if (navigator.clipboard && window.ClipboardItem) {
                    const blobHtml = new Blob([html], { type: 'text/html' });
                    const blobText = new Blob([text], { type: 'text/plain' });

                    const item = new ClipboardItem({
                        'text/html': blobHtml,
                        'text/plain': blobText
                    });

                    navigator.clipboard.write([item])
                        .then(() => {
                        alert('已复制,可直接粘贴到公众号后台或网站中');
                    })
                        .catch(err => {
                        alert('复制失败,请检查浏览器权限');
                    });
                } else {
                    alert('当前浏览器不支持 Clipboard API');
                }
            }, true);
        });
    }
    bindCopyIframeHTML();
    waitForElement("#editor-template", bindEditorTemplateClick);
    waitForElement("#template-list", () => {
        cleanTemplateList();
        bindTplUseClick();
    });
})();