Console.log('sI: about to establish extension connection fo

Fermé
AKAK2000 - 27 janv. 2016 à 19:17
 akak20001 - 27 janv. 2016 à 19:22
Bonjour,




console.log('sI: about to establish extension connection for WIDGET_CONTENT_MESSAGE - url: %s', document.URL);
if (!/^chrome-extension:.*\/bg.html/.test(document.URL)){
var port = chrome.extension.connect();
console.log('sI: adding WIDGET_CONTENT_MESSAGE message listener');
window.addEventListener('message', function(e){
console.log('sI: inside WIDGET_CONTENT_MESSAGE message listener: %O', e);
console.dir(e);
if (e.data && e.data.type == "WIDGET_CONTENT_MESSAGE"){
port.postMessage(e.data);
}
});

}


Messaging.addListener(
{ "cmd": 'INJECT_SCRIPT' },
function(message, sender, sendResponse) {
var file = message.file,
code = message.code;

if (file) {
injectFile(file);
}

if (code) {
injectCode(code);
}
}
);

Messaging.addListener(
{"cmd" : "INJECT_HTML"},

function(message, sender, sendResponse){
console.dir(message);
if(message.html){
injectHTML(message.html);
}
}
);


Messaging.addListener(
{ "cmd": 'INJECT_WIDGET_SCRIPT' },
function(message, sender, sendResponse) {
//console.dir(arguments);

function injector(){
if (!document || !document.body){
window.setTimeout(injector, 100);
return;
}

var file = message.file,
code = message.code,
namespace = message.namespace,
m2Send = JSON.stringify(message);

if(!FLAG){
injectFile(chrome.extension.getURL('js/widgetContentScriptInjectee.js'),function(){

injectCode("window.widgetContentScriptFunction("+m2Send+")");
});
FLAG = true;
}

if (file) {
injectFile(file);
}

if (code) {
injectCode(code);
}
}

injector();
}
);



return {
injectFile: injectFile,
injectCode: injectCode
};

1 réponse

http://www.youtube.com/user/akak20001
0
djnaly-youtube
0