-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js.h
3 lines (3 loc) · 7.04 KB
/
script.js.h
1
2
3
const char SCRIPT_JS[] PROGMEM = R"=====(
'use strict';angular.module('myApp',['ngMaterial']),myDash.$inject=['$scope','$mdToast','$http','$interval','$sce','$timeout'],angular.module('myApp').controller('dash',myDash).config(['$mdThemingProvider',function(a){a.theme('custom').primaryPalette('blue-grey').accentPalette('deep-orange')}]);function myDash(a,b,e,f,g,h){a.duration=0,a.dash={address:'--'},a.network={ips_to_check:[]},a.loc={},a.scanning=!1,a.page_ip='--',a.isRemote=function(){return a.dash.address!=a.page_ip},a.doAction=function(j){var k=a.dash.request.base_url+'?';a.isRemote()&&(k='http://'+a.dash.address+'/'+k);var l=!1;switch(window.scope=a,j){case'percentage':a.duration?l=a.dash.request.end_param+'='+a.dash.percentage+'&'+a.dash.request.duration_param+'='+a.duration:(a.dash.is_powered=0<a.dash.percentage,l=a.dash.request.start_param+'='+a.dash.percentage);break;case'toggle':if(a.dash.is_powered=!a.dash.is_powered,'percentage'==a.dash.mode){a.dash.is_powered?0==a.dash.percentage&&(a.dash.percentage=100):a.dash.percentage=0,l=a.dash.request.start_param+'='+a.dash.percentage;break}else;case'master':l=a.dash.request.master_param+'='+('momentary'==a.dash.mode||(a.dash.is_powered?'true':'false'));break;case'timer':l='timer='+(a.dash.is_using_timer?'true':'false');break;case'skip':l='skip='+(a.dash.is_skipping_next?'true':'false');break;default:alert('did not understand');}e.get(k+l).then(function(m){a.showToast(m.data.message)})},a.showToast=function(j){b.show(b.simple().textContent(j).position('top right'))},a.add_features_from_this_device=function(){e.get('features.json').then(function(j){a.page_ip=j.data.address,a.dash=j.data,a.merge_data_into_network_devices(j.data)||a.network.devices.push(j.data),document.title=j.data.app_name,a.showToast('Synchronised')})},a.refresh_network_devices=function(){if(!a.scanning){a.network.ips_to_check=[],a.network.ips_counted=0,a.network.ips_checked=0,a.network.ip_scan_percentage=0;for(var j=0;j<a.network.devices.length;j++)a.network.ips_to_check.push({ip_address:'http://'+a.network.devices[j].address,checked:!1,result:'Held in queue'});a.try_next_network_device_in_list()}},a.load_network_device_into_dash=function(j){a.dash=a.network.devices[j],a.selected_tab_index=1},a.getPowerStyle=function(){if(!a.dash.is_powered)return{color:'rgba(255, 255, 255, 0.3)'}},a.get123=function(){return a.dash.address.replace(/\d+$/g,'')},a.detect_network_devices=function(){localStorage.setItem('network.scan',JSON.stringify(a.network.scan)),a.network.ips_to_check=[],a.network.ips_counted=0,a.loc.replace_detected&&(a.network.devices=[]);for(var j='http://'+a.get123(),k=a.network.scan.ip_range_start;k<=a.network.scan.ip_range_end;k++)a.network.ips_to_check.push({ip_address:j+k,checked:!1,result:'Held in queue'});a.network.ips_checked=0,a.network.ip_scan_percentage=0,a.scanning=!0,h(function(){a.try_next_network_device_in_list()},2000),a.store_network_devices()},a.merge_data_into_network_devices=function(j){for(var k=0;k<a.network.devices.length;k++)if(a.network.devices[k].address==j.address)return a.network.devices[k]=j,!0;return!1},a.try_next_network_device_in_list=function(){for(var j=0;j<a.network.ips_to_check.length;j++)if(a.network.ips_to_check[j].checked);else{var k=a.network.ips_to_check[j].ip_address+'/features.json',l=g.trustAsResourceUrl(k);let m=j;return a.network.ips_to_check[m].result='waiting for response...',e.jsonp(l,{jsonpCallbackParam:'callback',timeout:1e4}).then(function(o){a.network.ips_to_check[m].result='Found device '+o.data.app_name,a.merge_data_into_network_devices(o.data)?a.network.ips_to_check[m].result='Updated device '+o.data.app_name:a.network.devices.push(o.data),a.loc.store_detected&&a.store_network_devices()}).catch(function(){a.network.ips_to_check[m].result='No response'}),a.network.ips_to_check[j].checked=!0,a.network.ips_checked++,a.network.ip_scan_percentage=parseInt(100*(a.network.ips_checked/a.network.ips_to_check.length)),void h(function(){a.try_next_network_device_in_list()},2000)}a.scanning=!1},a.considerUpdate=function(){},a.remoteRequest=function(j){var l=g.trustAsResourceUrl('http://'+j);e.jsonp(l,{jsonpCallbackParam:'callback'}).then(function(n){a.showToast(n.data.message)}).catch(function(){})},a.getUUID=function(){var j=new Date().getTime();window.performance&&'function'==typeof window.performance.now&&(j+=performance.now());var k='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(l){var m=0|(j+16*Math.random())%16;return j=Math.floor(j/16),('x'==l?m:8|3&m).toString(16)});return k},a.store_network_devices=function(){localStorage.setItem('network.devices',JSON.stringify(a.network.devices))},a.tpl_authenticate=function(){a.tpl.UUID=a.getUUID();var j={method:'login',params:{appType:'Kasa_Android',cloudUserName:a.tpl.creds.username,cloudPassword:a.tpl.creds.password,terminalUUID:a.tpl.UUID}};e.post('https://wap.tplinkcloud.com/',j).then(function(l){l.data.error_code?alert(l.data.msg):(a.tpl.token.value=l.data.result.token,localStorage.setItem('tpl_uuid',a.tpl.UUID),a.tpl.creds.store?localStorage.setItem('tpl.creds',JSON.stringify(a.tpl.creds)):localStorage.removeItem('tpl.creds'),a.tpl.token.store?localStorage.setItem('tpl.token',JSON.stringify(a.tpl.token)):localStorage.removeItem('tpl.token'),a.tpl_refreshDevices())},function(l){a.myWelcome=l.statusText})},a.tpl_refreshDevices=function(){e.post('https://wap.tplinkcloud.com?token='+a.tpl.token.value,{method:'getDeviceList'}).then(function(l){if(a.tpl.devices=l.data.result.deviceList,a.tpl.devices.length){for(var m=0;m<a.tpl.devices.length;m++)a.tpl_getState(m);a.selected_tab_index=0}})},a.tpl_getState=function(j){var k=a.tpl.devices[j].appServerUrl,l=a.tpl.devices[j].deviceId;e.post(k+'?token='+a.tpl.token.value,{method:'passthrough',params:{deviceId:l,requestData:'{"system":{"get_sysinfo":null},"emeter":{"get_realtime":null}}'}}).then(function(o){var p=JSON.parse(o.data.result.responseData).system.get_sysinfo.relay_state;a.tpl.devices[j].is_powered=!0==p})},a.tpl_setState=function(j,k){var l=a.tpl.devices[j].appServerUrl,m=a.tpl.devices[j].deviceId,n={method:'passthrough',params:{deviceId:m,requestData:'{"system":{"set_relay_state":{"state":'+(k?1:0)+'}}}'}};e.post(l+'?token='+a.tpl.token.value,n).then(function(){})},a.tpl={},a.tpl.refresh_rate=60,a.tpl.devices=[],a.tpl.creds=JSON.parse(localStorage.getItem('tpl.creds')),a.tpl.token=JSON.parse(localStorage.getItem('tpl.token')),null===a.tpl.creds&&(a.tpl.creds={},a.tpl.creds.username='',a.tpl.creds.password='',a.tpl.creds.store=!1),a.tpl.UUID=localStorage.getItem('tpl_uuid'),null===a.tpl.token?(a.tpl.token={},a.tpl.token.value='',a.tpl.token.store=!0):a.tpl_refreshDevices(),a.loc.store_detected=!0,a.network.devices=JSON.parse(localStorage.getItem('network.devices')),null==a.network.devices&&(a.network.devices=[]),a.network.scan=JSON.parse(localStorage.getItem('network.scan')),null===a.network.scan&&(a.network.scan={},a.network.scan.ip_range_start=2,a.network.scan.ip_range_end=40),a.selected_tab_index=0,f(function(){for(var j=0;j<a.tpl.devices.length;j++)a.tpl_getState(j)},1e3*a.tpl.refresh_rate),f(function(){a.refresh_network_devices()},60000),a.add_features_from_this_device()}
)=====";