From 56e32d11b326319803bfb2b6f6ef6f6597a87bbc Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 25 May 2021 01:12:54 +1000 Subject: [PATCH] Don't show print dialog until styles loaded --- html/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/html/index.js b/html/index.js index 5b51ada..9d1b6a4 100644 --- a/html/index.js +++ b/html/index.js @@ -593,11 +593,28 @@ function printResult() { wprint.document.title = 'pyRCV2 Report'; // Add stylesheets + let numToLoad = 0; + let numLoaded = 0; + + function onLoadStylesheet() { + numLoaded++; + if (numLoaded == numToLoad) { + wprint.print(); + } + } + for (let elCSSBase of document.querySelectorAll('head link')) { + numToLoad++; let elCSS = wprint.document.createElement('link'); elCSS.rel = elCSSBase.rel; elCSS.type = elCSSBase.type; - elCSS.href = elCSSBase.href; + if (elCSSBase.href.endsWith('?v=GITVERSION')) { + elCSS.href = elCSSBase.href.replace('?v=GITVERSION', '?v=' + Math.random()); + } else { + elCSS.href = elCSSBase.href; + } + + elCSS.onload = onLoadStylesheet; wprint.document.head.appendChild(elCSS); } @@ -702,6 +719,4 @@ function printResult() { divResultLogs2 = wprint.document.createElement('div'); divResultLogs2.innerHTML = divResultLogs1.innerHTML; elContainer.appendChild(divResultLogs2); - - wprint.print(); }