Skip to content

Commit

Permalink
No more inaccurate icon state
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Feb 26, 2020
1 parent 38b4df8 commit ed6b7d2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function click(unchecked_tab) {
const tab = checkTab(unchecked_tab);
chrome.browserAction.setBadgeText({ text: '...', tabId: tab.id });
const listener = page_listeners.get(tab.id);
if (listener && sameSite(tab.url, listener.tab.url) && await listener.hasVisibleResults()) {
if (listener && listener.isListening()) {
// Open the images that may have been found, and stop the existing listener
listener.openFound();
listener.close();
Expand All @@ -75,18 +75,20 @@ class PageListener {
this.tab = checkTab(tab);
/** @type {Set<string>} */
this.found = new Set;
this.handleRequest(this.tab);
this.listener = this.handleRequest.bind(this);
const filter = { tabId: this.tab.id, ...REQUESTS_FILTER };
chrome.webRequest.onBeforeRequest.addListener(this.listener, filter);
this.handleRequest(this.tab);
this.updateStatus();
this.interval = setInterval(this.updateStatus.bind(this), 1000);
}


close() {
chrome.webRequest.onBeforeRequest.removeListener(this.listener);
this.found.clear();
this.updateStatus();
clearInterval(this.interval);
}

/**
Expand Down Expand Up @@ -138,16 +140,17 @@ class PageListener {
const found = this.found.size;
let badge = (found || '').toString();
let title = '';
const { host } = new URL(this.tab.url);
if (!this.isListening()) {
badge = '';
title = '' + manifest.browser_action.default_title;
} else if (found === 0) {
title = 'Listening for zoomable image requests in this tab... ' +
title = `Listening for zoomable image requests from ${host}... ` +
'Zoom on your image and it should be detected.';
} else if (found === 1) {
title = "Found a zoomable image on this page. Click to open it.";
title = `Found a zoomable image on ${host}. Click to open it.`;
} else {
title = `Found ${found} images. Click to open them.`
title = `Found ${found} images on ${host}. Click to open them.`
}
const tabId = this.tab.id;
chrome.browserAction.setBadgeText({ text: badge, tabId });
Expand Down

0 comments on commit ed6b7d2

Please sign in to comment.