From 02af5fe730ecd1f046bb6330fbdb6768d4d63506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 8 Jun 2021 19:00:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02000.обновление.js | 52 +++++++++++++++++++++++++++++++++++ index.html | 1 + сервер.js | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 02000.обновление.js diff --git a/02000.обновление.js b/02000.обновление.js new file mode 100644 index 0000000..bbdb3c1 --- /dev/null +++ b/02000.обновление.js @@ -0,0 +1,52 @@ +function загрузитьJSONJS(отклик) +{ + const запрос = new XMLHttpRequest(); + запрос.onreadystatechange = function() + { + if (this.readyState == 4) + { + if (this.status == 200) + { + отклик(this.responseText); + } + else + { + console.error(this.status); + } + } + } + запрос.open("GET", "/json.js");// + "?" + gitjs.uuid()); + запрос.send(); +} + +function исполнитьJSONJS(текст) +{ + if (!текст.length) + { + return; + } + /* + try + { +console.debug("исполняем", текст); + eval(текст); +console.debug("исполнили", текст); + } + catch (e) + { + console.error(e); + } + */ + const скрипт = document.createElement("script"); + скрипт.src = текст; + document.body.appendChild(скрипт); +console.debug("исполнили скрипт?", текст); +} + +function обновитьJSONJS() +{ + загрузитьJSONJS(исполнитьJSONJS); +} + + +setInterval(обновитьJSONJS, 1000); diff --git a/index.html b/index.html index b307ee2..b5c77a3 100644 --- a/index.html +++ b/index.html @@ -24,5 +24,6 @@ + diff --git a/сервер.js b/сервер.js index 793a447..8744a5f 100644 --- a/сервер.js +++ b/сервер.js @@ -19,7 +19,7 @@ function process(req, res) { const content = Object.keys(jsonUpdates).sort().join("\n"); jsonUpdates = {}; - res.writeHead(200); + res.writeHead(200, { "Content-Type": "text/javascript" }); res.end(content, "utf-8"); return; }