This repository has been archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
searchGoogle.js
45 lines (41 loc) · 1.66 KB
/
searchGoogle.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
(function($){JOBAD.modules.register({
info: {
'identifier': 'searchGoogle',
'title': 'Search Google',
'author': 'Alexandru Toader',
'description': 'Search Google for selected text or for the title of a node. ',
'hasCleanNamespace': false
},
getSelectedText: function () {
var selectedText = (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text
);
if (!selectedText || selectedText == "") {
if (document.activeElement && document.activeElement.selectionStart) {
selectedText = document.activeElement.value.substring(document.activeElement.selectionStart.document.activeElement.selectionEnd);
}
}
return selectedText;
},
contextMenuEntries: function (target) {
var txt = this.getSelectedText().toString();
var text = "Search Google for ";
if (txt && txt.replace(/\s+/g, ' ') != '') {
text += '"' + txt.substring(0, 5) + ".." + '""';
return [
[text, function (element) {
window.open("http://www.google.com/search?q=" + txt, "_parent");
}]
];
} else if (target.attr('class') == 'node' && target.is('div')) {
console.log("here");
txt = target.text();
text += '"' + txt.substring(0, 5) + ".." + '""';
return [
[text, function (element) {
window.open("http://www.google.com/search?q=" + txt, "_parent");
}]
];
}
},
});
})(JOBAD.refs.$);