From 7f7ace3a8f962dfb47a0137e346c4b6f639c8cea Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Tue, 15 Jul 2014 17:09:05 -0400 Subject: Add webpage's favicon to the request body Note that this is not perfect on Chrome since the favicon is loaded asynchronously after the page loaded event. --- chrome-extension/bg.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'chrome-extension') diff --git a/chrome-extension/bg.js b/chrome-extension/bg.js index 208b7bd..2157d58 100644 --- a/chrome-extension/bg.js +++ b/chrome-extension/bg.js @@ -8,10 +8,11 @@ chrome.storage.onChanged.addListener(function(changes) { } }); -function log(url, title){ +function log(url, title, favicon){ var data = JSON.stringify({ url: url, time: Date.now(), - title: title, key: prefs.key + title: title, key: prefs.key, + favicon: favicon }); var xhr = new XMLHttpRequest(); xhr.open("POST", prefs.callback); @@ -23,7 +24,7 @@ chrome.tabs.onActivated.addListener(function (activeInfo) { if (tab.status === "complete" && tab.active) { chrome.windows.get(tab.windowId, {populate: false}, function(window) { if (window.focused) { - log(tab.url, tab.title); + log(tab.url, tab.title, tab.favIconUrl || null); } }); } @@ -34,7 +35,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { if (changeInfo.status === "complete" && tab.active) { chrome.windows.get(tab.windowId, {populate: false}, function(window) { if (window.focused) { - log(tab.url, tab.title); + log(tab.url, tab.title, tab.favIconUrl || null); } }); } @@ -42,13 +43,13 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { chrome.windows.onFocusChanged.addListener(function (windowId) { if (windowId == chrome.windows.WINDOW_ID_NONE) { - log(null, null); + log(null, null, null); } else { chrome.windows.get(windowId, {populate: true}, function(window) { if (window.focused) { chrome.tabs.query({active: true, windowId: windowId}, function (tabs) { if (tabs[0].status === "complete") { - log(tabs[0].url, tabs[0].title); + log(tabs[0].url, tabs[0].title, tabs[0].favIconUrl || null); } }); } -- cgit v1.2.3-70-g09d2