]> git.wh0rd.org Git - chrome-ext/web-power-switch.git/commitdiff
extract user-set name for device, and link to the system
authorMike Frysinger <vapier@gentoo.org>
Mon, 15 Apr 2013 03:27:09 +0000 (23:27 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 15 Apr 2013 03:27:09 +0000 (23:27 -0400)
popup.js

index 7ba21e2505df7cb947b21b1a30bb5e7b91871813..189bbb74d071ab6d74bdb4f2d7b37bd58df6867e 100644 (file)
--- 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:
+       /*
+               <tr>
+               <th bgcolor="#DDDDFF" align=left>
+               Controller: !!!Web Power Switch 6
+               </th>
+               </tr>
+       */
+
+       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 = '<a href="' + url_base + '" target="_blank">' + cell.innerHTML + '</a>'
+       }
+
        /*
                <tr bgcolor="#F4F4F4"><td align=center>1</td>
                <td>Outlet 1</td><td>