-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathreload-chrome.js
executable file
·50 lines (41 loc) · 1.23 KB
/
reload-chrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/// Reload extensions....
/// run me as `osascript -l JavaScript reload-chrome.js`
// requires Extension Reloader https://chrome.google.com/webstore/detail/extensions-reloader/fimgfedafeadlieiabdeeaodndnlbhid
function run(argv) {
var app = Application('Google Chrome'),
extUrl = 'http://reload.extensions',
ctxUrl = argv;
function each(a, fn) {
for (var i = 0; i < a.length; i++)
fn(a[i], i);
}
function find(a, fn) {
for (var i = 0; i < a.length; i++)
if (fn(a[i], i))
return a[i];
return null;
}
function enumTabs() {
var wts = [];
each(app.windows, function (win) {
each(win.tabs, function (tab, i) {
wts.push({'window': win, 'tab': tab})
});
});
return wts.filter(function (wt) {
return !wt.window.title().match(/^Developer Tools/);
});
}
function reload() {
var wts = enumTabs();
if (!wts.length) {
console.log('no open tabs');
var w = app.Window().make();
w.tabs[0].url = extUrl;
} else {
wts[0].tab.url = extUrl;
}
}
app.activate();
reload();
}