Fixing favicon loading for all icons. Part of #561
This commit is contained in:
parent
094a0e2391
commit
e467988a71
6 changed files with 35 additions and 24 deletions
|
@ -9,6 +9,7 @@ module.exports = {
|
||||||
"webextensions": true
|
"webextensions": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
|
"Utils": true,
|
||||||
"CustomizableUI": true,
|
"CustomizableUI": true,
|
||||||
"CustomizableWidgets": true,
|
"CustomizableWidgets": true,
|
||||||
"SessionStore": true,
|
"SessionStore": true,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<script src="js/utils.js"></script>
|
||||||
<script src="js/confirm-page.js"></script>
|
<script src="js/confirm-page.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -5,7 +5,7 @@ async function load() {
|
||||||
const currentCookieStoreId = searchParams.get("currentCookieStoreId");
|
const currentCookieStoreId = searchParams.get("currentCookieStoreId");
|
||||||
const redirectUrlElement = document.getElementById("redirect-url");
|
const redirectUrlElement = document.getElementById("redirect-url");
|
||||||
redirectUrlElement.textContent = redirectUrl;
|
redirectUrlElement.textContent = redirectUrl;
|
||||||
createFavicon(redirectUrl, redirectUrlElement);
|
appendFavicon(redirectUrl, redirectUrlElement);
|
||||||
|
|
||||||
const container = await browser.contextualIdentities.get(cookieStoreId);
|
const container = await browser.contextualIdentities.get(cookieStoreId);
|
||||||
[...document.querySelectorAll(".container-name")].forEach((containerNameElement) => {
|
[...document.querySelectorAll(".container-name")].forEach((containerNameElement) => {
|
||||||
|
@ -32,12 +32,11 @@ async function load() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFavicon(pageUrl, redirectUrlElement) {
|
function appendFavicon(pageUrl, redirectUrlElement) {
|
||||||
const origin = new URL(pageUrl).origin;
|
const origin = new URL(pageUrl).origin;
|
||||||
const imageElement = document.createElement("img");
|
const favIconElement = Utils.createFavIconElement(`${origin}/favicon.ico`);
|
||||||
imageElement.src = `${origin}/favicon.ico`;
|
|
||||||
|
|
||||||
redirectUrlElement.prepend(imageElement);
|
redirectUrlElement.prepend(favIconElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmSubmit(redirectUrl, cookieStoreId) {
|
function confirmSubmit(redirectUrl, cookieStoreId) {
|
||||||
|
|
|
@ -18,7 +18,6 @@ const P_CONTAINERS_EDIT = "containersEdit";
|
||||||
const P_CONTAINER_INFO = "containerInfo";
|
const P_CONTAINER_INFO = "containerInfo";
|
||||||
const P_CONTAINER_EDIT = "containerEdit";
|
const P_CONTAINER_EDIT = "containerEdit";
|
||||||
const P_CONTAINER_DELETE = "containerDelete";
|
const P_CONTAINER_DELETE = "containerDelete";
|
||||||
const DEFAULT_FAVICON = "moz-icon://goat?size=16";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes any occurances of &, ", <, > or / with XML entities.
|
* Escapes any occurances of &, ", <, > or / with XML entities.
|
||||||
|
@ -446,22 +445,9 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
|
||||||
const siteSettings = await Logic.getAssignment(currentTab);
|
const siteSettings = await Logic.getAssignment(currentTab);
|
||||||
this.setupAssignmentCheckbox(siteSettings);
|
this.setupAssignmentCheckbox(siteSettings);
|
||||||
const currentPage = document.getElementById("current-page");
|
const currentPage = document.getElementById("current-page");
|
||||||
const favIconUrl = currentTab.favIconUrl || "";
|
currentPage.innerHTML = escaped`${currentTab.title}`;
|
||||||
currentPage.innerHTML = escaped`
|
const favIconElement = Utils.createFavIconElement(currentTab.favIconUrl || "");
|
||||||
<img class="offpage" src="${favIconUrl}" /> ${currentTab.title}
|
currentPage.prepend(favIconElement);
|
||||||
`;
|
|
||||||
|
|
||||||
const imageElement = currentPage.querySelector("img");
|
|
||||||
const loadListener = (e) => {
|
|
||||||
e.target.classList.remove("offpage");
|
|
||||||
e.target.removeEventListener("load", loadListener);
|
|
||||||
e.target.removeEventListener("error", errorListener);
|
|
||||||
};
|
|
||||||
const errorListener = (e) => {
|
|
||||||
e.target.src = DEFAULT_FAVICON;
|
|
||||||
};
|
|
||||||
imageElement.addEventListener("error", errorListener);
|
|
||||||
imageElement.addEventListener("load", loadListener);
|
|
||||||
|
|
||||||
const currentContainer = document.getElementById("current-container");
|
const currentContainer = document.getElementById("current-container");
|
||||||
currentContainer.innerText = identity.name;
|
currentContainer.innerText = identity.name;
|
||||||
|
@ -645,8 +631,9 @@ Logic.registerPanel(P_CONTAINER_INFO, {
|
||||||
fragment.appendChild(tr);
|
fragment.appendChild(tr);
|
||||||
tr.classList.add("container-info-tab-row");
|
tr.classList.add("container-info-tab-row");
|
||||||
tr.innerHTML = escaped`
|
tr.innerHTML = escaped`
|
||||||
<td><img class="icon" src="${tab.favicon}" /></td>
|
<td></td>
|
||||||
<td class="container-info-tab-title truncate-text">${tab.title}</td>`;
|
<td class="container-info-tab-title truncate-text">${tab.title}</td>`;
|
||||||
|
tr.querySelector("td").appendChild(Utils.createFavIconElement(tab.favicon));
|
||||||
|
|
||||||
// On click, we activate this tab. But only if this tab is active.
|
// On click, we activate this tab. But only if this tab is active.
|
||||||
if (tab.active) {
|
if (tab.active) {
|
||||||
|
|
23
webextension/js/utils.js
Normal file
23
webextension/js/utils.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
const DEFAULT_FAVICON = "moz-icon://goat?size=16";
|
||||||
|
|
||||||
|
// TODO use export here instead of globals
|
||||||
|
window.Utils = {
|
||||||
|
|
||||||
|
createFavIconElement(url) {
|
||||||
|
const imageElement = document.createElement("img");
|
||||||
|
imageElement.classList.add("icon", "offpage");
|
||||||
|
imageElement.src = url;
|
||||||
|
const loadListener = (e) => {
|
||||||
|
e.target.classList.remove("offpage");
|
||||||
|
e.target.removeEventListener("load", loadListener);
|
||||||
|
e.target.removeEventListener("error", errorListener);
|
||||||
|
};
|
||||||
|
const errorListener = (e) => {
|
||||||
|
e.target.src = DEFAULT_FAVICON;
|
||||||
|
};
|
||||||
|
imageElement.addEventListener("error", errorListener);
|
||||||
|
imageElement.addEventListener("load", loadListener);
|
||||||
|
return imageElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
|
@ -148,7 +148,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="js/utils.js"></script>
|
||||||
<script src="js/popup.js"></script>
|
<script src="js/popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue