Copy Button for Quizlet

Adds a copy button to Quizlet vocab lists

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Copy Button for Quizlet
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Adds a copy button to Quizlet vocab lists
// @author       kingquokka
// @match        https://quizlet.com/gb/*
// @grant        none
// ==/UserScript==


let styleSheet = `
.copyBtn {
    background-color: blue;
    color: white;
    padding: 5px;
    font-size: 10px;
}
`;

let s = document.createElement('style');
s.type = "text/css";
s.innerHTML = styleSheet;
(document.head || document.documentElement).appendChild(s);

window.addEventListener('load', function() {
    'use strict';

    function copy(ele) {
        let temp = document.createElement('textarea');
        document.body.appendChild(temp);
        temp.value = ele.textContent;
        temp.select();
        document.execCommand('copy');
        temp.remove();
    }

    function addCopyBtn(ele) {
        let btn = document.createElement("button");
        btn.innerHTML = "Copy";
        btn.className = "copyBtn";
        btn.onclick = () => {
            copy(ele.lastChild);
        }

        ele.insertBefore(document.createElement('br'), ele.childNodes[0]);
        ele.insertBefore(btn, ele.childNodes[0]);
    }

    let spanTags = document.getElementsByClassName("SetPageTerm-sideContent");

    console.log(spanTags);

    for (let spanTag of spanTags) {
        addCopyBtn(spanTag);
    }
});