-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (54 loc) · 1.51 KB
/
main.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
var options;
//To display the icon
chrome.extension.sendRequest({}, function(response) {
options = response;
});
$(document).ready(function(){
var currPageSize = 2; //Average page size as expected of 2014
var currPageurl = "https://www.google.com";
chrome.extension.sendRequest({
pageSize: currPageSize,
pageUrl: currPageurl,
prerender: false
}, function(response) {
options = response;
});
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if(options.url1 || options.url2 || options.url3 || options.url4 || options.url5){
if (!request.pageUrl.indexOf('http') == 0)
url = 'http://' + url;
if(request.pageSize && request.pageUrl && request.prerender){
//Enabling Prerender
var state = document.visibilityState || document.webkitVisibilityState;
if (state != 'visible') {
var id = document.location.search.replace('?prerender-id=', '');
window.localStorage.setItem('prerender-enabled-' + id, 'true');
}
var body = document.getElementsByTagName("body")[0];
var a = document.createElement('a');
a.rel = "prerender";
switch(options.openurl){
case 0:
a.href = options.url1;
break;
case 1:
a.href = options.url2;
break;
case 2:
a.href = options.url3;
break;
case 3:
a.href = options.url4;
break;
case 4:
a.href = options.url5;
break;
}
body.append(a);
}
}
sendResponse(settings.toObject());
}
);
});