Greasy Fork is available in English.
输入关键词生成组合叠词并添加复制按钮
当前为
// ==UserScript==
// @name 关键词叠词生成器
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 输入关键词生成组合叠词并添加复制按钮
// @author You
// @match *://*/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// 插入输入框、生成按钮、输出区域
const inputBox = document.createElement('input');
inputBox.type = 'text';
inputBox.placeholder = '输入关键词,用空格分隔(例如:ramekins oven safe)';
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';
// 添加到页面
document.body.appendChild(inputBox);
document.body.appendChild(generateButton);
document.body.appendChild(copyButton);
document.body.appendChild(outputArea);
// 生成叠词组合
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('没有生成叠词可复制!');
}
});
})();