-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnextjs.js
54 lines (51 loc) · 1.77 KB
/
nextjs.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// listens for message from button click from toolbar in background.js
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
const versionScript = document.createElement("script");
if (message.action === "updateBadgeText") {
versionScript.src = chrome.runtime.getURL("inject-script-badgetext.js");
versionScript.onload = function autoUnload() {
this.remove;
};
} else if (message.action === "showNextJsData") {
versionScript.src = chrome.runtime.getURL("inject-script-showdata.js");
versionScript.onload = function autoUnload() {
this.remove;
};
}
document.body.appendChild(versionScript);
});
// https://developer.chrome.com/extensions/content_scripts#host-page-communication
window.addEventListener(
"message",
function(event) {
// We only accept messages from ourselves
if (event.source != window) return;
if (event.data.type && event.data.type == "BADGE_TEXT") {
chrome.runtime.sendMessage(
{
messageType: event.data.type,
nextJsData: event.data.nextJsData,
nextJsDataLength: event.data.nextJsData.length
},
function(response) {
// for now, nothing to do here. just sending message and return will
// come frm a sendMessage in inject-script.js
}
);
}
if (event.data.type && event.data.type == "SHOW_DATA") {
chrome.runtime.sendMessage(
{
messageType: event.data.type,
nextJsData: event.data.nextJsData,
nextJsDataLength: event.data.nextJsData.length
},
function(response) {
// for now, nothing to do here. just sending message and return will
// come frm a sendMessage in inject-script.js
}
);
}
},
false
);