forked from stoodkev/SteemPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
50 lines (43 loc) · 1.9 KB
/
background.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
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log("bgs: forwarded " + request.data + " to the tab " + request.to);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, request, function(response) { });
});
});
chrome.commands.onCommand.addListener(function(command) {
console.log(command);
if (command === 'busyfy') {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
if (url.includes('steemit.com')) {
chrome.tabs.getSelected(null, function (tab) {
var code = url.replace('steemit.com', 'busy.org');
chrome.tabs.update(tab.id, {url: code});
});
}
else if (url.includes('busy.org')) {
chrome.tabs.getSelected(null, function (tab) {
var code = url.replace('busy.org', 'steemit.com');
chrome.tabs.update(tab.id, {url: code});
});
}
});
}
else if (command === 'steemdify') {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
if (url.includes('steemit.com')) {
chrome.tabs.getSelected(null, function (tab) {
var code = url.replace('steemit.com', 'steemd.com');
chrome.tabs.update(tab.id, {url: code});
});
}
else if (url.includes('steemd.com')) {
chrome.tabs.getSelected(null, function (tab) {
var code = url.replace('steemd.com', 'steemit.com');
chrome.tabs.update(tab.id, {url: code});
});
}
});
}
});