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

add favicon next to title #7

Closed
TheMapSmith opened this issue Apr 21, 2023 · 2 comments
Closed

add favicon next to title #7

TheMapSmith opened this issue Apr 21, 2023 · 2 comments

Comments

@TheMapSmith
Copy link
Owner

wonderful! this is all working great. can you please add the favicon between the visit time and the page title?

@TheMapSmith
Copy link
Owner Author

Sure! To display the favicon between the visit time and the page title, you can update the history_window.js file to include an img element for the favicon.

Here's the updated history_window.js file:

const datePicker = document.getElementById('custom-date-picker');
const historyList = document.getElementById('custom-history-list');
const closeButton = document.getElementById('close-button');

datePicker.addEventListener('change', (event) => {
  const selectedDate = event.target.value;
  filterHistoryEntriesByDate(selectedDate);
});

closeButton.addEventListener('click', () => {
  window.close();
});

function filterHistoryEntriesByDate(selectedDate) {
  chrome.history.search({
    text: '',
    startTime: new Date(selectedDate).getTime(),
    endTime: new Date(selectedDate).getTime() + 86400000,
    maxResults: 1000
  }, (results) => {
    historyList.innerHTML = '';

    for (const entry of results) {
      const entryElement = document.createElement('div');
      entryElement.classList.add('entry');

      // Format the visited time
      const visitedTime = new Date(entry.lastVisitTime);
      const timeString = visitedTime.toLocaleTimeString();

      // Create a span element to display the visited time
      const visitedTimeElement = document.createElement('span');
      visitedTimeElement.textContent = `${timeString} - `;
      entryElement.appendChild(visitedTimeElement);

      // Create an img element for the favicon
      const faviconElement = document.createElement('img');
      faviconElement.src = `https://s2.googleusercontent.com/s2/favicons?domain=${entry.url}`;
      faviconElement.alt = '';
      faviconElement.classList.add('favicon');
      entryElement.appendChild(faviconElement);

      const entryTitle = document.createElement('a');
      entryTitle.href = entry.url;
      entryTitle.target = '_blank';
      entryTitle.textContent = entry.title || entry.url;
      entryElement.appendChild(entryTitle);

      historyList.appendChild(entryElement);
    }
  });
}

In this updated file, we added a new faviconElement that is an img element to display the favicon. The src attribute of the faviconElement fetches the favicon from the Google favicon service using the domain of the entry URL. The faviconElement is then appended to the entryElement between the visited time and the page title.

To ensure proper spacing and alignment of the favicon, add the following CSS rule to your style.css file:

.favicon {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 4px;
  vertical-align: middle;
}

@TheMapSmith
Copy link
Owner Author

image

TheMapSmith added a commit that referenced this issue Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant