Copy Button for Quizlet

Adds a copy button to Quizlet vocab lists

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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