X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=popup.js;h=742962dd074def469fca2bed4e2743b8b7176888;hb=5268e625c576d5a92915e8eb32c587fbc9cab673;hp=a88ed9409e8f4b03250be05d99e6b20fae789d3a;hpb=a98f3ef6a42ca6883b68136d1e87246627f30a9e;p=chrome-ext%2Fweb-power-switch.git
diff --git a/popup.js b/popup.js
index a88ed94..742962d 100644
--- a/popup.js
+++ b/popup.js
@@ -14,7 +14,8 @@ function fetchpage(url, callback) {
callback(xhr, state);
} else {
xhr.setstatus = true;
- setstatus('Could not connect; check settings');
+ setstatus('Could not connect;
check your ' +
+ 'settings');
console.log('connect error', state);
}
}
@@ -87,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 |
@@ -110,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';
@@ -126,7 +155,7 @@ function initpopup(xhr, state) {
function setstatus(msg) {
var status = document.getElementById('status');
- status.innerText = msg;
+ status.innerHTML = msg;
status.style.visibility = msg ? '' : 'hidden';
status.style.float = msg ? '' : 'left';
status.style.position = msg ? '' : 'absolute';
@@ -137,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);
+ };
+ }
+ });
});
});
|