-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
112 lines (102 loc) · 2.98 KB
/
main.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
const checkExist = setInterval(() => {
let title = document.querySelector("title");
if (title != null) {
function callback(mutations) {
const url = new URL(window.location);
const pathname = url.pathname;
if (url.hostname === "flathub.org") replaceFlathubButton(pathname);
else if (url.hostname === "apps.gnome.org")
replaceAppsGnomeLink(pathname);
else if (url.hostname === "appcenter.elementary.io")
replaceAppCenterLink(pathname);
}
let observer = new MutationObserver(callback);
let config = {
childList: true,
subtree: true,
attributes: true,
characterData: true,
};
observer.observe(title, config);
clearInterval(checkExist);
callback();
}
}, 500);
function replaceAppsGnomeLink(pathname) {
const appsGnomeInstallButton = document.querySelector("a.text-button");
const occurrences = (pathname.match(/\//g) || []).length;
const app =
occurrences == 4 ? pathname.split("/")[3] : pathname.split("/")[2];
if (pathname.includes("/app/"))
appsGnomeInstallButton.href = "appstream:" + app;
}
function replaceFlathubButton(pathname) {
const languageButtonsLabel = {
id: "Pasang",
"pt-BR": "Instalar",
ca: "Instal·lar",
cs: "Nainstalovat",
de: "Installieren",
// "et" needs website translation
es: "Instalar",
eo: "Instali",
fr: "Installer",
hr: "Instaliraj",
it: "Installa",
lt: "Įdiegti",
hu: "Telepítés",
nl: "Installeren",
// "nb-NO" needs website translation
pl: "Zainstaluj",
pt: "Instalar",
fi: "Asenna",
vi: "Cài đặt",
tr: "Kur",
// "el" needs website translation
be: "Усталяваць",
bg: "Инсталиране",
ru: "Установить",
uk: "Установити",
ar: "ثبِّت",
fa: "نصب",
// "hi" needs website translation
bn: "ইনস্টল করুন",
ta: "நிறுவவும்",
si: "ස්ථාපනය",
ja: "インストール",
"zh-Hans": "安装",
"zh-Hant": "安裝",
};
let currentLanguage;
for (let key in languageButtonsLabel) {
if (pathname.includes(`/${key}/`)) {
currentLanguage = key;
}
}
let oldButton = document
.evaluate(
`//*[text()="${languageButtonsLabel[currentLanguage] || "Install"}"]`,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE
)
.snapshotItem(0);
if (oldButton) {
let newButton = oldButton.cloneNode(true);
if (newButton.id != "customInstallButton") {
newButton.id = "customInstallButton";
newButton.removeAttribute("href");
newButton.href =
"appstream:" +
oldButton.href.split("/").pop().replace(".flatpakref", "");
oldButton.parentNode.replaceChild(newButton, oldButton);
}
}
}
function replaceAppCenterLink(pathname) {
document.querySelectorAll("a").forEach((el) => {
if (el.innerText == "Download as Flatpak") {
el.href = "appstream:" + pathname;
}
});
}