Vocabulary.com Export

Adds functionality for copying vocabulary lists to the clipboard

目前為 2023-07-06 提交的版本,檢視 最新版本

// ==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);
  
}

QingJ © 2025

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