Skip to content

Instantly share code, notes, and snippets.

@danielbair
Last active April 26, 2021 01:17
Show Gist options
  • Save danielbair/c5b2394994a5b08f668bd89dcbfe5464 to your computer and use it in GitHub Desktop.
Save danielbair/c5b2394994a5b08f668bd89dcbfe5464 to your computer and use it in GitHub Desktop.
Capture the vocabulary from Monarch App
// ==UserScript==
// @name Monarch Capture Vocabulary
// @namespace http://danielbair.com/
// @version 0.3
// @description Capture the vocabulary from Monarch App
// @author Daniel Bair
// @match https://monarch-app.aop.com/curriculum/section/*
// @icon https://www.google.com/s2/favicons?domain=aop.com
// @grant none
// @copyright 2020+, Daniel Bair
// ==/UserScript==
(function() {
'use strict';
// Your code here...
window.addEventListener("load", function(){
var vocabelm = document.getElementsByClassName('gl-vocabulary')[0];
var vocabtable = vocabelm.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
var vocabrow = vocabtable.getElementsByTagName("tr");
var vocablist = "";
for(var i=0; i<vocabrow.length; i++) {
vocablist = vocablist + vocabrow[i].getElementsByTagName("td")[1].innerHTML + "\n";
}
function copyVocab() {
if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = vocablist;
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
document.body.appendChild(textarea);
textarea.select();
try {
return document.execCommand("copy"); // Security exception may be thrown by some browsers.
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
console.log("Copy to clipboard success.");
alert("Spelling Word List copied to Clipboard");
document.body.removeChild(textarea);
}
}
}
var button = document.createElement("input");
button.type = "button";
button.value = "Copy Spelling Word List to Clipboard";
button.onclick = copyVocab;
vocabelm.appendChild(button);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment