Skip to content

Commit

Permalink
add favicons to omnibar tabs, make util function to help and refactor…
Browse files Browse the repository at this point in the history
… _tabs.onShow (#2043)
  • Loading branch information
pangdaxing23 authored Oct 21, 2023
1 parent 980c23e commit 119c110
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/content_scripts/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,21 @@ function refreshHints(hints, pressedKeys) {
return result;
}

function attachFaviconToImgSrc(tab, imgEl) {
const browserName = getBrowserName();
if (browserName === "Chrome") {
imgEl.src = `chrome://favicon/${tab.url}`;
} else if (browserName.startsWith("Safari")) {
imgEl.src = new URL(tab.url).origin + "/favicon.ico";
} else {
imgEl.src = tab.favIconUrl;
}
}

export {
LOG,
actionWithSelectionPreserved,
attachFaviconToImgSrc,
constructSearchURL,
createElementWithContent,
dispatchMouseEvent,
Expand Down
7 changes: 7 additions & 0 deletions src/content_scripts/ui/frontend.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ body {
vertical-align: middle;
display: table-cell;
}
#sk_omnibarSearchResult li.tab {
display: flex;
align-items: flex-start;
}
#sk_omnibarSearchResult li.tab img {
margin-right: 0.5rem;
}
#sk_omnibarSearchResult li div.title {
text-align: left;
}
Expand Down
10 changes: 2 additions & 8 deletions src/content_scripts/ui/frontend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { encode } from 'js-base64';
import {
attachFaviconToImgSrc,
createElementWithContent,
generateQuickGuid,
getAnnotations,
Expand Down Expand Up @@ -268,14 +269,7 @@ const Front = (function() {
setSanitizedContent(tab, `<div class=sk_tab_wrap><div class=sk_tab_icon><img/></div><div class=sk_tab_title>${htmlEncode(t.title)}</div></div>`);
tab.style.boxShadow = "0px 3px 7px 0px rgba(245, 245, 0, 0.9)";
}
const browserName = getBrowserName();
if (browserName === "Chrome") {
tab.querySelector("img").src = `chrome://favicon/${t.url}`;
} else if (browserName.startsWith("Safari")) {
tab.querySelector("img").src = new URL(t.url).origin + "/favicon.ico";
} else {
tab.querySelector("img").src = t.favIconUrl;
}
attachFaviconToImgSrc(t, tab.querySelector("img"));
tab.querySelector("div.sk_tab_title").style.width = (unitWidth - 24) + 'px';
_tabs.append(tab);
});
Expand Down
9 changes: 8 additions & 1 deletion src/content_scripts/ui/omnibar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import KeyboardUtils from '../common/keyboardUtils';
import Mode from '../common/mode';
import { debounce } from 'lodash';
import {
attachFaviconToImgSrc,
constructSearchURL,
createElementWithContent,
filterByTitleOrUrl,
Expand Down Expand Up @@ -406,8 +407,14 @@ function createOmnibar(front, clipboard) {
} else if(b.type && b.type.length === 2 && b.type.charCodeAt(0) > 255) {
type = b.type;
}
var li = createElementWithContent('li',
if (b.hasOwnProperty('favIconUrl')) {
var li = createElementWithContent('li',
`<img/><div class="text-container"><div class="title">${self.highlight(rxp, htmlEncode(b.title))} ${additional}</div><div class="url">${self.highlight(rxp, htmlEncode(decodeURIComponent(b.url)))}</div></div>`, { "class": "tab" });
attachFaviconToImgSrc(b, li.querySelector('img'));
} else {
var li = createElementWithContent('li',
`<div class="title">${type} ${self.highlight(rxp, htmlEncode(b.title))} ${additional}</div><div class="url">${self.highlight(rxp, htmlEncode(decodeURIComponent(b.url)))}</div>`);
}
li.uid = uid;
li.url = b.url;
return li;
Expand Down

0 comments on commit 119c110

Please sign in to comment.