const container = document.getElementById("app"); const appcontainer = document.createElement("ul"); const removedcontainer = document.createElement("ul"); const removed_status = document.createElement("div"); const removed_text = document.createElement("p"); const update_status = document.createElement("div"); const update_text = document.createElement("p"); update_text.innerHTML = chrome.i18n.getMessage("popup_checkingForUpdates"); update_status.appendChild(update_text); update_status.setAttribute("class", "message"); update_status.setAttribute("id", "updateStatus"); removed_text.innerHTML = chrome.i18n.getMessage("popup_removedExtensions"); removed_status.setAttribute( "title", chrome.i18n.getMessage("popup_removedExtensionsTooltip"), ); removed_status.appendChild(removed_text); removed_status.setAttribute("id", "removedStatus"); removed_status.setAttribute("class", "message"); removed_status.classList.add("hidden"); container.appendChild(update_status); container.appendChild(appcontainer); container.appendChild(removed_status); container.appendChild(removedcontainer); checkForUpdates( function (updateCheck, installed_versions, appid, updatever, is_webstore) { let li = document.createElement("li"); li.setAttribute( "data-enabled", installed_versions[appid].enabled ? "true" : "false", ); let img = document.createElement("img"); img.setAttribute("alt", installed_versions[appid].name); if (installed_versions[appid].icons) img.setAttribute( "src", "chrome://extension-icon/" + appid + "/" + installed_versions[appid].icons[0].size + "/0", ); else img.setAttribute( "src", "chrome://extension-icon/" + appid + "/16/0", ); li.appendChild(img); span = document.createElement("span"); span.innerHTML = installed_versions[appid].name; li.appendChild(span); li.setAttribute( "title", installed_versions[appid].version + " ⇒ " + updatever, ); storepage = document.createElement("a"); storepage.setAttribute("target", "_blank"); storepage.innerHTML = ''; if (is_webstore) { storepage.setAttribute( "href", "https://chrome.google.com/webstore/detail/" + appid, ); li.appendChild(storepage); } else if (installed_versions[appid].homepageUrl) { storepage.setAttribute( "href", installed_versions[appid].homepageUrl, ); li.appendChild(storepage); } li.setAttribute("crx_url", updateCheck["@codebase"]); let crx_url = updateCheck["@codebase"]; li.addEventListener("click", function (evt) { if (evt.target.tagName != "A") promptInstall(crx_url, is_webstore); }); appcontainer.appendChild(li); update_status.classList.add("hidden"); }, function (was_removed, extData) { let li = document.createElement("li"); li.setAttribute("data-enabled", extData.enabled ? "true" : "false"); li.setAttribute("class", "updatefailure"); if ("icons" in extData) { let img = document.createElement("img"); if (extData.icons) img.setAttribute( "src", "chrome://extension-icon/" + extData.id + "/" + extData.icons[0].size + "/0", ); else img.setAttribute( "src", `chrome://extension-icon/${chrome.runtime.id}/16/0`, ); li.appendChild(img); } let span = document.createElement("span"); li.appendChild(span); if (was_removed) { span.innerHTML = extData.name; li.setAttribute("class", "removedext"); removedcontainer.appendChild(li); removed_status.classList.remove("hidden"); close_button = document.createElement("a"); close_button.setAttribute("target", "_blank"); close_button.innerHTML = ''; li.appendChild(close_button); close_button.onclick = () => { let default_options = { removed_extensions: {}, }; chrome.storage.sync.get( default_options, function (stored_values) { stored_values["removed_extensions"][extData.id] = true; chrome.storage.sync.set({ removed_extensions: stored_values["removed_extensions"], }); li.remove(); if ( removedcontainer.getElementsByTagName("li") .length == 0 ) removed_status.classList.add("hidden"); }, ); }; } else { span.innerHTML = chrome.i18n.getMessage( "popup_updateFailed", extData.name, ); appcontainer.appendChild(li); if (extData.updateUrl) { chrome.permissions.contains( { origins: [extData.updateUrl], }, (e) => { if (!e) { fix_button = document.createElement("a"); fix_button.setAttribute("target", "_blank"); fix_button.innerHTML = ''; li.appendChild(fix_button); fix_button.onclick = () => { chrome.permissions.request({ origins: [extData.updateUrl], }); }; } }, ); } } }, function () { update_text.innerHTML = chrome.i18n.getMessage("popup_allUpToDate"); }, );