This repository has been archived on 2020-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
angularjs-batarang/js/services/chromeExtension.js

28 lines
777 B
JavaScript
Raw Normal View History

// abstraction layer for Chrome Extension APIs
2012-07-02 21:09:51 +00:00
panelApp.value('chromeExtension', {
sendRequest: function (requestName, cb) {
chrome.extension.sendRequest({
script: requestName,
tab: chrome.devtools.inspectedWindow.tabId
}, cb || function () {});
},
// evaluates in the context of a window
//written because I don't like the API for chrome.devtools.inspectedWindow.eval;
// passing strings instead of functions are gross.
eval: function (fn, args, cb) {
// with two args
if (!cb && typeof args === 'function') {
cb = args;
args = {};
} else if (!args) {
args = {};
}
chrome.devtools.inspectedWindow.eval('(' +
fn.toString() +
'(window, ' +
JSON.stringify(args) +
'));', cb);
}
});