在SO聊天中播放哔哔声

Pee*_*Haa 5 javascript chat google-chrome-extension

我正在尝试使用Chrome扩展程序在SO聊天中播放通知提示音(或提及哔声),但我无法正确使用(如果可能的话).我试过以下代码:

this.notify = function () {
  $("#jplayer").jPlayer('play', 0);
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

未捕获的TypeError:对象[object Object]没有方法'jPlayer'

有没有办法使用SO聊天声音"模块"/播放器播放@mention哔声?

UPDATE

我知道我可以设置我自己的"音频播放器",但我想在这里使用聊天中使用的音频播放器,我想使用通知蜂鸣声.

我已将我的完整代码上传到GitHub gist中,这是该项目的一部分.我试图调用音频播放器的行是224.

PAE*_*AEz 3

我猜它是一个沙箱,你不允许从页面执行脚本,所以我猜插件也算在内。
众所周知,这只是在沙盒之外玩的问题......

脚本.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);
Run Code Online (Sandbox Code Playgroud)

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);
  }
});
Run Code Online (Sandbox Code Playgroud)

清单.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/*"
  ]
}
Run Code Online (Sandbox Code Playgroud)

您可以在此处看到一些有关与页面通信的内容... http://code.google.com/chrome/extensions/content_scripts.html