-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
54 lines (47 loc) · 1.48 KB
/
content.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
/* global chrome, SearchEngine, Utilities */
function getSelectors(engine, callback) {
'use strict';
chrome.runtime.sendMessage({
action: 'get-selectors',
engine: engine
}, callback);
return true;
}
function addPreprocessEntry(searchEngine) {
'use strict';
var engine = searchEngine.getEngine();
if (engine === 'Google') {
searchEngine.preprocessEntry = function(entry) {
var anchor = $(entry).find('a');
var href = $(anchor).attr('data-href') || $(anchor).attr('href');
$(anchor).attr('actual-href', href);
};
} else if (engine === 'Bing') {
searchEngine.preprocessEntry = function(entry) {
var anchor = $(entry).find('a');
var href = $(anchor).attr('href');
$(anchor).attr('actual-href', href);
};
} else if (engine === 'Yahoo') {
searchEngine.preprocessEntry = function(entry) {
var anchor = $(entry).find('a');
var href = $(anchor).attr('href');
var regex = /RU=([^/]*)/;
href = decodeURIComponent(href.match(regex)[1]);
$(anchor).attr({ 'actual-href': href, 'target': '_self' });
};
}
}
function initExtension() {
'use strict';
window.addEventListener('unload', function() { Utilities.sendBuffer(); });
Utilities.registerUser();
var searchEngine = new SearchEngine();
var engine = searchEngine.getEngine();
getSelectors(engine, function(selectors) {
searchEngine.selectors = selectors;
addPreprocessEntry(searchEngine);
searchEngine.init();
});
}
initExtension();