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

feat(browser): Browser activity tracker add #65

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions packages/Activity-Tracker-browser-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name":"Browser Activity Tracker",
"description": "Shows you your digital time based on your browser activity",
kriptonian1 marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.0.0",
"manifest_version": 3,

"action":{
"default_icon":{
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
}

},

"background":{
"service_worker": "src/background.js"
},

"author": "",
"homepage_url": "https://github.com/OpenLake/Activity-Tracker#readme",
kriptonian1 marked this conversation as resolved.
Show resolved Hide resolved

"permissions": [
"tabs",
"activeTab",
"storage"
]
}
kriptonian1 marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions packages/Activity-Tracker-browser-extension/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/popup.css">
<title>Document</title>
</head>
<body>
<script src="src/background.js"></script>
<h1 class="textBody">activity</h1>
<div>
<a class="textBody" id="activityTitle">Title: Loading ...</a>
</div>
<a class="textBody" href="" id="activityUrl">URL: Loading ...</a>
<div><img id="activityFavicon" src="" alt="Favicon"></div>

<p class="textBody" id="activetime">time</p>

</body>
</html>
96 changes: 96 additions & 0 deletions packages/Activity-Tracker-browser-extension/src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
let tab=null;
let url=null;
let favicon=null;
class ActiveWindowWatcher {
/**
* @param {number} interval Polling interval
* @param {(activity) => void} changeCallback
*/
constructor(interval = 1000) {
this.startTime = null;
this.tab = null; //Title
this.url = null;
this.favicon = null;
// this.changeCallback = changeCallback;
this.interval = interval;
}

/**
* Storing the start time of the active window
* Collecting data of the window which will be active
*/
storeTime() {
const endTime = Date.now();
const startTime = this.startTime;

const title = this.tab;
const url = this.url;
const favicon = this.favicon;


const data = {
title,
url,
favicon,
startTime,
endTime,
};

// this.changeCallback(data);
console.log(data)
}

/**
* Checks the active window is specific time interval
* and whenever the active window changes stores the time difference by calling {@link ActiveWindowWatcher.storeTime} function
*/
tracker() {
setInterval(() => {
let queryOptions = { active: true, currentWindow: true}; // to get current active tab
chrome.tabs.query(queryOptions,function currentTab(tabs){
let currentTab = tabs[0]; // take the object from the returned promise
let currentTitle = currentTab.title; // take object title
let currentUrl = currentTab.url; // take object URL
let currentFavIcons = currentTab.favIconUrl
tab = currentTitle;
url = currentUrl;
favicon = currentFavIcons;

// Title
// const activityTitle = document.getElementById('activityTitle');
// const activityTitleUrl = document.getElementById('activityTitle');
// activityTitle.innerHTML = "Title: "+currentTitle; //format it in html
// activityTitleUrl.setAttribute("href",currentUrl);
// console.log(activityTitle)


});

if (tab === undefined) return;

if (!this.tab) {
this.startTime = Date.now();
this.tab = tab;
this.url = url;
this.favicon = favicon;
}

//If the active window is changed store the used time data.
if (tab !== this.tab) {
this.storeTime();
this.tab = null;
this.url = null;
this.favicon = null;
}
console.log(tab,url,favicon, this.startTime);

}, this.interval);
}

initialize() {
this.tracker();
}
}

const activityTracker = new ActiveWindowWatcher(1000);
activityTracker.initialize();
Empty file.
10 changes: 10 additions & 0 deletions packages/Activity-Tracker-browser-extension/style/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body {
width: 300px;
height: 300px;
text-align: center;
background-color: rgb(18, 31, 48);
}

.textBody{
color: aliceblue;
}
kriptonian1 marked this conversation as resolved.
Show resolved Hide resolved