Skip to content

Commit

Permalink
firefox trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Incpi committed Dec 22, 2024
1 parent 2596d5a commit 7361767
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 27 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ We guarantee:

## Installation

> [!WARNING]
> No Firefox browser support.
To install the Dark CPI Extension, please follow these steps:

1. **Download the Extension:**

- Visit
the [Chrome Web Store](https://chromewebstore.google.com/detail/dark-sap-cpi/lmegddleeigeddljmdkonofmppbefneo)
or [EDGE store](https://microsoftedge.microsoft.com/addons/detail/gpafgeambljleonppfbeieehlmdiffop) or search
or [EDGE store](https://microsoftedge.microsoft.com/addons/detail/gpafgeambljleonppfbeieehlmdiffop)
or [FireFox](https://addons.mozilla.org/en-US/firefox/addon/dark-cpi/) or search
for "Dark CPI" in web-stores.
- Click "Add to Chrome" to install the extension.

Expand Down Expand Up @@ -84,6 +82,9 @@ The extension comes with the following predefined themes:

## Changelogs

### v2.1.0
- [Feature] FireFox support Has been added.

### v2.0.0

- [Feature] Updated in Native UI5.
Expand Down
27 changes: 19 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
"use strict";

chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
browser.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 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" });
// Send a message to check if the script is already injected
await browser.tabs.sendMessage(tabId, { action: "checkInjected" });
} catch (error) {
console.log("injecting files...");
console.log("Injecting files...");

try {
await chrome.scripting.executeScript({
// Inject the scripts using browser.scripting (compatible with Firefox)
await browser.scripting.executeScript({
target: { tabId },
files: ["script/OnInit.js"],
});
await chrome.scripting.executeScript({

await browser.scripting.executeScript({
target: { tabId },
files: ["script/main_script.js"],
world: "MAIN",
world: "MAIN", // Optional: define the execution world
});
} catch (error) {
console.log(error);
console.log("Error injecting scripts:", error);
}
}
}
Expand Down
Binary file removed bin/Dark CPI Extension.zip
Binary file not shown.
Binary file removed bin/Dark CPI.zip
Binary file not shown.
6 changes: 2 additions & 4 deletions docs/readme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ We guarantee:

## Installation

> [!WARNING]
> No Firefox browser support.
To install the Dark CPI Extension, please follow these steps:

1. **Download the Extension:**

- Visit
the [Chrome Web Store](https://chromewebstore.google.com/detail/dark-sap-cpi/lmegddleeigeddljmdkonofmppbefneo)
or [EDGE store](https://microsoftedge.microsoft.com/addons/detail/gpafgeambljleonppfbeieehlmdiffop) or search
or [EDGE store](https://microsoftedge.microsoft.com/addons/detail/gpafgeambljleonppfbeieehlmdiffop)
or [FireFox](https://addons.mozilla.org/en-US/firefox/addon/dark-cpi/) or search
for "Dark CPI" in web-stores.
- Click "Add to Chrome" to install the extension.

Expand Down
12 changes: 10 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"manifest_version": 3,
"name": "Dark CPI",
"version": "2.0.1",
"browser_specific_settings": {
"gecko": {
"id": "DarkSAPCPI@incpi",
"strict_min_version": "109.0"
}
},
"version": "2.1.0",
"description": "Extension provides control to change theme to dark mode for SAP integration suite (CPI)",
"author": "Omkar Patel",
"homepage_url": "https://incpi.vercel.app/blog/83efd",
"background": {
"service_worker": "background.js"
"scripts": [
"background.js"
]
},
"host_permissions": [
"https://*.hana.ondemand.com/*",
Expand Down
48 changes: 48 additions & 0 deletions manifest_c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"manifest_version": 3,
"name": "Dark CPI",
"version": "2.1.0",
"description": "Extension provides control to change theme to dark mode for SAP integration suite (CPI)",
"author": "Omkar Patel",
"homepage_url": "https://incpi.vercel.app/blog/83efd",
"background": {
"service_worker": "background.js"
},
"host_permissions": [
"https://*.hana.ondemand.com/*",
"https://*.platform.sapcloud.cn/*"
],
"icons": {
"128": "/images/icon128.png",
"48": "/images/icon48.png",
"32": "/images/icon32.png",
"16": "/images/icon16.png"
},
"permissions": [
"scripting",
"tabs"
],
"content_scripts": [
{
"matches": [
"https://*.hana.ondemand.com/*",
"https://*.platform.sapcloud.cn/*"
],
"css": [
"utils/styles.css"
]
}
],
"web_accessible_resources": [
{
"matches": [
"https://*.hana.ondemand.com/*",
"https://*.platform.sapcloud.cn/*"
],
"resources": [
"utils/*.js",
"images/*"
]
}
]
}
14 changes: 9 additions & 5 deletions script/OnInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
console.log("Start initial script");

window.addEventListener("requestDataChromeApi", (event) => {
if (event.detail.request == "chromeExtensionURL") {
let detail = {};
if (event.detail.request == "DARKCPI") {
let detail;
try {
detail.url = chrome.runtime.getURL("/");
if (typeof chrome !== "undefined" && chrome.runtime && chrome.runtime.getURL) {
detail = chrome.runtime.getURL("/"); // Get extension's URL in Chrome
} else if (typeof browser !== "undefined" && browser.runtime && browser.runtime.getURL) {
detail = browser.runtime.getURL("/"); // Get extension's URL in Firefox
}
window.dispatchEvent(new CustomEvent("resposeDataChromeApi", { detail }));
} catch (error) {
console.log(error);
console.log("Error while fetching extension URL:", error);
}
}
});
});
6 changes: 3 additions & 3 deletions script/main_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ window.askChromeExtensionURL = () => {
return new Promise((resolve, reject) => {
window.addEventListener("resposeDataChromeApi", (event) => {
window.removeEventListener("resposeDataChromeApi", this);
resolve(event.detail.url);
resolve(event.detail);
});
let detail = {};
detail.request = "chromeExtensionURL";
detail.request = "DARKCPI";
window.dispatchEvent(new CustomEvent("requestDataChromeApi", { detail }));
setTimeout(() => reject("Cannot get chrome extension URL"), 200);
});
Expand Down Expand Up @@ -41,7 +41,7 @@ window.startProcess = () => {
});
})
.catch((message) => {
console.log(message);
console.log("Error:", message);
window.startProcess();
});
};
Expand Down
3 changes: 2 additions & 1 deletion utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ sap.ui.define([], function() {
"use strict";
return {
prefixId: "DarkCPI_",
manifestVersion: "2.0.1",
manifestVersion: "2.1.0",
data_update_label: { bugFixes: "Bug Fixes", improvements: "Improvements", features: "Features" },
data_updates: {
bugFixes: [], features: [], improvements: [
{ description: "FireFox support has been added." },
{ description: "Load time was decreased by optimizing the extension runtime." },
{ description: "Decreased extension size and external libraries." },
{ description: "Limited CSS overwrites to ensure a seamless native experience." },
Expand Down

0 comments on commit 7361767

Please sign in to comment.