Last active
May 26, 2019 06:21
-
-
Save schuyberg/521386bb126821313c093465398548c0 to your computer and use it in GitHub Desktop.
Tampermonkey script to print d20pfsrd pages onto a 3x5 cards - adds buttons to print .statblock, and .article-content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name d20pfsrd Print Card 2 | |
// @match www.d20pfsrd.com/* | |
// @description print a statblock from d20pfsrd.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const right_sidebar = document.querySelector(".right-sidebar"); | |
const article_content = document.querySelector('.article-content'); | |
const statblock = document.querySelector('.statblock'); | |
const css = `.product-right, .section15, .ogn-childpages { display: none; } | |
.printblock { | |
display: block; | |
position: absolute; | |
top: 0; | |
left: 0; | |
display: block; | |
width: 100%; | |
font-size: 10; | |
font-family: Arial, sans-serif; | |
} | |
.title { | |
font-size: 12; | |
font-weight: bold; | |
}`; | |
addButton(article_content, "Print article"); | |
addButton(statblock, "Print statblock"); | |
function addButton(element, label) { | |
let button = document.createElement("button"); | |
button.innerHTML = label; | |
right_sidebar.prepend(button); | |
button.addEventListener ("click", function() { | |
return printSelection(element) | |
}); | |
} | |
function printSelection(selection) { | |
let print_this = selection.cloneNode(true); | |
print_this.classList.add('printblock'); | |
let printwindow = window.open('', 'PRINT', 'height=400,width=600'); | |
printwindow.document.write('<html><head><style>' + css + '</style></head><body></body></html>'); | |
printwindow.document.body.appendChild(print_this); | |
printwindow.print(); | |
printwindow.close(); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment