-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvk-content.js
30 lines (27 loc) · 866 Bytes
/
vk-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
if (!document.getElementById('vkps_injection')) {
var e = document.createElement('script');
e.id = 'vkps_injection';
e.src = chrome.extension.getURL('vk-inject.js');
document.head.appendChild(e);
var dataUrlRequest = false;
var dataUrlReady = false;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.message == 'attachDataUrl') {
dataUrlRequest = request;
if (dataUrlReady) {
window.postMessage(dataUrlRequest, '*');
}
}
});
window.addEventListener('message', function(event) {
if (event.data.message == 'attachDataUrlReady') {
dataUrlReady = true;
if (dataUrlRequest) {
window.postMessage(dataUrlRequest, '*');
}
} else
if (event.data.message == 'attachDataUrlSuccess') {
chrome.runtime.sendMessage(event.data);
}
});
}