Skip to content

Commit

Permalink
Modify install button on new webstore preview
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverDecaf committed Sep 13, 2023
1 parent dc26b23 commit 8169bfc
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 38 deletions.
Binary file modified Chromium Web Store.crx
Binary file not shown.
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "__MSG_extension_Name__",
"description": "__MSG_extension_Description__",
"default_locale": "en",
"version": "1.5.3.1",
"version": "1.5.4",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqF/d41Q7agjkUzYq8ZGbQr8XW8mmEIMXOnR1uCTnYLL+Dm9Z+LO50xZukOISNy6zFxpI8ts/OGLsm+I2x9+UprUU4/EVdmxuwegFE6NBoEhHoRNYY0gbXZkaU8YY/XwzjVY/k18DDhl5NYPEnF6uq4Oyidg+xtd3W4+iGYczuOLER1Tp5y614zOTphcvFYhvUkCijQ6HT1TtRq/34SlFoRQqo4SFiLriK451xWIcfwiMLIekWrdoQa1v8dqIlMA3r6CKc0QykJpSYbiyormWiZ0hl2HLpkZ85mD9V0eDQ5RCtb6vkybK7INcq4yKQV4YkXhr9NpX9U4re4dlFQjEJQIDAQAB",
"permissions": [
"management",
Expand All @@ -27,6 +27,7 @@
{
"matches": [
"https://chrome.google.com/webstore*",
"https://chromewebstore.google.com/*",
"https://addons.opera.com/*extensions/details/*",
"https://microsoftedge.microsoft.com/addons/*"
],
Expand Down
19 changes: 10 additions & 9 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function handleContextClick(info, tab) {
installed_versions,
appid,
updatever,
is_webstore
is_webstore,
) {
let crx_url = updateCheck["@codebase"];
promptInstall(crx_url, is_webstore, WEBSTORE.chrome, msgHandler);
Expand Down Expand Up @@ -53,12 +53,12 @@ function startupTasks() {
(Date.now() -
localstore.last_scheduled_update) /
1000 /
60
)
60,
),
),
periodInMinutes: settings.update_period_in_minutes,
});
}
},
);
});
}
Expand All @@ -76,7 +76,7 @@ chrome.management.onInstalled.addListener(function (ext) {
},
() => {
if (chrome.runtime.lastError) tabsAwaitingInstall.delete(tabid);
}
},
);
}
});
Expand All @@ -101,7 +101,7 @@ chrome.alarms.onAlarm.addListener(function (alarm) {
periodInMinutes: settings.update_period_in_minutes,
});
}
}
},
);
});
chrome.runtime.onInstalled.addListener(function () {
Expand All @@ -121,6 +121,7 @@ chrome.runtime.onInstalled.addListener(function () {
id: "installExt",
documentUrlPatterns: [
"https://chrome.google.com/webstore/detail/*",
"https://chromewebstore.google.com/detail/*",
"https://addons.opera.com/*/extensions/details/*",
"https://microsoftedge.microsoft.com/addons/detail/*",
],
Expand All @@ -134,7 +135,7 @@ const msgHandler = function (request, sender, sendResponse) {
},
(dlid) => {
nonWebstoreExtensionsDownloading.add(dlid);
}
},
);
}
if (request.manualInstallDownloadUrl) {
Expand All @@ -145,7 +146,7 @@ const msgHandler = function (request, sender, sendResponse) {
},
(dlid) => {
manualInstallExtensionsDownloading.add(dlid);
}
},
);
}
if (request.newTabUrl) {
Expand Down Expand Up @@ -189,7 +190,7 @@ chrome.downloads.onChanged.addListener((d) => {
},
(tab) => {
extensionsTabId.id = tab.id;
}
},
);
});
// chrome.notifications.create("manually_install", {
Expand Down
82 changes: 71 additions & 11 deletions src/scripts/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function createButton(newParent, addBtn = true) {
button_div.setAttribute("role", "button");
button_div.setAttribute(
"class",
"dd-Va g-c-wb g-eg-ua-Uc-c-za g-c-Oc-td-jb-oa g-c"
"dd-Va g-c-wb g-eg-ua-Uc-c-za g-c-Oc-td-jb-oa g-c",
);

button_div.setAttribute("tabindex", "0");
Expand All @@ -27,7 +27,7 @@ function createButton(newParent, addBtn = true) {
"aria-label",
isInstall
? chrome.i18n.getMessage("webstore_addButton")
: chrome.i18n.getMessage("webstore_removeButton")
: chrome.i18n.getMessage("webstore_removeButton"),
);
r.innerHTML = isInstall
? chrome.i18n.getMessage("webstore_addButton")
Expand All @@ -52,7 +52,7 @@ function createButton(newParent, addBtn = true) {
if (resp.uninstalled) {
button_div.toggleState(true);
}
}
},
);
}
});
Expand All @@ -66,6 +66,40 @@ function createButton(newParent, addBtn = true) {
newParent.appendChild(button_div);
dlBtn = button_div;
}
function modifyNewCWSButton(button_div, addBtn = true) {
button_div.removeAttribute("disabled");
const label = button_div.querySelector("span.UywwFc-vQzf8d");
button_div.toggleState = function (isInstall) {
isInstall
? button_div.setAttribute("isInstallBtn", "true")
: button_div.setAttribute("isInstallBtn", "false");
label.innerHTML = isInstall
? chrome.i18n.getMessage("webstore_addButton")
: chrome.i18n.getMessage("webstore_removeButton");
};
button_div.toggleState(addBtn);
let dlurl = buildExtensionUrl(window.location.href);
button_div.id = getExtensionId(window.location.href);
button_div.addEventListener("click", function () {
if (button_div.getAttribute("isInstallBtn") == "true") {
chrome.runtime.sendMessage({
installExt: getExtensionId(window.location.href),
});
promptInstall(dlurl, true);
} else {
chrome.runtime.sendMessage(
{
uninstallExt: getExtensionId(window.location.href),
},
(resp) => {
if (resp.uninstalled) {
button_div.toggleState(true);
}
},
);
}
});
}
var modifyButtonObserver = new MutationObserver(function (mutations, observer) {
mutations.forEach(function (mutation) {
if (
Expand All @@ -79,12 +113,12 @@ var modifyButtonObserver = new MutationObserver(function (mutations, observer) {
chrome.runtime.sendMessage(
{
checkExtInstalledId: getExtensionId(
window.location.href
window.location.href,
),
},
(resp) => {
createButton(container_div, !resp.installed);
}
},
);
}
}
Expand All @@ -99,6 +133,27 @@ attachMainObserver = new MutationObserver(function (mutations, observer) {
});
observer.disconnect();
});
var modifyButtonObserverNew = new MutationObserver(function (
mutations,
observer,
) {
mutations.forEach(function (mutation) {
const btn = mutation.target.querySelector(
"button.UywwFc-LgbsSe-OWXEXe-dgl2Hf",
);
if (btn && !btn.hasAttribute("isInstallBtn")) {
btn.setAttribute("isInstallBtn", "true");
chrome.runtime.sendMessage(
{
checkExtInstalledId: getExtensionId(window.location.href),
},
(resp) => {
modifyNewCWSButton(btn, !resp.installed);
},
);
}
});
});
if (is_ews.test(window.location.href)) {
new MutationObserver(function (mutations, observer) {
mutations.forEach(function (mutation) {
Expand All @@ -110,18 +165,18 @@ if (is_ews.test(window.location.href)) {
.split(" ")
.sort(
(a, b) =>
parseInt(b.slice(1)) - parseInt(a.slice(1))
)[btn.name == "GetButton" ? 1 : 0]
parseInt(b.slice(1)) - parseInt(a.slice(1)),
)[btn.name == "GetButton" ? 1 : 0],
);
btn.removeAttribute("disabled");
btn.addEventListener("click", () => {
promptInstall(
buildExtensionUrl(
window.location.href,
btn.id.split("-")[1]
btn.id.split("-")[1],
),
true,
WEBSTORE.edge
WEBSTORE.edge,
);
});
dlBtn = btn;
Expand All @@ -137,6 +192,11 @@ if (is_cws.test(window.location.href)) {
childList: true,
});
}
if (is_ncws.test(window.location.href)) {
modifyButtonObserverNew.observe(document.body, {
childList: true,
});
}
if (
is_ows.test(window.location.href) &&
document.body.querySelector("#feedback-container") //built-ins don't have a feedback section
Expand All @@ -155,8 +215,8 @@ if (
promptInstall(
buildExtensionUrl(window.location.href),
true,
WEBSTORE.opera
)
WEBSTORE.opera,
),
);
}
window.onload = () => {
Expand Down
Loading

0 comments on commit 8169bfc

Please sign in to comment.