-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
112 lines (103 loc) · 2.95 KB
/
background.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
let currentTabId;
let tabId;
let previousTab;
function onError(error) {
console.error(`Error occurred: ${error.message}`);
}
function setButtonIcon(imageURL) {
try {
browser.browserAction.setIcon({ path: imageURL });
} catch (e) {
onError(e);
}
}
async function createPinnedTab() {
try {
let tab = await browser.tabs.create({
url: "https://copilot.microsoft.com",
pinned: true,
active: true,
});
tabId = tab.id;
} catch (error) {
console.error(error);
}
}
// Handle the search for existing tabs with the specified URL
async function handleSearch(customTabs) {
if (customTabs.length > 0) {
tabId = customTabs[0].id;
let { faviconOption } = await browser.storage.local.get("faviconOption");
if (faviconOption === "website") {
setButtonIcon(customTabs[0].favIconUrl);
} else {
setButtonIcon("icons/icon-128.png");
}
} else {
await createPinnedTab();
}
if (tabId === currentTabId) {
browser.tabs.update(previousTab, { active: true });
} else {
previousTab = currentTabId;
browser.tabs.update(tabId, { active: true });
}
}
async function handleClick(tab) {
currentTabId = tab.id;
try {
// Search for existing tabs with the specified URL
const customTabs = await browser.tabs.query({
pinned: true,
url: `*://www.bing.com/*`,
});
await handleSearch(customTabs);
} catch (error) {
onError(error);
}
}
// Handle options page
function update(details) {
if (details.reason === "install" || details.reason === "update") {
browser.runtime.openOptionsPage();
}
}
browser.browserAction.onClicked.addListener(async (tab) => {
await handleClick(tab);
});
browser.runtime.onInstalled.addListener(update);
(() => {
"use strict";
const e = navigator.userAgent.toLowerCase().includes("firefox"),
r = (e, r) =>
navigator.userAgent.includes("Firefox")
? r
? `Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.3 ${e}`
: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.3 ${e}`
: `${navigator.userAgent} ${e}`;
e &&
chrome.webRequest.onBeforeSendHeaders.addListener(
(e) => {
const { requestHeaders: a } = e;
if ((console.log(a), a))
return {
requestHeaders: a.map((e) => {
var a;
return (
"user-agent" === e.name.toLowerCase() &&
((
null === (a = e.value) || void 0 === a
? void 0
: a.toLowerCase().includes("mobile")
)
? (e.value = r("EdgA/130.0.2849.68", !0))
: (e.value = r("Edg/130.0.0.", !1))),
e
);
}),
};
},
{ urls: ["*://*.bing.com/*"] },
["blocking", "requestHeaders"]
);
})();