-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
29 lines (25 loc) · 1.23 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// data common to all content scripts
var CHAT_FRAME_ID = "irc-iframe";
var CHAT_LIST_TEXT = "Chat";
var CHAT_FRAME = "<iframe src=\"https://kiwiirc.com/client/irc.freenode.net/\" id=\"" + CHAT_FRAME_ID + "\" style=\"border:0; width:100%; height:100%;\"></iframe>";
var courseId; // gets set by below event handler
// let content scripts fetch their current URL via messaging background.js
var getCurrentUrl = function(callback) {
chrome.runtime.sendMessage("getCurrentUrl", function(response) {
callback(response.url);
});
};
// Every vendor (Piazza, BB, etc.) content script needs to listen for
// requests from the background page (content scripts can't message each other, so the
// background page is an intermediary) to get their courseId.
// Listen for a courseId request and fulfill it with getCourseId(), whose implementation
// varies from vendor to vendor
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
if (message == "getCourseId") {
getCourseId(function(courseId) {
sendResponse({courseId: courseId});
});
return true; // keep message channel open to be able to call sendResponse asynchronously in a callback
}
});