-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
63 lines (60 loc) · 2.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
var rule = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostPrefix: 'github.com', pathSuffix: '.htm' }
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostPrefix: 'github.com', pathSuffix: '.html' }
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'kaivalyar.github.io', pathPrefix: '/htmlpreview'}
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'kaivalyar.github.io', pathPrefix: 'htmlpreview'}
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'kaivalyarawal.com', pathPrefix: 'GitPreview'}
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'kaivalyarawal.com', pathPrefix: '/GitPreview'}
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
};
chrome.runtime.onInstalled.addListener(function(details) {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([rule]);
});
});
chrome.pageAction.onClicked.addListener(function(tab) {
var tabUrl = "unknown error"
chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
var activeTab = arrayOfTabs[0];
tabUrl = activeTab.url;
});
chrome.tabs.getCurrent(function (tab) {
var myNewUrl = "kaivalyar.github.io/htmlpreview"
if (tabUrl.indexOf('kaivalyar.github.io/htmlpreview/?') !== -1) { // ie if url contains 'kaivalyar.github.io/htmlpreview/?'
var myNewUrl = tabUrl.substring(tabUrl.indexOf('?')+1)
} else {
var myNewUrl = "http://kaivalyar.github.io/htmlpreview/?" + tabUrl;
}
chrome.tabs.update({url: myNewUrl});
});
});
chrome.commands.onCommand.addListener(function(command) {
var tabUrl = "unknown error"
chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
var activeTab = arrayOfTabs[0];
tabUrl = activeTab.url;
});
chrome.tabs.getCurrent(function (tab) {
var myNewUrl = "kaivalyarawal.com/GitPreview"
if (tabUrl.indexOf('kaivalyarawal.com/GitPreview/?') !== -1) { // ie if url contains 'kaivalyar.github.io/htmlpreview/?'
var myNewUrl = tabUrl.substring(tabUrl.indexOf('?')+1)
} else {
var myNewUrl = "http://kaivalyarawal.com/GitPreview/?" + tabUrl;
}
chrome.tabs.update({url: myNewUrl});
});
});