class BlueWeather { constructor() { // cunstruct xmlhttp this.xhttp = new XMLHttpRequest(); this.host = window.location.href.substring(0, window.location.href.lastIndexOf("/")); this.log("init done", 2) } getLocationData(locId) { this.sendRequest("https://api.itsblue.de/weather/json.php?locId="+locId+"") if(this.xhttp.status === 200) { this.log("getting sensors response was: " + this.xhttp.responseText, 3) var ret = JSON.parse(this.xhttp.responseText) if(ret){ return ret } } } endSession() { document.cookie = "session=;" window.location.href = "./index.html" } // -------------------- // - helper functions - // -------------------- sendRequest(url) { this.log("starting request; URL is: " + url, 3) this.xhttp.open("GET", url, false) this.xhttp.send() return this.xhttp } getCookie(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } log(text, level){ // levels: // 0: error // 1: warning // 2: info // 3: debug var preString = "[BlueWeather]" switch(level){ case 0: preString += "[error] " console.error(preString+text) break case 1: preString += "[warining] " console.warn(preString+text) break case 2: preString += "[info] " console.log(preString+text) break case 3: preString += "[debug] " console.debug(preString+text) } } }