Add context injector for pdf

This commit is contained in:
Jake Howard 2017-03-31 18:25:03 +01:00
parent 86a8dda99b
commit 7e5d37f3fd
3 changed files with 24 additions and 2 deletions

20
md_pdf/assets/context.js Normal file
View file

@ -0,0 +1,20 @@
function subst() {
var vars = {};
var query_strings_from_url = document.location.search.substring(1).split('&');
for (var query_string in query_strings_from_url) {
if (query_strings_from_url.hasOwnProperty(query_string)) {
var temp_var = query_strings_from_url[query_string].split('=', 2);
vars[temp_var[0]] = decodeURI(temp_var[1]);
}
}
var css_selector_classes = Object.keys(vars);
for (var css_class in css_selector_classes) {
if (css_selector_classes.hasOwnProperty(css_class)) {
var element = document.getElementsByClassName(css_selector_classes[css_class]);
for (var j = 0; j < element.length; ++j) {
element[j].textContent = vars[css_selector_classes[css_class]];
}
}
}
}

View file

@ -2,7 +2,8 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="context.js"></script>
</head> </head>
<body class="footer"> <body onload="subst()" class="footer">
</body> </body>
</html> </html>

View file

@ -2,7 +2,8 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="context.js"></script>
</head> </head>
<body class="header"> <body onload="subst()" class="header">
</body> </body>
</html> </html>