Copy Button for Quizlet

Adds a copy button to Quizlet vocab lists

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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