-
Notifications
You must be signed in to change notification settings - Fork 13
/
brave.lua
51 lines (43 loc) · 1.08 KB
/
brave.lua
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
51
-- BRAVE
--
-- Some utility functions for controlling Brave Browser.
-- Probably would work super similarly on Chrome and Safari, or any webkit
-- browser.
--
-- NOTE: May require you enable View -> Developer -> Allow Javascript from
-- Apple Events in Brave's menu.
local module = {}
module.start = function(config_table)
module.config = config_table
end
module.jump = function(url)
hs.osascript.javascript([[
(function() {
var brave = Application('Brave');
brave.activate();
for (win of brave.windows()) {
var tabIndex =
win.tabs().findIndex(tab => tab.url().match(/]] .. url .. [[/));
if (tabIndex != -1) {
win.activeTabIndex = (tabIndex + 1);
win.index = 1;
}
}
})();
]])
end
module.killTabsByDomain = function(domain)
hs.osascript.javascript([[
(function() {
var brave = Application('Brave');
for (win of brave.windows()) {
for (tab of win.tabs()) {
if (tab.url().match(/]] .. string.gsub(domain, '/', '\\/') .. [[/)) {
tab.close()
}
}
}
})();
]])
end
return module