X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=popup.js;h=742962dd074def469fca2bed4e2743b8b7176888;hb=7e0338f48e9827c01114713351ea64670c20a56a;hp=7ba21e2505df7cb947b21b1a30bb5e7b91871813;hpb=e981c8374cda5aef50354d7f4f3c7233ee0ffe7b;p=chrome-ext%2Fweb-power-switch.git
diff --git a/popup.js b/popup.js
index 7ba21e2..742962d 100644
--- a/popup.js
+++ b/popup.js
@@ -88,6 +88,31 @@ function initpopup(xhr, state) {
// There is no clean API for extracting the current state.
// Example result:
+ /*
+
+
+ Controller: !!!Web Power Switch 6
+
+
+ */
+
+ var th, ths = state.currentTarget.responseXML.querySelectorAll('th');
+ for (var i = 0; th = ths[i]; ++i) {
+ if (th.bgColor != '#DDDDFF')
+ continue;
+
+ var controller_name = trim(th.innerText);
+ if (controller_name.slice(0, 12) != 'Controller: ')
+ continue;
+
+ row = tbl.insertRow(-1);
+ cell = row.insertCell(-1);
+ cell.colSpan = 2;
+ cell.align = 'center';
+ cell.innerText = controller_name.slice(12);
+ cell.innerHTML = '' + cell.innerHTML + ' '
+ }
+
/*
1
Outlet 1
@@ -111,7 +136,10 @@ function initpopup(xhr, state) {
row = tbl.insertRow(-1);
cell = row.insertCell(-1);
- cell.innerText = outlet_name + ':';
+ if (outlet_name === '')
+ cell.innerHTML = 'unnamed ';
+ else
+ cell.innerText = outlet_name + ':';
cell = row.insertCell(-1);
button = document.createElement('input');
button.type = 'button';
@@ -138,6 +166,24 @@ document.addEventListener('DOMContentLoaded', function() {
url_base = settings['url'] || settings_defaults['url'];
user = settings['user'] || settings_defaults['user'];
pass = settings['pass'] || settings_defaults['pass'];
- fetchpage('index.htm', initpopup);
+ chrome.permissions.contains({
+ origins: [url_base + '/*']
+ }, function(granted) {
+ if (granted) {
+ fetchpage('index.htm', initpopup);
+ } else {
+ setstatus(
+ 'Missing permissions; please visit the ' +
+ 'settings page ' +
+ ' to grant access. ' +
+ ' '
+ );
+ // Work around http://crbug.com/125706.
+ document.getElementById('retry').onclick = function() {
+ chrome.permissions.request({origins: [url_base + '/*']});
+ fetchpage('index.htm', initpopup);
+ };
+ }
+ });
});
});