Vocabulary.com Export

Adds functionality for copying vocabulary lists to the clipboard

当前为 2023-07-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Vocabulary.com Export
// @version     1.0.0
// @author      petracoding
// @namespace   petracoding
// @grant       none
// @license     MIT
// @include     https://vocabulary.com/*
// @include     http://vocabulary.com/*
// @description Adds functionality for copying vocabulary lists to the clipboard
// ==/UserScript==



// SETTINGS:

const delimiter = "\n"; 							// Use "\n" for a new line. Default: "\n"
const delimiterBetweenWords = "\n\n"; // Use "\n" for a new line. Default: "\n\n"







// DO NOT CHANGE ANYTHING BELOW HERE.

start();

function start() {
  const wrapper = document.querySelector(".stats");
  if (!wrapper) return;
  
  wrapper.innerHTML = wrapper.innerHTML + `
    <div class="primary"><a class="action-1 button vocab-export-copy1">Copy to clipboard (Word + Definition)</a></div>
    <div class="primary"><a class="action-1 button vocab-export-copy2">Copy to clipboard (Example sentence with gaps + Word)</a></div>
		<div class="vocab-export-done" style="display:none;">Copied!</div>
  `;
  
  const btn1 = document.querySelector(".vocab-export-copy1");
  btn1.addEventListener("click", () => {
    	copy();
  });
  
  const btn2 = document.querySelector(".vocab-export-copy2");
  btn2.addEventListener("click", () => {
    	copy("examples");
  });
   
}

function copy(type) {
  const doneEl = document.querySelector(".vocab-export-done");
  const list = document.querySelectorAll(".wordlist .entry");
  let output = "";
  
  [...list].forEach((li) => {
    if (li.querySelector(".count")) {
      li.querySelector(".count").remove();
    }
    
    if (type == "examples") {
      if (li.querySelector(".example")) {
        
        [...li.querySelectorAll(".example strong")].forEach(e => e.remove());

        if (li.querySelector(".example .source")) {
          li.querySelector(".example .source").remove();
        }

        output += li.querySelector(".example").innerHTML.replaceAll("\n","___") + delimiter + li.querySelector(".word").innerHTML.trim() + delimiterBetweenWords;

      }
    } else {
      output += li.querySelector(".word").innerHTML.trim() + delimiter + li.querySelector(".definition").innerHTML + delimiterBetweenWords;
    }
  });
  
  navigator.clipboard.writeText(output);
  doneEl.style.display = "block";
  
  setTimeout(function () {
        doneEl.style.display = "none";
  }, 1000);
  
}