Skip to content

Instantly share code, notes, and snippets.

@Schrank
Created May 30, 2020 20:33
Show Gist options
  • Save Schrank/4b66c42fa63e7f80abf3381e4aab2fdb to your computer and use it in GitHub Desktop.
Save Schrank/4b66c42fa63e7f80abf3381e4aab2fdb to your computer and use it in GitHub Desktop.
Get all Earthdawn dices for level 3-20
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Earthdawn dices</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<script>
let colSize = 3;
let levels = [
[4],
[6],
[8],
[10],
[12],
[6, 6],
[6, 8],
[8, 8],
[8, 10],
[10, 10],
[10, 12],
[12, 12],
[12, 6, 6],
[12, 8, 6],
[12, 8, 8],
[12, 8, 10],
[20, 6, 6],
[20, 6, 8],
];
function ready(callbackFunc) {
if (document.readyState !== 'loading') {
// Document is already ready, call the callback directly
callbackFunc();
} else if (document.addEventListener) {
// All modern browsers to register DOMContentLoaded
document.addEventListener('DOMContentLoaded', callbackFunc);
} else {
// Old IE browsers
document.attachEvent('onreadystatechange', function () {
if (document.readyState === 'complete') {
callbackFunc();
}
});
}
}
const chunk = (arr, size) =>
Array.from({length: Math.ceil(arr.length / size)}, (v, i) =>
arr.slice(i * size, i * size + size)
);
ready(function () {
let fragments = [];
levels.forEach(function (val, index) {
let dice = '';
val.forEach(function (val) {
dice = (dice ? dice + '+' : '') + 'd' + val + 'e' + val;
//https://dice.run/#/d/d12e12
});
let level = index + 3;
let html = `<div class="col"><h1>Level ${level}</h1><iframe src="https://dice.run/#/d/${dice}"></iframe></div>`;
fragments.push(document.createRange().createContextualFragment(html));
});
chunk(fragments, colSize).forEach(function (iframeContainers) {
//let row = document.createRange().createContextualFragment('<div class="row"></div>');
let row = document.createElement('div');
row.classList.add('row');
iframeContainers.forEach(function (container) {
row.appendChild(container);
});
document.getElementById('dices').appendChild(row);
});
});
</script>
<div id="dices" class="container">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment