OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="jstemplate_compiled.js" type="text/javascript"></script> | 3 <script src="jstemplate_compiled.js" type="text/javascript"></script> |
4 <script> | 4 <script> |
5 | 5 |
6 tabs = {}; | 6 tabs = {}; |
7 tabIds = []; | 7 tabIds = []; |
8 | 8 |
9 focusedWindowId = undefined; | 9 focusedWindowId = undefined; |
10 currentWindowId = undefined; | 10 currentWindowId = undefined; |
11 | 11 |
12 function bootStrap() { | 12 function bootStrap() { |
13 chrome.windows.getCurrent(function(currentWindow) { | 13 chrome.windows.getCurrent(function(currentWindow) { |
14 currentWindowId = currentWindow.id; | 14 currentWindowId = currentWindow.id; |
15 chrome.windows.getLastFocused(function(focusedWindow) { | 15 chrome.windows.getLastFocused(function(focusedWindow) { |
16 focusedWindowId = focusedWindow.id; | 16 focusedWindowId = focusedWindow.id; |
17 loadWindowList(); | 17 loadWindowList(); |
18 }); | 18 }); |
19 }); | 19 }); |
20 } | 20 } |
21 | 21 |
| 22 function isInt(i) { |
| 23 return (typeof i == "number") && !(i % 1) && !isNaN(i); |
| 24 } |
| 25 |
22 function loadWindowList() { | 26 function loadWindowList() { |
23 chrome.windows.getAll(true, function(windowList) { | 27 chrome.windows.getAll(true, function(windowList) { |
24 tabs = {}; | 28 tabs = {}; |
25 tabIds = []; | 29 tabIds = []; |
26 for (var i = 0; i < windowList.length; i++) { | 30 for (var i = 0; i < windowList.length; i++) { |
27 windowList[i].current = (windowList[i].id == currentWindowId); | 31 windowList[i].current = (windowList[i].id == currentWindowId); |
28 windowList[i].focused = (windowList[i].id == focusedWindowId); | 32 windowList[i].focused = (windowList[i].id == focusedWindowId); |
29 | 33 |
30 for (var j = 0; j < windowList[i].tabs.length; j++) { | 34 for (var j = 0; j < windowList[i].tabs.length; j++) { |
31 tabIds[tabIds.length] = windowList[i].tabs[j].id; | 35 tabIds[tabIds.length] = windowList[i].tabs[j].id; |
(...skipping 15 matching lines...) Expand all Loading... |
47 | 51 |
48 return retval; | 52 return retval; |
49 } | 53 } |
50 | 54 |
51 function updateTab(id){ | 55 function updateTab(id){ |
52 try { | 56 try { |
53 chrome.tabs.update(id, updateTabData(id)); | 57 chrome.tabs.update(id, updateTabData(id)); |
54 } catch (e) { | 58 } catch (e) { |
55 alert(e); | 59 alert(e); |
56 } | 60 } |
57 } | 61 } |
58 | |
59 | 62 |
60 function moveTabData(id) { | 63 function moveTabData(id) { |
61 return { | 64 return { |
62 'index': parseInt(document.getElementById('index_' + id).value), | 65 'index': parseInt(document.getElementById('index_' + id).value), |
63 'windowId': parseInt(document.getElementById('windowId_' + id).value) | 66 'windowId': parseInt(document.getElementById('windowId_' + id).value) |
64 } | 67 } |
65 } | 68 } |
66 function moveTab(id) { | 69 function moveTab(id) { |
67 try { | 70 try { |
68 chrome.tabs.move(id, moveTabData(id)); | 71 chrome.tabs.move(id, moveTabData(id)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { | 178 chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { |
176 appendToLog('tabs.onSelectionChanged -- window: ' + props.windowId + ' tab: '
+ tabId); | 179 appendToLog('tabs.onSelectionChanged -- window: ' + props.windowId + ' tab: '
+ tabId); |
177 loadWindowList(); | 180 loadWindowList(); |
178 }); | 181 }); |
179 | 182 |
180 chrome.tabs.onRemoved.addListener(function(tabId) { | 183 chrome.tabs.onRemoved.addListener(function(tabId) { |
181 appendToLog('tabs.onRemoved -- tab: ' + tabId); | 184 appendToLog('tabs.onRemoved -- tab: ' + tabId); |
182 loadWindowList(); | 185 loadWindowList(); |
183 }); | 186 }); |
184 | 187 |
185 function isInt(i) { | |
186 return (typeof i == "number") && !(i % 1) && !isNaN(i); | |
187 } | |
188 | |
189 function createWindow() { | 188 function createWindow() { |
190 var args = { | 189 var args = { |
191 'left': parseInt(document.getElementById('new_window_left').value), | 190 'left': parseInt(document.getElementById('new_window_left').value), |
192 'top': parseInt(document.getElementById('new_window_top').value), | 191 'top': parseInt(document.getElementById('new_window_top').value), |
193 'width': parseInt(document.getElementById('new_window_width').value), | 192 'width': parseInt(document.getElementById('new_window_width').value), |
194 'height': parseInt(document.getElementById('new_window_height').value), | 193 'height': parseInt(document.getElementById('new_window_height').value), |
195 'url': document.getElementById('new_window_url').value | 194 'url': document.getElementById('new_window_url').value |
196 } | 195 } |
197 | 196 |
198 if (!isInt(args.left)) | 197 if (!isInt(args.left)) |
(...skipping 20 matching lines...) Expand all Loading... |
219 window.tabs = tabList; | 218 window.tabs = tabList; |
220 var input = new JsExprContext(window); | 219 var input = new JsExprContext(window); |
221 var output = document.getElementById('window_' + window.id); | 220 var output = document.getElementById('window_' + window.id); |
222 jstProcess(input, output); | 221 jstProcess(input, output); |
223 | 222 |
224 appendToLog('window refreshed -- windowId: ' + window.id + ' tab count:' +
window.tabs.length); | 223 appendToLog('window refreshed -- windowId: ' + window.id + ' tab count:' +
window.tabs.length); |
225 }); | 224 }); |
226 }); | 225 }); |
227 } | 226 } |
228 | 227 |
| 228 function updateWindowData(id) { |
| 229 var retval = { |
| 230 left: parseInt(document.getElementById('left_' + id).value), |
| 231 top: parseInt(document.getElementById('top_' + id).value), |
| 232 width: parseInt(document.getElementById('width_' + id).value), |
| 233 height: parseInt(document.getElementById('height_' + id).value) |
| 234 } |
| 235 |
| 236 if (!isInt(retval.left)) |
| 237 delete retval.left; |
| 238 if (!isInt(retval.top)) |
| 239 delete retval.top; |
| 240 if (!isInt(retval.width)) |
| 241 delete retval.width; |
| 242 if (!isInt(retval.height)) |
| 243 delete retval.height; |
| 244 |
| 245 return retval; |
| 246 } |
| 247 |
| 248 function updateWindow(id){ |
| 249 try { |
| 250 chrome.windows.update(id, updateWindowData(id)); |
| 251 } catch (e) { |
| 252 alert(e); |
| 253 } |
| 254 } |
| 255 |
229 function removeWindow(windowId) { | 256 function removeWindow(windowId) { |
230 try { | 257 try { |
231 chrome.windows.remove(windowId, function() { | 258 chrome.windows.remove(windowId, function() { |
232 appendToLog('window: ' + windowId + ' removed.'); | 259 appendToLog('window: ' + windowId + ' removed.'); |
233 }); | 260 }); |
234 } catch (e) { | 261 } catch (e) { |
235 alert(e); | 262 alert(e); |
236 } | 263 } |
237 } | 264 } |
238 | 265 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 <div style="width: 40px; display:inline-block">url:</div> | 320 <div style="width: 40px; display:inline-block">url:</div> |
294 <input style="width: 90%" type="text" jsvalues="value:url;id:'
url_' + id" /> | 321 <input style="width: 90%" type="text" jsvalues="value:url;id:'
url_' + id" /> |
295 </div> | 322 </div> |
296 <div><input type="checkbox" jsvalues="checked:selected; id:'sele
cted_' + id" /> Selected</div> | 323 <div><input type="checkbox" jsvalues="checked:selected; id:'sele
cted_' + id" /> Selected</div> |
297 </div> | 324 </div> |
298 <button onclick="updateTab(this.jstdata)" jsvalues=".jstdata:id">U
pdate Tab</button> | 325 <button onclick="updateTab(this.jstdata)" jsvalues=".jstdata:id">U
pdate Tab</button> |
299 <button onclick="removeTab(this.jstdata);" jsvalues=".jstdata:id">
Close Tab</button> | 326 <button onclick="removeTab(this.jstdata);" jsvalues=".jstdata:id">
Close Tab</button> |
300 </div> | 327 </div> |
301 </div> | 328 </div> |
302 </div> | 329 </div> |
| 330 <button onclick="updateWindow(this.jstdata);" jsvalues=".jstdata:id">Upd
ate Window</button> |
303 <button onclick="removeWindow(this.jstdata);" jsvalues=".jstdata:id">Clo
se Window</button> | 331 <button onclick="removeWindow(this.jstdata);" jsvalues=".jstdata:id">Clo
se Window</button> |
304 <button onclick="refreshSelectedTab(this.jstdata);" jsvalues=".jstdata:i
d">Refresh Selected Tab</button> | 332 <button onclick="refreshSelectedTab(this.jstdata);" jsvalues=".jstdata:i
d">Refresh Selected Tab</button> |
305 </div> | 333 </div> |
306 </div> | 334 </div> |
307 <div style="background-color: #EEEEBB; margin: 20px; padding: 8px"> | 335 <div style="background-color: #EEEEBB; margin: 20px; padding: 8px"> |
308 <h3 style="text-align: center; margin: 8px"> Create Window</h3> | 336 <h3 style="text-align: center; margin: 8px"> Create Window</h3> |
309 <div style="margin: 8px"> | 337 <div style="margin: 8px"> |
310 <div style="width: 300px; display: inline-block"> | 338 <div style="width: 300px; display: inline-block"> |
311 left: <input style="width: 20px" type="text" id="new_window_left" /> | 339 left: <input style="width: 20px" type="text" id="new_window_left" /> |
312 top: <input style="width: 20px" type="text" id="new_window_top" /> | 340 top: <input style="width: 20px" type="text" id="new_window_top" /> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 <button onclick="loadWindowList();">Refresh</button> | 376 <button onclick="loadWindowList();">Refresh</button> |
349 <button onclick="updateAll();">Update All</button> | 377 <button onclick="updateAll();">Update All</button> |
350 <button onclick="moveAll();">Move All</button> | 378 <button onclick="moveAll();">Move All</button> |
351 <button onclick="clearLog();">-->Clear Log</button> | 379 <button onclick="clearLog();">-->Clear Log</button> |
352 <button onclick="chrome.windows.create();">New Window</button> | 380 <button onclick="chrome.windows.create();">New Window</button> |
353 </div> | 381 </div> |
354 <div id="log" style="background-color: #EEAAEE; margin: 20px; padding: 8px"> | 382 <div id="log" style="background-color: #EEAAEE; margin: 20px; padding: 8px"> |
355 </div> | 383 </div> |
356 </body> | 384 </body> |
357 </html> | 385 </html> |
OLD | NEW |