-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinject.js
21 lines (19 loc) · 823 Bytes
/
inject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/
var doClick = function(className) {
var node = document.getElementsByClassName(className)[0];
var evt = document.createEvent('MouseEvents');
evt.initEvent('click', true, false);
node.dispatchEvent(evt);
};
// Simulate clicking on elements by class name
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request.cmd == "play-pause")
doClick("playControl");
else if(request.cmd == "next")
doClick("skipControl__next");
else if(request.cmd == "prev")
doClick("skipControl__previous");
});
// This will be received by background.js so it can get soundcloud's tab id
chrome.runtime.sendMessage({msg: "foo"});