关键词叠词生成器

输入关键词生成组合叠词并添加复制按钮,显示在亚马逊美国站导航栏

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

// ==UserScript==
// @name         关键词叠词生成器
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  输入关键词生成组合叠词并添加复制按钮,显示在亚马逊美国站导航栏
// @author       You
// @match        https://www.amazon.com/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 检查页面是否为亚马逊美国站
    if (!window.location.href.includes('amazon.com')) {
        return;
    }

    // 插入输入框、生成按钮、输出区域
    const inputBox = document.createElement('input');
    inputBox.type = 'text';
    inputBox.style.width = '300px';
    inputBox.style.padding = '8px';
    inputBox.style.margin = '10px';

    const generateButton = document.createElement('button');
    generateButton.textContent = '生成叠词';
    generateButton.style.padding = '8px 16px';
    generateButton.style.margin = '10px';

    const copyButton = document.createElement('button');
    copyButton.textContent = '一键复制';
    copyButton.style.padding = '8px 16px';
    copyButton.style.margin = '10px';

    const outputArea = document.createElement('pre');
    outputArea.style.whiteSpace = 'pre-wrap';
    outputArea.style.wordWrap = 'break-word';
    outputArea.style.marginTop = '10px';
    outputArea.style.border = '1px solid #ccc';
    outputArea.style.padding = '10px';
    outputArea.style.maxHeight = '300px';
    outputArea.style.overflowY = 'scroll';

    // 添加到亚马逊美国站导航栏中间
    const navBar = document.getElementById('nav-main'); // 获取亚马逊主导航栏
    if (navBar) {
        const navItem = document.createElement('div');
        navItem.style.display = 'flex';
        navItem.style.alignItems = 'center';
        navItem.style.justifyContent = 'center';
        navItem.style.marginTop = '10px';
        navItem.style.zIndex = '1000';
        
        // 将输入框、按钮等添加到导航栏
        navItem.appendChild(inputBox);
        navItem.appendChild(generateButton);
        navItem.appendChild(copyButton);
        navItem.appendChild(outputArea);

        navBar.appendChild(navItem);
    }

    // 生成叠词组合
    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]}`);
        }

        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).then(() => {
                alert('已复制到剪贴板!');
            });
        } else {
            alert('没有生成叠词可复制!');
        }
    });

})();

QingJ © 2025

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