Greasy Fork

Greasy Fork is available in English.

美化版关键词叠词生成器

输入关键词生成组合叠词,视觉体验更佳

当前为 2024-11-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         美化版关键词叠词生成器
// @namespace    http://tampermonkey.net/
// @version      1.3
// @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: linear-gradient(135deg, #0073e6, #4c83ff);
            padding: 20px;
            border-radius: 20px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
            font-family: 'Arial', sans-serif;
            color: #fff;
            text-align: center;
            animation: fadeIn 0.5s ease;
            width: auto;
            max-width: 500px;
            min-width: 320px;
        }

        #wordGeneratorContainer input {
            width: 90%;
            padding: 10px;
            margin-top: 10px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 8px;
            outline: none;
        }

        #outputArea {
            white-space: pre-wrap;
            word-wrap: break-word;
            margin-top: 15px;
            border: 1px solid #ddd;
            padding: 15px;
            background-color: rgba(255, 255, 255, 0.1);
            min-height: 100px;
            max-height: 150px;
            overflow-y: auto;
            border-radius: 8px;
        }

        button {
            margin: 10px 5px;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 25px;
            border: none;
            cursor: pointer;
            transition: transform 0.2s, background-color 0.3s;
        }

        button:hover {
            transform: scale(1.1);
            background-color: rgba(255, 255, 255, 0.2);
        }

        #generateButton {
            background-color: #34c759;
            color: white;
        }

        #copyButton {
            background-color: #007aff;
            color: white;
        }

        #clearButton {
            background-color: #ff9500;
            color: white;
        }

        #closeButton {
            position: absolute;
            top: -10px;
            right: -10px;
            background-color: #ff3b30;
            color: white;
            padding: 8px 12px;
            font-size: 14px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
        }

        #openGeneratorButton {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background: radial-gradient(circle, #0073e6, #4c83ff);
            color: white;
            padding: 15px;
            font-size: 20px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            z-index: 9999;
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.2);
            animation: pulse 1.5s infinite;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translate(-50%, -55%);
            }
            to {
                opacity: 1;
                transform: translate(-50%, -50%);
            }
        }

        @keyframes pulse {
            0%, 100% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.1);
            }
        }
    `);

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

    const inputBox = document.createElement('input');
    inputBox.type = 'text';
    inputBox.placeholder = '请输入关键词,2-4个用空格分隔';

    const buttonRow = document.createElement('div');
    buttonRow.style.display = 'flex';
    buttonRow.style.justifyContent = 'space-around';

    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 closeButton = document.createElement('button');
    closeButton.textContent = '×';
    closeButton.id = 'closeButton';

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

    buttonRow.appendChild(generateButton);
    buttonRow.appendChild(copyButton);
    buttonRow.appendChild(clearButton);

    container.appendChild(closeButton);
    container.appendChild(inputBox);
    container.appendChild(buttonRow);
    container.appendChild(outputArea);
    document.body.appendChild(container);

    // 显示生成器按钮
    const openGeneratorButton = document.createElement('button');
    openGeneratorButton.id = 'openGeneratorButton';
    openGeneratorButton.textContent = '+';
    document.body.appendChild(openGeneratorButton);

    // 生成叠词
    function generateCombinations(input) {
        const words = input.trim().split(/\s+/);
        const length = words.length;

        if (length < 2 || length > 4) {
            return '请输入 2 到 4 个关键词!';
        }

        const combinations = [];

        // AB式
        if (length === 2) {
            combinations.push(`${words[0]} ${words[1]} ${words[0]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[0]} ${words[1]}`);
            combinations.push(`${words[0]} ${words[1]} ${words[1]}`);
        }

        // ABC式
        if (length === 3) {
            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]}`);
        }

        // ABCD式
        if (length === 4) {
            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;
        outputArea.textContent = generateCombinations(input) || '请输入关键词!';
    });

    copyButton.addEventListener('click', () => {
        const textToCopy = outputArea.textContent;
        if (textToCopy) {
            navigator.clipboard.writeText(textToCopy);
            alert('复制成功!');
        } else {
            alert('没有内容可复制!');
        }
    });

    clearButton.addEventListener('click', () => {
        inputBox.value = '';
        outputArea.textContent = '';
    });

    closeButton.addEventListener('click', () => {
        container.style.display = 'none';
    });

    openGeneratorButton.addEventListener('click', () => {
        container.style.display = 'block';
    });
})();