-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
130 lines (114 loc) · 4.36 KB
/
background.js
File metadata and controls
130 lines (114 loc) · 4.36 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'scirate.com'},
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'scholar.google.com'},
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'arxiv.org'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
chrome.storage.sync.set({
isLoveSen: 0,
currentSen: 1,
readList: {}
});
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
chrome.storage.sync.set({url:tab.url}, function(){
});
chrome.tabs.executeScript(
tabId,//tabs[0].id,
{file: 'bg_1.js'},
_=>{
let e=chrome.runtime.lastError;
if(e!==undefined){
}
}
);
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
//console.log(sender.tab ?
// "from a content script:" + sender.tab.url :
// "from the extension");
if (request.sciteshref!==undefined){
sendResponse({farewell: "goodbye"});
//console.log('get scirate href');
var httpReq = new XMLHttpRequest();
httpReq.open('GET', request.sciteshref, true);
httpReq.setRequestHeader('Content-Type','text/html; charset=utf-8');
httpReq.setRequestHeader('Access-Control-Allow-Headers', '*');
httpReq.setRequestHeader('Access-Control-Allow-Origin', '*');
var fields={};
httpReq.onreadystatechange = function () {
//console.log('test');
if (httpReq.readyState === 4){// && httpReq.status === '200') {
console.log('read scites ready!');
//console.log(httpReq);
var rsp=httpReq.responseText;
if(rsp.match('Scites</h2>')!=null){
console.log('scites number exists');
var numberofscites=rsp.substring(rsp.match('Scites</h2>').index-10, rsp.match('Scites</h2>').index-1);
console.log(numberofscites);
numberofscites=numberofscites.substring(numberofscites.match('<h2>').index+4,);
console.log('nscites ready');
console.log(numberofscites);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {nscites:numberofscites, sciteshref:request.sciteshref}, function(response) {
console.log(response.farewell);
});
});
//chrome.storage.sync.set({nscites:numberofscites}, function(){
//chrome.storage.sync.remove('sciteshref', function(data){});
//console.log('sciteshref removed');
//} );
}
else{
if(rsp.match('Scite</h2>')!=null){
console.log('scites number exists');
var numberofscites=rsp.substring(rsp.match('Scite</h2>').index-10, rsp.match('Scite</h2>').index-1);
console.log(numberofscites);
numberofscites=numberofscites.substring(numberofscites.match('<h2>').index+4,);
console.log('nscites ready');
console.log(numberofscites);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {nscites:numberofscites, sciteshref:request.sciteshref}, function(response) {
console.log(response.farewell);
});
});
}
else {
console.log(rsp);
}
}
};
};
httpReq.send(fields);
};
});
chrome.tabs.onActivated.addListener(function(info){
chrome.tabs.query({active:true, currentWindow: true}, function(tabs){
var tabId=tabs[0].tabId, tabUrl=tabs[0].url;
if(tabUrl!==undefined){
chrome.storage.sync.set({url:tabUrl}, function(){
});
}
chrome.tabs.executeScript(
tabId,//tabs[0].id,
{file: 'bg_1.js'},
_=>{
let e=chrome.runtime.lastError;
if(e!==undefined){
}
}
);
});
});