关键词叠词生成器

输入关键词生成组合叠词

  1. // ==UserScript==
  2. // @name 关键词叠词生成器
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description 输入关键词生成组合叠词
  6. // @author You
  7. // @match https://www.amazon.com/*
  8. // @match https://www.amazon.co.uk/*
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // 添加样式
  16. GM_addStyle(`
  17. #wordGeneratorContainer {
  18. position: fixed;
  19. top: 50%;
  20. left: 50%;
  21. transform: translate(-50%, -50%);
  22. z-index: 9999;
  23. background-color: #f9f9f9;
  24. padding: 20px;
  25. border: 2px solid #ccc;
  26. border-radius: 15px;
  27. box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
  28. display: none;
  29. font-family: 'Arial', sans-serif;
  30. width: auto;
  31. max-width: 500px;
  32. min-width: 300px;
  33. }
  34.  
  35. #openGeneratorButton {
  36. position: fixed;
  37. bottom: 20px;
  38. right: 20px;
  39. background-color: #0073e6;
  40. color: white;
  41. padding: 15px 20px;
  42. font-size: 20px;
  43. border: none;
  44. border-radius: 50%;
  45. cursor: pointer;
  46. z-index: 9999;
  47. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  48. }
  49.  
  50. #outputArea {
  51. white-space: pre-wrap;
  52. word-wrap: break-word;
  53. margin-top: 15px;
  54. border: 1px solid #ddd;
  55. padding: 15px;
  56. background-color: #f4f4f4;
  57. min-height: 100px;
  58. max-height: 150px;
  59. overflow-y: auto;
  60. border-radius: 8px;
  61. }
  62.  
  63. #wordGeneratorContainer button {
  64. margin-top: 10px;
  65. margin-right: 5px;
  66. padding: 10px;
  67. font-size: 14px;
  68. border: none;
  69. border-radius: 8px;
  70. cursor: pointer;
  71. }
  72.  
  73. #copyButton {
  74. background-color: #0073e6;
  75. color: white;
  76. }
  77.  
  78. #clearButton {
  79. background-color: #ff9800;
  80. color: white;
  81. }
  82.  
  83. #closeButton {
  84. background-color: #ff3b3b;
  85. color: white;
  86. }
  87.  
  88. #generateButton {
  89. background-color: #4caf50;
  90. color: white;
  91. }
  92.  
  93. #wordGeneratorContainer button:hover {
  94. opacity: 0.8;
  95. }
  96. `);
  97.  
  98. // 创建容器
  99. const container = document.createElement('div');
  100. container.id = 'wordGeneratorContainer';
  101.  
  102. const inputBox = document.createElement('input');
  103. inputBox.type = 'text';
  104. inputBox.placeholder = '输入关键词';
  105. inputBox.style.width = '100%';
  106.  
  107. const generateButton = document.createElement('button');
  108. generateButton.id = 'generateButton';
  109. generateButton.textContent = '生成叠词';
  110.  
  111. const copyButton = document.createElement('button');
  112. copyButton.id = 'copyButton';
  113. copyButton.textContent = '复制';
  114.  
  115. const clearButton = document.createElement('button');
  116. clearButton.id = 'clearButton';
  117. clearButton.textContent = '清空';
  118.  
  119. const closeButton = document.createElement('button');
  120. closeButton.id = 'closeButton';
  121. closeButton.textContent = '关闭';
  122.  
  123. const outputArea = document.createElement('pre');
  124. outputArea.id = 'outputArea';
  125.  
  126. container.appendChild(inputBox);
  127. container.appendChild(generateButton);
  128. container.appendChild(copyButton);
  129. container.appendChild(clearButton);
  130. container.appendChild(closeButton);
  131. container.appendChild(outputArea);
  132. document.body.appendChild(container);
  133.  
  134. // 显示生成器按钮
  135. const openGeneratorButton = document.createElement('button');
  136. openGeneratorButton.id = 'openGeneratorButton';
  137. openGeneratorButton.textContent = '叠';
  138. document.body.appendChild(openGeneratorButton);
  139.  
  140. // 功能实现
  141. function generateCombinations(input) {
  142. const words = input.trim().split(/\s+/);
  143. const length = words.length;
  144.  
  145. if (length < 2 || length > 4) {
  146. return '请输入 2 到 4 个关键词!';
  147. }
  148.  
  149. const combinations = [];
  150.  
  151. // AB式
  152. if (length === 2) {
  153. combinations.push(`${words[0]} ${words[1]} ${words[0]} ${words[1]}`);
  154. combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]}`);
  155. combinations.push(`${words[0]} ${words[0]} ${words[1]}`);
  156. combinations.push(`${words[0]} ${words[1]} ${words[1]}`);
  157. }
  158.  
  159. // ABC式
  160. if (length === 3) {
  161. combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[0]} ${words[1]} ${words[2]}`);
  162. combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[2]}`);
  163. combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[2]}`);
  164. combinations.push(`${words[0]} ${words[1]} ${words[1]} ${words[2]}`);
  165. combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[2]}`);
  166. }
  167.  
  168. // ABCD式
  169. if (length === 4) {
  170. combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[3]} ${words[0]} ${words[1]} ${words[2]} ${words[3]}`);
  171. combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[2]} ${words[3]} ${words[3]}`);
  172. combinations.push(`${words[0]} ${words[0]} ${words[1]} ${words[2]} ${words[3]}`);
  173. combinations.push(`${words[0]} ${words[1]} ${words[1]} ${words[2]} ${words[3]}`);
  174. combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[2]} ${words[3]}`);
  175. combinations.push(`${words[0]} ${words[1]} ${words[2]} ${words[3]} ${words[3]}`);
  176. }
  177.  
  178. return combinations.join('\n');
  179. }
  180.  
  181. generateButton.addEventListener('click', () => {
  182. const input = inputBox.value;
  183. const output = generateCombinations(input);
  184. outputArea.textContent = output;
  185. });
  186.  
  187. copyButton.addEventListener('click', () => {
  188. const text = outputArea.textContent;
  189. if (text) {
  190. navigator.clipboard.writeText(text).then(() => {
  191. alert('内容已复制到剪贴板!');
  192. });
  193. } else {
  194. alert('没有内容可复制!');
  195. }
  196. });
  197.  
  198. clearButton.addEventListener('click', () => {
  199. inputBox.value = '';
  200. outputArea.textContent = '';
  201. });
  202.  
  203. closeButton.addEventListener('click', () => {
  204. container.style.display = 'none';
  205. });
  206.  
  207. openGeneratorButton.addEventListener('click', () => {
  208. container.style.display = 'block';
  209. });
  210. })();

QingJ © 2025

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