From a22f571d2426c42e95299c1213c72205d593345c Mon Sep 17 00:00:00 2001 From: Lanston Chu <38820312+lanstonchu@users.noreply.github.com> Date: Sat, 1 Aug 2020 15:16:09 -0500 Subject: [PATCH] Add codes to support external css According to https://stackoverflow.com/questions/62012281/how-to-reference-a-gist-stylesheet-in-another-gist --- main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.js b/main.js index 13e9a1b..5808089 100644 --- a/main.js +++ b/main.js @@ -70,6 +70,22 @@ // 5. write data var content = info.files[fileName].content; document.write(content); + + //load links + var links = document.querySelectorAll("link"); + for (let [key, value] of Object.entries(info.files)) { + for (var i = 0; i < links.length; i++) { + var href = links[i].getAttribute("href").replace(/^\/|\/$/g, ''); + if (value.filename === href && value.type === "text/css") { + console.log("load file " + value.filename); + var style = document.createElement('style'); + style.type = 'text/css'; + style.innerHTML = value.content; + document.getElementsByTagName('head')[0].appendChild(style); + } + } + } + }) .catch(function (err) { showMainPage();