Greasy Fork

Greasy Fork is available in English.

千川创意标题自动填写(精准button版)

自动根据标题行数点击“添加标题”按钮并填写内容(最多30个)

当前为 2025-10-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @license MIT
// @name         千川创意标题自动填写(精准button版)
// @namespace    http://tampermonkey.net/
// @version      3.3
// @description  自动根据标题行数点击“添加标题”按钮并填写内容(最多30个)
// @match        https://qianchuan.jinritemai.com/creation/uni-prom-product*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const WAIT_MS = 1500;

    setTimeout(() => {
        // 左下角悬浮面板
        const panel = document.createElement('div');
        panel.innerHTML = `
            <div id="autoFillPanel" style="
                position: fixed;
                bottom: 30px;
                left: 30px;
                z-index: 99999;
                background: rgba(0,0,0,0.85);
                color: #fff;
                border-radius: 10px;
                padding: 14px 16px;
                width: 280px;
                font-family: sans-serif;
                box-shadow: 0 0 12px rgba(0,0,0,0.4);
            ">
                <div style="margin-bottom:8px;text-align:center;font-size:14px;">创意标题自动填写</div>
                <textarea id="fillTextArea" placeholder="请输入多个标题,每行一个(最多30个)" style="
                    width:100%;
                    height:130px;
                    padding:6px 8px;
                    border-radius:6px;
                    border:none;
                    outline:none;
                    resize:none;
                    font-size:13px;
                    margin-bottom:10px;
                "></textarea>
                <button id="startFillBtn" style="
                    width:100%;
                    background:#4CAF50;
                    color:white;
                    border:none;
                    border-radius:6px;
                    padding:8px 12px;
                    font-size:14px;
                    cursor:pointer;
                ">开始自动填写</button>
            </div>
        `;
        document.body.appendChild(panel);
        // 恢复上次输入内容
        const textarea = document.getElementById('fillTextArea');
        textarea.value = localStorage.getItem('qianchuan_titles') || '';

        // 每次输入时自动保存
        textarea.addEventListener('input', () => {
            localStorage.setItem('qianchuan_titles', textarea.value);
        });


        // 点击逻辑
        document.getElementById('startFillBtn').addEventListener('click', async () => {
            const rawText = document.getElementById('fillTextArea').value.trim();
            if (!rawText) {
                alert("请输入标题内容(每行一个)!");
                return;
            }

            let titles = rawText.split(/\r?\n/).map(t => t.trim()).filter(t => t.length > 0);
            if (titles.length === 0) {
                alert("请输入有效标题!");
                return;
            }

            if (titles.length > 30) {
                alert("标题过多,只会使用前30个。");
                titles = titles.slice(0, 30);
            }

            // ✅ 查找“添加标题”按钮(精准匹配 class + data-e2e + 文本)
            const allButtons = Array.from(document.querySelectorAll('button.ovui-button[data-e2e="button"]'));
            const addButton = allButtons.find(btn => btn.innerText.trim() === '添加标题');

            if (!addButton) {
                alert("未找到“添加标题”按钮,请确认页面是否加载完成。");
                console.warn("脚本:未找到包含‘添加标题’文字的 button。");
                return;
            }

            // 自动点击“添加标题”
            for (let i = 0; i < titles.length; i++) {
                addButton.click();
                console.log(`➕ 已点击添加标题 (${i + 1}/${titles.length - 1})`);
                await new Promise(r => setTimeout(r, 50));
            }

            // 等待输入框加载
            await new Promise(r => setTimeout(r, 1200));

            // 查找输入框
            const inputSelector = 'div[data-e2e*="uni-prom-product__creativeTitle__ocInput"] input.ovui-input';
            const inputs = document.querySelectorAll(inputSelector);

            if (inputs.length === 0) {
                alert("未找到创意标题输入框!");
                console.warn("脚本:输入框未加载。");
                return;
            }

            const fillCount = Math.min(inputs.length, titles.length);
            for (let i = 0; i < fillCount; i++) {
                const input = inputs[i];
                const text = titles[i];
                input.focus();
                input.value = text;
                input.dispatchEvent(new Event('input', { bubbles: true }));
                input.dispatchEvent(new Event('change', { bubbles: true }));
                console.log(`✅ 第 ${i + 1} 个标题已填写: ${text}`);
                await new Promise(r => setTimeout(r, 100));
            }

            alert(`已成功添加并填写 ${fillCount} 个标题!`);
        });
    }, WAIT_MS);

})();