-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
28 lines (27 loc) · 1.02 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
"use strict";
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === "complete" && tab.url) {
const regexPatterns = [/^https:\/\/.*\.hana\.ondemand\.com\/itspaces\/shell\/.*/, /^https:\/\/.*\.hana\.ondemand\.com\/shell\/.*/, /^https:\/\/.*\.platform\.sapcloud\.cn\/itspaces\/shell\/.*/, /^https:\/\/.*\.platform\.sapcloud\.cn\/shell\/.*/];
const isMatch = regexPatterns.some((pattern) => pattern.test(tab.url));
if (isMatch) {
try {
await chrome.tabs.sendMessage(tabId, { action: "checkInjected" });
} catch (error) {
console.log("injecting files...");
try {
await chrome.scripting.executeScript({
target: { tabId },
files: ["script/OnInit.js"],
});
await chrome.scripting.executeScript({
target: { tabId },
files: ["script/main_script.js"],
world: "MAIN",
});
} catch (error) {
console.log(error);
}
}
}
}
});