Quizlet.com Export

Adds functionality for copying quizlet lists to the clipboard

目前为 2023-07-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Quizlet.com Export
  3. // @version 1.0.2
  4. // @author petracoding
  5. // @namespace petracoding
  6. // @grant none
  7. // @license MIT
  8. // @include https://quizlet.com/*
  9. // @include http://quizlet.com/*
  10. // @include https://www.quizlet.com/*
  11. // @include http://www.quizlet.com/*
  12. // @description Adds functionality for copying quizlet lists to the clipboard
  13. // ==/UserScript==
  14.  
  15.  
  16.  
  17. // SETTINGS:
  18.  
  19. const swapTermAndDefinition = false; // true or false
  20. const delimiter = " "; // Use "\n" for a new line. Default: " "
  21. const delimiterBetweenTerms = "\n"; // Use "\n" for a new line. Default: "\n"
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. // DO NOT CHANGE ANYTHING BELOW HERE.
  30.  
  31. start();
  32.  
  33. function start() {
  34. const wrapper = document.querySelector(".SetPageHeader");
  35. if (!wrapper) return;
  36. const el = document.createElement("div");
  37. el.innerHTML = `
  38. <br/><div class="primary"><a class="action-1 button quizlet-export">Copy to clipboard</a></div>
  39. `;
  40. wrapper.appendChild(el);
  41. const btn = document.querySelector(".quizlet-export");
  42. btn.addEventListener("click", () => {
  43. copy();
  44. });
  45. }
  46.  
  47. function copy() {
  48. const list = document.querySelectorAll(".SetPage-content .SetPageTerms-term");
  49. let output = "";
  50. [...list].forEach((li) => {
  51. if (li.querySelector(".count")) {
  52. li.querySelector(".count").remove();
  53. }
  54. const lineBreak = " | ";
  55. const term = li.querySelector(".SetPageTerm-wordText .TermText").innerHTML.replaceAll("<br>", lineBreak).trim();
  56. const definition = li.querySelector(".SetPageTerm-definitionText .TermText").innerHTML.replaceAll("<br>", lineBreak).trim();
  57.  
  58. if (swapTermAndDefinition) {
  59. output += definition + delimiter + term + delimiterBetweenTerms;
  60. } else {
  61. output += term + delimiter + definition + delimiterBetweenTerms;
  62. }
  63. });
  64. navigator.clipboard.writeText(output);
  65. alert("Done! All visible terms have been copied to the clipboard, you can now paste them anywhere.\n\nIf you are missing terms make sure to scroll down on your Quizlet list and load all terms before pressing the copy button.");
  66. }