diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-10 22:01:11 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-10 22:01:11 -0400 |
| commit | e53a6e3c651a3191e24b05ff9d69e871632ddbf8 (patch) | |
| tree | ac9d416e4b12eafa0794b0dea4e4403f7860a526 | |
| parent | d3c324e4b06f0744325798b92e2dd63fa81b520e (diff) | |
| download | browsing-activity-tracker-e53a6e3c651a3191e24b05ff9d69e871632ddbf8.tar.gz | |
Add Chrome extension
| -rw-r--r-- | chrome-extension/bg.js | 35 | ||||
| -rw-r--r-- | chrome-extension/manifest.json | 12 |
2 files changed, 47 insertions, 0 deletions
diff --git a/chrome-extension/bg.js b/chrome-extension/bg.js new file mode 100644 index 0000000..8a74e89 --- /dev/null +++ b/chrome-extension/bg.js @@ -0,0 +1,35 @@ +function log(url, title){ + var xhr = new XMLHttpRequest(); + xhr.open("POST", "http://localhost:8080"); + var data = "url=" + encodeURIComponent(url); + data += "&time=" + Date.now(); + data += "&title=" + encodeURIComponent(title); + data += "&key=" + "chromium"; + xhr.send(data); +} + +chrome.tabs.onActivated.addListener(function (activeInfo) { + chrome.tabs.get(activeInfo.tabId, function(tab) { + if (tab.status === "complete") { + log(tab.url, tab.title); + } + }); +}); + +chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + if (changeInfo.status === "complete" && tab.active) { + log(tab.url, tab.title); + } +}); + +chrome.windows.onFocusChanged.addListener(function (windowId) { + if (windowId == chrome.windows.WINDOW_ID_NONE) { + log(null, null); + } else { + chrome.tabs.query({active: true, currentWindow: true}, function (tabs) { + if (tabs[0].status === "complete") { + log(tabs[0].url, tabs[0].title); + } + }); + } +}); diff --git a/chrome-extension/manifest.json b/chrome-extension/manifest.json new file mode 100644 index 0000000..fc29fa6 --- /dev/null +++ b/chrome-extension/manifest.json @@ -0,0 +1,12 @@ +{ + "name": "Webpage Logger", + "version": "0.1", + "description": "Notify a callback URL", + "manifest_version": 2, + "background": { + "scripts": ["bg.js"] + }, + "permissions": [ + "tabs" + ] +} |
