Supongo que es una cosa de sandbox, no se te permite ejecutar scripts desde la página, así que supongo que los complementos cuentan.
la que se conoce que es sólo una cuestión de jugar fuera de la caja de arena ....
script.js
var customEvent = document.createEvent('Event');
customEvent.initEvent('JPlayerNotify', true, true);
function notify() {
document.getElementById('communicationDIV').innerText='notify';
document.getElementById('communicationDIV').dispatchEvent(customEvent);
}
// Utitlity function to append some js into the page, so it runs in the context of the page
function appendScript(file) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.setAttribute("src", chrome.extension.getURL(file));
document.head.appendChild(script);
}
appendScript("JPlayer.js");
// had to wait for a bit for the page to be ready (dialup and all), you wont need to do the setTimeout
setTimeout("notify()",3500);
JPlayer.js
var notify_node = document.createElement('div');
notify_node.id = 'communicationDIV';
document.documentElement.appendChild(notify_node);
notify_node.addEventListener('JPlayerNotify', function() {
var eventData = notify_node.innerText;
if (eventData=='notify'){
$("#jplayer").jPlayer('play', 0);
}
});
manifest.json
{
"name": "JPlayerNotify",
"version": "0.5.0",
"description": "JPlayerNotify",
"content_scripts" : [
{
"matches": ["http://chat.stackoverflow.com/rooms/*"],
"js" : ["script.js"],
"run_at" : "document_idle",
"all_frames" : false
}
],
"permissions": [
"http://stackoverflow.com/*",
"https://stackoverflow.com/*",
"http://*.stackoverflow.com/*",
"https://*.stackoverflow.com/*"
]
}
Se puede ver un poco de materia en la comunicación con la página de aquí ... http://code.google.com/chrome/extensions/content_scripts.html
En qué archivo le has puesto este código? Supongo que el código no se está ejecutando en la página, sino más bien la página de fondo de la extensión. – mowwwalker
@Walkerneo Estoy ejecutando esto en uno de los archivos JS "content_scripts". – PeeHaa
@Walkerneo Agregué un enlace al proyecto para que pueda verificarlo. – PeeHaa