Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Default Shortcut Icon to Offline Icon #436

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2825,8 +2825,21 @@ document.addEventListener("DOMContentLoaded", function () {
// `https://${hostname}/apple-touch-icon.png`
// ];

const GOOGLE_FAVICON_API_FALLBACK = (hostname) =>
`https://s2.googleusercontent.com/s2/favicons?domain_url=https://${hostname}&sz=256`;
async function GOOGLE_FAVICON_API_FALLBACK (hostname, logo) {
const proxyUrl = 'https://cors-anywhere.herokuapp.com/';
const targetUrl = `https://s2.googleusercontent.com/s2/favicons?domain_url=https://${hostname}&sz=256`;
let fetchedURL = './shortcuts_icons/offline.svg';
try {
await fetch(proxyUrl + targetUrl)
.then((response) => {
if (response.status == 200) {
fetchedURL = targetUrl;
}
})
} finally {
logo.src = fetchedURL;
}
}

// const FAVICON_REQUEST_TIMEOUT = 5000;

Expand Down Expand Up @@ -3297,7 +3310,8 @@ document.addEventListener("DOMContentLoaded", function () {
// Special case for invalid URLs
logo.src = "./shortcuts_icons/invalid-url.svg";
} else {
logo.src = GOOGLE_FAVICON_API_FALLBACK(hostname);
logo.src = "./shortcuts_icons/offline.svg";
GOOGLE_FAVICON_API_FALLBACK(hostname, logo);

// Handle image loading error on offline scenario
logo.onerror = () => {
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ body #bookmarkButton.bookmark-button.rotate {
color: var(--darkColor-blue);
width: 60px;
font-size: 12px;
padding: 2px 0;
padding: 2px 0 0 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
not vertically centered anymore

margin-left: 10px;
cursor: pointer;
}
Expand Down