const fetchImage = async () => {
  let url = 'https://pixabay.com/api/?key=40464761-f10ea4f5a3e67a5652bbecbee&q=traveling+Travel+cities+touristicplaces+city&image_type=photo&pretty=true';
  try {
    let response = await fetch(url);
    let data = await response.json();
    let images = data.hits;
    if (images.length === 0) {
      console.log('No images found.');
      return;
    }

    let randomImage = images[Math.floor(Math.random() * images.length)];
    localStorage.setItem("url", randomImage.largeImageURL);
    // throw new Error('Failed to fetch image');
  } catch (error) {
    let defaultImageUrl = chrome.runtime.getURL("images/background.jpg");
    localStorage.setItem("url", defaultImageUrl);
  }
};

fetchImage();

const _DateAndTime = () => {
  document.querySelector("#currentTime").innerHTML = new Date().toLocaleTimeString('en-gb', { hour: 'numeric', minute: 'numeric', hour12: true});
}

document.getElementById('search-input').focus();
document.getElementById('search-input').select();

setInterval(_DateAndTime, 60000);
_DateAndTime();
