关键词叠词生成器

输入关键词生成组合叠词

目前為 2024-11-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         关键词叠词生成器
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  输入关键词生成组合叠词
// @author       You
// @match        https://www.amazon.com/*
// @match        https://www.amazon.co.uk/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 创建样式,确保元素显示并美化
    GM_addStyle(`
        #wordGeneratorContainer {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 9999;
            background-color: #f9f9f9;
            padding: 20px;
            border: 2px solid #ccc;
            border-radius: 15px;
            box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
            display: none;
            font-family: 'Arial', sans-serif;
            transition: all 0.3s ease;
            width: auto;
            max-width: 500px;
            min-width: 300px;
        }

        #wordGeneratorContainer .inputRow {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            margin-bottom: 10px;
        }

        #wordGeneratorContainer input,
        #wordGeneratorContainer button {
            margin: 5px;
            padding: 12px 18px;
            font-size: 16px;
            border-radius: 8px;
            border: 1px solid #ccc;
            outline: none;
            transition: border 0.3s ease;
            width: 48%;
        }

        #wordGeneratorContainer input:focus,
        #wordGeneratorContainer button:hover {
            border-color: #0073e6;
        }

        #outputArea {
            white-space: pre-wrap;
            word-wrap: break-word;
            margin-top: 15px;
            border: 1px solid #ddd;
            padding: 15px;
            background-color: #f4f4f4;
            min-height: 150px;
            max-height: 200px;
            overflow-y: auto;
            border-radius: 8px;
        }

        #openGeneratorButton {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #0073e6;
            color: white;
            padding: 15px 20px;
            font-size: 20px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            z-index: 9999;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            transition: transform 0.2s ease;
        }

        #openGeneratorButton:hover {
            transform: scale(1.1);
        }

        #closeButton {
            position: absolute;
            top: 5px;
            right: 5px;
            background-color: #ff3b3b;
            color: white;
            padding: 8px 12px;
            font-size: 14px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
            transition: background-color 0.3s ease;
        }

        #closeButton:hover {
            background-color: #d32f2f;
        }

        #clearButton {
            background-color: #ff9800;
            color: white;
            padding: 8px 12px;
            font-size: 16px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            width: 48%;
        }

        #clearButton:hover {
            background-color: #f57c00;
        }

        #generateButton {
            background-color: #4caf50;
            color: white;
            padding: 8px 12px;
            font-size: 16px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            width: 48%;
        }

        #generateButton:hover {
            background-color: #388e3c;
        }

        #copyButton {
            background-color: #0073e6;
            color: white;
            padding: 8px 12px;
            font-size: 16px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            width: 48%;
        }

        #copyButton:hover {
            background-color: #005bb5;
        }
    `);

    // 创建生成器容器
    const container = document.createElement('div');
    container.id = 'wordGeneratorContainer';

    const inputRow = document.createElement('div');
    inputRow.classList.add('inputRow');

    const inputBox = document.createElement('input');
    inputBox.type = 'text';
    inputBox.placeholder = '输入关键词';

    const generateButton = document.createElement('button');
    generateButton.textContent = '生成叠词';
    generateButton.id = 'generateButton';

    const copyButton = document.createElement('button');
    copyButton.textContent = '一键复制';
    copyButton.id = 'copyButton';

    const clearButton = document.createElement('button');
    clearButton.textContent = '清空';
    clearButton.id = 'clearButton';

    const outputArea = document.createElement('pre');
    outputArea.id = 'outputArea';

    const closeButton = document.createElement('button');
    closeButton.textContent = '×';
    closeButton.id = 'closeButton';

    // 将元素添加到容器
    inputRow.appendChild(inputBox);
    inputRow.appendChild(generateButton);
    inputRow.appendChild(copyButton);
    inputRow.appendChild(clearButton);

    container.appendChild(inputRow);
    container.appendChild(outputArea);
    container.appendChild(closeButton);

    // 将容器添加到页面中
    document.body.appendChild(container);

    // 创建触发弹出的按钮
    const openGeneratorButton = document.createElement('button');
    openGeneratorButton.textContent = '叠';
    openGeneratorButton.id = 'openGeneratorButton';

    // 将触发按钮添加到页面
    document.body.appendChild(openGeneratorButton);

    // 生成叠词组合
    function generateCombinations(input) {
        const words = input.trim().split(' ');
        const length = words.length;
        let combinations = [];

        if (length === 2) {
            // 处理 AB 形式
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[0]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[1]}`);
        } else if (length === 3) {
            // 处理 ABC 形式
            combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[0]} ${words[1]} ${words[2]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[2]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[2]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[1]} ${words[2]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[2]}`);
        } else if (length === 4) {
            // 处理 ABCD 形式
            combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[3]} ${words[0]} ${words[1]} ${words[2]} ${words[3]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[2]} ${words[3]} ${words[3]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[2]} ${words[3]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[3]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[2]} ${words[3]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[3]} ${words[3]}`);
        }

        return combinations.join('\n');
    }

    // 生成叠词按钮点击事件
    generateButton.addEventListener('click', () => {
        const input = inputBox.value;
        if (input) {
            outputArea.textContent = generateCombinations(input);
        } else {
            outputArea.textContent = '请输入关键词!';
        }
    });

    // 复制按钮点击事件
    copyButton.addEventListener('click', () => {
        const textToCopy = outputArea.textContent;
        if (textToCopy) {
            navigator.clipboard.writeText(textToCopy);
        } else {
            alert('没有生成叠词可复制!');
        }
    });

    // 打开生成器按钮点击事件
    openGeneratorButton.addEventListener('click', () => {
        container.style.display = 'block';  // 显示生成器
    });

    // 关闭按钮点击事件
    closeButton.addEventListener('click', () => {
        container.style.display = 'none';  // 隐藏生成器
    });

    // 清空输入框按钮点击事件
    clearButton.addEventListener('click', () => {
        inputBox.value = '';  // 清空输入框内容
        outputArea.textContent = '';  // 清空输出区域
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址