Skip to content

Instantly share code, notes, and snippets.

@danielbair
Last active July 29, 2021 02:55
Show Gist options
  • Save danielbair/537c16e7d4d2279c14bd8a5d9be893b5 to your computer and use it in GitHub Desktop.
Save danielbair/537c16e7d4d2279c14bd8a5d9be893b5 to your computer and use it in GitHub Desktop.
Fix teacher printing problems on Monarch App
// ==UserScript==
// @name Monarch Fix Print Content
// @namespace http://danielbair.com/
// @version 0.6
// @description Fix teacher printing problems on Monarch App
// @author Daniel Bair
// @match https://monarch-app.aop.com/curriculum/*
// @icon https://www.google.com/s2/favicons?domain=aop.com
// @grant none
// @copyright 2020+, Daniel Bair
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("load", function(){
window.fixPrint = function() {
console.log('Fixing Monarch Print Problems');
var content = document.getElementById('print_content');
Object.values(content.getElementsByTagName('img')).forEach(function(item){
item.src = item.src.replace(/^\/\//g,'https://');
console.log(item);
});
Object.values(content.getElementsByTagName('select')).forEach(function(item){
var size = item.children.length;
item.setAttribute('size',size);
item.setAttribute('style','vertical-align: top;');
console.log(item);
});
Object.values(content.getElementsByClassName('items')).forEach(function(item){
//item.firstChild.textContent = '';
//item.innerHTML = item.innerHTML.replace(/\d\.\s/g,'');
console.log(item);
});
var child = document.createElement('style');
child.setAttribute('type','text/css');
child.innerHTML = "option { color: black; } .monarch_essay_title { height: 200px !important; } .word { background-color: #A4FF6E; margin-bottom: 3px; padding-left: 3px; padding-right: 3px; padding-bottom: 1px; border: 1px solid #999; } .matching_answer_preview { padding-left: 200px !important; background: #eee; border: #999 1px solid; margin-right: 10px; padding: 0px 4px; min-height: 23px; min-width: 23px; }";
content.appendChild(child);
console.log('Adding print styles');
}
window.addPrintButtons = function() {
var print = document.getElementById('the_problems').contentWindow.document.getElementById('print_problems_blank')
var onclick = print.getElementsByTagName('input')[0].getAttribute('onclick') + ' setTimeout(function(){ window.parent.fixPrint(); }, 3000);';
print.getElementsByTagName('input')[0].setAttribute('onclick',onclick);
var button = document.createElement("input");
button.type = "button";
button.value = "Fix Print Content";
button.onclick = window.fixPrint;
print.appendChild(button);
console.log('Added Fix Print Content button');
}
document.querySelector('#the_problems').addEventListener("load", function(e) {
window.addPrintButtons();
console.log(e.target);
});
//setTimeout(function(){
window.addPrintButtons();
//}, 1000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment