Si tratta di una cosa sandbox, suppongo che non sia consentito eseguire script dalla pagina, quindi credo che i plugin contino.
Questo noto il suo solo una questione di giocare al di fuori della sandbox ....
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/*"
]
}
Potete vedere alcune cose sulla comunicazione con la pagina qui ... http://code.google.com/chrome/extensions/content_scripts.html
In quale file hai messo questo codice? Immagino che il codice non venga eseguito sulla pagina, ma piuttosto la pagina di sfondo per l'estensione. – mowwwalker
@Walkerneo Sto eseguendo questo in uno dei file JS "content_scripts". – PeeHaa
@Walkerneo Ho aggiunto un collegamento al progetto per poterlo verificare. – PeeHaa