MCPcopy
hub / github.com/NeverDecaf/chromium-web-store / createButton

Function createButton

src/scripts/inject.js:3–68  ·  view source on GitHub ↗
(newParent, addBtn = true)

Source from the content-addressed store, hash-verified

1var dlBtn;
2
3function createButton(newParent, addBtn = true) {
4 const button_div = document.createElement("div");
5 button_div.setAttribute("role", "button");
6 button_div.setAttribute(
7 "class",
8 "dd-Va g-c-wb g-eg-ua-Uc-c-za g-c-Oc-td-jb-oa g-c",
9 );
10
11 button_div.setAttribute("tabindex", "0");
12 button_div.setAttribute("style", "user-select: none;");
13 var hf = document.createElement("div");
14 hf.setAttribute("class", "g-c-Hf");
15 button_div.appendChild(hf);
16 var x = document.createElement("div");
17 x.setAttribute("class", "g-c-x");
18 hf.appendChild(x);
19 const r = document.createElement("div");
20 r.setAttribute("class", "g-c-R webstore-test-button-label");
21 x.appendChild(r);
22 button_div.toggleState = function (isInstall) {
23 isInstall
24 ? button_div.setAttribute("isInstallBtn", "")
25 : button_div.removeAttribute("isInstallBtn");
26 button_div.setAttribute(
27 "aria-label",
28 isInstall
29 ? chrome.i18n.getMessage("webstore_addButton")
30 : chrome.i18n.getMessage("webstore_removeButton"),
31 );
32 r.innerHTML = isInstall
33 ? chrome.i18n.getMessage("webstore_addButton")
34 : chrome.i18n.getMessage("webstore_removeButton");
35 };
36 if (addBtn) button_div.setAttribute("isInstallBtn", "");
37 button_div.toggleState(addBtn);
38 let dlurl = buildExtensionUrl(window.location.href);
39 button_div.id = getExtensionId(window.location.href);
40 button_div.addEventListener("click", function () {
41 if (button_div.hasAttribute("isInstallBtn")) {
42 chrome.runtime.sendMessage({
43 installExt: getExtensionId(window.location.href),
44 });
45 promptInstall(dlurl, true);
46 } else {
47 chrome.runtime.sendMessage(
48 {
49 uninstallExt: getExtensionId(window.location.href),
50 },
51 (resp) => {
52 if (resp.uninstalled) {
53 button_div.toggleState(true);
54 }
55 },
56 );
57 }
58 });
59 button_div.addEventListener("mouseover", function () {
60 this.classList.add("g-c-l");

Callers 1

inject.jsFile · 0.70

Calls 3

buildExtensionUrlFunction · 0.70
getExtensionIdFunction · 0.70
promptInstallFunction · 0.70

Tested by

no test coverage detected