|
@@ -1,3 +1,28 @@
|
|
|
+// background.js
|
|
|
+chrome.runtime.onInstalled.addListener(function () {
|
|
|
+ console.log("插件已被安装");
|
|
|
+});
|
|
|
+
|
|
|
+let rinfo = {}
|
|
|
+
|
|
|
+chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
+ if (request.action === "show_popup") {
|
|
|
+ const info = request.data;
|
|
|
+ let n = chrome.windows.create({
|
|
|
+ url: chrome.runtime.getURL("page.html"), // 指向你的弹出页面
|
|
|
+ }, (newTab) => {
|
|
|
+ rinfo[newTab.tabs[0].id] = info
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+// 监听已更新的标签,以找出何时打开了 page.html
|
|
|
+chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
|
+ if (changeInfo.status === 'complete' && tab.url.includes('page.html')) {
|
|
|
+ chrome.tabs.sendMessage(tabId, { msgToPopup: rinfo[tabId] + new Date().toString() });
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
// // background.js
|
|
|
// chrome.runtime.onInstalled.addListener(function () {
|
|
|
// console.log("插件已被安装");
|