-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
executable file
·52 lines (47 loc) · 1.65 KB
/
content_script.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
function inject_script(script_name){
var s = document.createElement('script');
s.src = chrome.extension.getURL(script_name);
(document.head||document.documentElement).appendChild(s);
//s.onload = function() {
// s.parentNode.removeChild(s);
//};
}
inject_script('generic_tools.js')
inject_script('inject.js')
console.log("script injected.")
document.addEventListener('from_injected', function(e) {
//console.log("sending message with history to extension");
chrome.runtime.sendMessage({detail: e.detail}, null);
});
//-----------------------------------
/*keep_scrolling = false;
function scrollUp(){
$('.nano.im_history_wrap').nanoScroller({scroll:'top'});
if (keep_scrolling){
setTimeout(scrollUp, 1000);
}
}*/
chrome.runtime.onMessage.addListener(function (request_msg, sender, sendResponse) {
console.log('content script received request '+request_msg.text);
if (request_msg.text === 'stch_check_conn') {
sendResponse({text : "OK"})
}
if (request_msg.text === 'stch_load_current_history') {
document.dispatchEvent(new CustomEvent('to_injected_current', {}));
}
if (request_msg.text === 'stch_load_more_history') {
document.dispatchEvent(new CustomEvent('to_injected_get_more',
{'detail':request_msg.value}));
}
if (request_msg.text === 'stch_open_photos') {
document.dispatchEvent(new CustomEvent('to_injected_open_photos',
{'detail':request_msg.value}));
}
/*if (request_msg.text === 'stch_start_scrolling_up'){
keep_scrolling = true;
scrollUp();
}
if (request_msg.text === 'stch_stop_scrolling'){
keep_scrolling = false;
}*/
});