Skip to content

Commit

Permalink
fix: Update support for flathub.org and drop beta support
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
CleoMenezesJr committed Apr 25, 2023
1 parent 8a036ed commit f0604d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
31 changes: 12 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const checkExist = setInterval(() => {
const url = new URL(window.location);
const pathname = url.pathname;

if (url.hostname === "beta.flathub.org")
replaceFlathubBetaButton(pathname);
else if (url.hostname === "flathub.org") replaceFlathubLink(pathname);
if (url.hostname === "flathub.org") replaceFlathubButton(pathname);
else if (url.hostname === "apps.gnome.org")
replaceAppsGnomeLink(pathname);
else if (url.hostname === "appcenter.elementary.io")
Expand Down Expand Up @@ -37,13 +35,7 @@ function replaceAppsGnomeLink(pathname) {
appsGnomeInstallButton.href = "appstream:" + app;
}

function replaceFlathubLink(pathname) {
const flathubInstallButton = document.querySelector("[download]");
if (pathname.includes("/details/"))
flathubInstallButton.href = "appstream:" + pathname.split("/")[3];
}

function replaceFlathubBetaButton(pathname) {
function replaceFlathubButton(pathname) {
const languageButtonsLabel = {
id: "Pasang",
"pt-BR": "Instalar",
Expand Down Expand Up @@ -97,16 +89,17 @@ function replaceFlathubBetaButton(pathname) {
)
.snapshotItem(0);

let newButton = oldButton.cloneNode(true);
const occurrences = (pathname.match(/\//g) || []).length;
const app =
occurrences == 3 ? pathname.split("/")[3] : pathname.split("/")[2];

if (newButton.id != "customInstallButton") {
newButton.id = "customInstallButton";
newButton.onclick = () => (window.location = "appstream:" + app);
if (oldButton) {
let newButton = oldButton.cloneNode(true);

oldButton.parentNode.replaceChild(newButton, oldButton);
if (newButton.id != "customInstallButton") {
newButton.id = "customInstallButton";
newButton.removeAttribute("href");
newButton.href =
"appstream:" +
oldButton.href.split("/").pop().replace(".flatpakref", "");
oldButton.parentNode.replaceChild(newButton, oldButton);
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Flatline",
"version": "1.5",
"version": "1.6",

"description": "Select apps directly from your favorite software center by clicking Install from Flathub, apps.gnome and AppCenter.",

Expand All @@ -13,7 +13,6 @@
{
"matches": [
"https://flathub.org/*",
"https://beta.flathub.org/*",
"https://apps.gnome.org/*",
"https://appcenter.elementary.io/*"
],
Expand Down

0 comments on commit f0604d5

Please sign in to comment.