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; }