mirror of
https://github.com/eddyem/bta-panels.git
synced 2025-12-06 10:45:20 +03:00
added cookies
This commit is contained in:
parent
8eb5de88ae
commit
54b3e74a1e
@ -2,12 +2,11 @@ var Stimeout, Itimeout; //
|
||||
var Rtimeout, Etimeout; // ÔÁÊÍÅÒ ÚÁÐÒÏÓÏ×, ÔÁÊÍÁÕÔ ÓÏÏÂÝ. Ï ÏÛÉÂËÅ
|
||||
const Stimeout_rate = 500, Itimeout_rate = 30000, Rtimeout_rate = 5000;
|
||||
var ImageSrc = new Array(2); // ÁÄÒÅÓ ÉÚÏÂÒÁÖÅÎÉÑ
|
||||
var Isrc = 0; // ÎÏÍÅÒ ÁÄÒÅÓÁ ÉÚÏÂÒÁÖÅÎÉÑ
|
||||
var oldDate = 0; // ÄÁÔÁ/×ÒÅÍÑ ÎÁ ÍÏÍÅÎÔ ÐÏÓÌÅÄÎÅÇÏ ÏÂÎÏ×ÌÅÎÉÑ (× ÍÓ)
|
||||
var MskTime, SidTime; // ÍÏÓËÏ×ÓËÏÅ É Ú×ÅÚÄÎÏÅ ×ÒÅÍÑ
|
||||
var PanelType;
|
||||
|
||||
const paramsURL = [ "http://tb.sao.ru/cgi-bin/eddy/bta_print.cgi",
|
||||
const paramsURL = ["http://tb.sao.ru/cgi-bin/eddy/bta_print.cgi",
|
||||
"http://ishtar.sao.ru/cgi-bin/bta_print.cgi"];
|
||||
const MeteoURL = [ "http://tb.sao.ru/cgi-bin/eddy/tempmon",
|
||||
"http://ishtar.sao.ru/cgi-bin/tempmon"];
|
||||
@ -18,6 +17,83 @@ const GuideURL = "http://n2.sao.ru/webcam/webcam_n2_0.jpeg";
|
||||
const USNOURL = "http://n2.sao.ru/ua2/gd15_ua2_jpeg.cgi?size=384&coord=cur";
|
||||
const myURL = "http://ishtar.sao.ru/BTApanels/";
|
||||
|
||||
|
||||
const TEST = true; // set to false in release
|
||||
function tlog__(msg){console.log(msg);}
|
||||
var tlog;
|
||||
if(TEST) tlog = tlog__;
|
||||
else tlog = function(msg){};
|
||||
|
||||
var Storage = null;
|
||||
|
||||
localCookies = function(){
|
||||
function get(nm){
|
||||
tlog("get " + nm);
|
||||
var name = nm + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0; i < ca.length; i++){
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1);
|
||||
if (c.indexOf(name) != -1)
|
||||
return c.substring(name.length,c.length);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function set(nm, val){
|
||||
tlog("set "+ nm + " to " + val);
|
||||
document.cookie = nm + "=" + val + ";";
|
||||
tlog(document.cookie);
|
||||
}
|
||||
return{
|
||||
getItem : get,
|
||||
setItem : set
|
||||
};
|
||||
}();
|
||||
|
||||
|
||||
function checkStorage(){
|
||||
if(Storage) return;
|
||||
var ret = localCookies;
|
||||
try{
|
||||
ret = localStorage;
|
||||
} catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
Storage = ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load object nm from local storage
|
||||
* if it's absent set it to defval or return null if devfal undefined
|
||||
*/
|
||||
function LoadObject(nm, defval){
|
||||
checkStorage();
|
||||
var val = null;
|
||||
try{
|
||||
var X = Storage.getItem(nm);
|
||||
tlog(X);
|
||||
val = JSON.parse(X);
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
if(val == null && typeof(defval) != "undefined"){
|
||||
tlog("Can't load object, try to use defaults");
|
||||
val = defval;
|
||||
}else
|
||||
tlog("load object " + nm + " with value " + val);
|
||||
return val;
|
||||
}
|
||||
/*
|
||||
* Save object obj in local storage as nm
|
||||
*/
|
||||
function SaveObject(obj, nm){
|
||||
checkStorage();
|
||||
tlog("save " + obj);
|
||||
Storage.setItem(nm, JSON.stringify(obj));
|
||||
}
|
||||
|
||||
var Isrc = LoadObject("ImageSrc", 0); // ÎÏÍÅÒ ÁÄÒÅÓÁ ÉÚÏÂÒÁÖÅÎÉÑ
|
||||
|
||||
function $(Id){
|
||||
return document.getElementById(Id);
|
||||
}
|
||||
@ -29,6 +105,7 @@ function _(Name){
|
||||
function chBigImg(){
|
||||
Isrc = (Isrc == 0) ? 1:0;
|
||||
$('BigIMG').src = ImageSrc[Isrc] + "?" + Math.random();
|
||||
SaveObject(Isrc, "ImageSrc");
|
||||
}
|
||||
|
||||
function init(panelName){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user