OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var systemInfo = chrome.experimental.systemInfo; |
| 6 |
| 7 var indicator = {} |
| 8 var isStarted = false; |
| 9 |
| 10 function onStorageChanged(info) { |
| 11 var elem = document.getElementById(info.id); |
| 12 if (indicator[info.id]++ % 2) |
| 13 elem.bgColor = "green"; |
| 14 else |
| 15 elem.bgColor = "white"; |
| 16 elem.innerHTML = info.availableCapacity; |
| 17 } |
| 18 |
| 19 function startMonitor() { |
| 20 if (isStarted) return; |
| 21 systemInfo.storage.onAvailableCapacityChanged.addListener(onStorageChanged); |
| 22 isStarted = true; |
| 23 } |
| 24 |
| 25 function stopMonitor() { |
| 26 if (!isStarted) return; |
| 27 systemInfo.storage.onAvailableCapacityChanged.removeListener( |
| 28 onStorageChanged); |
| 29 isStarted = false; |
| 30 } |
| 31 |
| 32 function init() { |
| 33 document.getElementById("start-btn").onclick = startMonitor; |
| 34 document.getElementById("stop-btn").onclick = stopMonitor; |
| 35 |
| 36 chrome.experimental.systemInfo.storage.get(function(info) { |
| 37 var table = "<table width=65% border=\"1\">\n" + |
| 38 "<tr><td><b>ID</b></td>" + |
| 39 "<td>Type</td>" + |
| 40 "<td>Capacity (bytes)</td>" + |
| 41 "<td>Available (bytes)</td>" + |
| 42 "</tr>\n"; |
| 43 for (var i = 0; i < info.units.length; i++) { |
| 44 indicator[info.units[i].id] = 0; |
| 45 table += showStorageInfo(info.units[i]); |
| 46 } |
| 47 table += "</table>\n"; |
| 48 var div = document.getElementById("storage-list"); |
| 49 div.innerHTML = table; |
| 50 }); |
| 51 } |
| 52 |
| 53 function showStorageInfo(unit) { |
| 54 table = "<tr><td>" + unit.id + "</td>" + |
| 55 "<td>" + unit.type + "</td>" + |
| 56 "<td>" + unit.capacity + "</td>" + |
| 57 "<td id=" + "\"" + unit.id + "\">" + unit.availableCapacity + "</td>" + |
| 58 "</tr>\n"; |
| 59 return table; |
| 60 } |
| 61 |
| 62 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |