@@ -43,9 +43,12 @@ browser.windows.onFocusChanged.addListener(async (windowId) => {
|
|||||||
browser.tabs.onUpdated.addListener(async (tabId, changeInfo) => {
|
browser.tabs.onUpdated.addListener(async (tabId, changeInfo) => {
|
||||||
if (changeInfo.status === 'complete') {
|
if (changeInfo.status === 'complete') {
|
||||||
// Get current tab URL.
|
// Get current tab URL.
|
||||||
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
|
const tabs: browser.Tabs.Tab[] = await browser.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true,
|
||||||
|
});
|
||||||
// If tab updated is the same as active tab
|
// If tab updated is the same as active tab
|
||||||
if (tabId == tab.id) {
|
if (tabId == tabs[0]?.id) {
|
||||||
await WakaTimeCore.recordHeartbeat();
|
await WakaTimeCore.recordHeartbeat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ interface State {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
loggingStyle: string;
|
loggingStyle: string;
|
||||||
loggingType: string;
|
loggingType: string;
|
||||||
socialMediaSites: string;
|
socialMediaSites: string[];
|
||||||
theme: string;
|
theme: string;
|
||||||
trackSocialMedia: boolean;
|
trackSocialMedia: boolean;
|
||||||
whitelist: string;
|
whitelist: string;
|
||||||
@@ -62,7 +62,7 @@ export default function Options(): JSX.Element {
|
|||||||
hostname: items.hostname as string,
|
hostname: items.hostname as string,
|
||||||
loggingStyle: items.loggingStyle as string,
|
loggingStyle: items.loggingStyle as string,
|
||||||
loggingType: items.loggingType as string,
|
loggingType: items.loggingType as string,
|
||||||
socialMediaSites: items.socialMediaSites as string,
|
socialMediaSites: items.socialMediaSites as string[],
|
||||||
theme: items.theme as string,
|
theme: items.theme as string,
|
||||||
trackSocialMedia: items.trackSocialMedia as boolean,
|
trackSocialMedia: items.trackSocialMedia as boolean,
|
||||||
whitelist: items.whitelist as string,
|
whitelist: items.whitelist as string,
|
||||||
@@ -143,6 +143,10 @@ export default function Options(): JSX.Element {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleSocialMedia = () => {
|
||||||
|
setState({ ...state, trackSocialMedia: !state.trackSocialMedia });
|
||||||
|
};
|
||||||
|
|
||||||
const loggingStyle = function () {
|
const loggingStyle = function () {
|
||||||
if (state.loggingStyle == 'blacklist') {
|
if (state.loggingStyle == 'blacklist') {
|
||||||
return (
|
return (
|
||||||
@@ -299,11 +303,13 @@ export default function Options(): JSX.Element {
|
|||||||
|
|
||||||
<div className="form-group row">
|
<div className="form-group row">
|
||||||
<div className="col-lg-10 col-lg-offset-2 space-between align-items-center">
|
<div className="col-lg-10 col-lg-offset-2 space-between align-items-center">
|
||||||
<div
|
<div>
|
||||||
onClick={() => setState({ ...state, trackSocialMedia: !state.trackSocialMedia })}
|
<input
|
||||||
>
|
type="checkbox"
|
||||||
<input type="checkbox" defaultChecked={state.trackSocialMedia} />
|
checked={state.trackSocialMedia}
|
||||||
<span>Track social media sites</span>
|
onChange={toggleSocialMedia}
|
||||||
|
/>
|
||||||
|
<span onClick={toggleSocialMedia}>Track social media sites</span>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -336,14 +342,14 @@ export default function Options(): JSX.Element {
|
|||||||
</div>
|
</div>
|
||||||
<div className="modal-body">
|
<div className="modal-body">
|
||||||
<SitesList
|
<SitesList
|
||||||
handleChange={(sites: string) =>
|
handleChange={(sites: string) => {
|
||||||
setState({
|
setState({
|
||||||
...state,
|
...state,
|
||||||
socialMediaSites: sites,
|
socialMediaSites: sites.split('\n'),
|
||||||
})
|
});
|
||||||
}
|
}}
|
||||||
label="Social"
|
label="Social"
|
||||||
sites={state.socialMediaSites}
|
sites={state.socialMediaSites.join('\n')}
|
||||||
helpText="Sites that you don't want to show in your reports."
|
helpText="Sites that you don't want to show in your reports."
|
||||||
rows={5}
|
rows={5}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -34,16 +34,18 @@ describe('wakatime config', () => {
|
|||||||
},
|
},
|
||||||
"currentUserApiEndPoint": "/users/current",
|
"currentUserApiEndPoint": "/users/current",
|
||||||
"detectionIntervalInSeconds": 60,
|
"detectionIntervalInSeconds": 60,
|
||||||
"devSites": "https://codepen.io/
|
"devSites": [
|
||||||
https://www.codewars.com/
|
"codepen.io",
|
||||||
https://dev.to/
|
"codewars.com",
|
||||||
https://github.com/
|
"dev.to",
|
||||||
https://www.hackerrank.com/
|
"github.com",
|
||||||
https://leetcode.com/
|
"hackerrank.com",
|
||||||
https://developer.mozilla.org/en-US/
|
"leetcode.com",
|
||||||
https://stackoverflow.com/
|
"developer.mozilla.org",
|
||||||
https://www.udemy.com/
|
"stackoverflow.com",
|
||||||
https://www.w3schools.com/",
|
"udemy.com",
|
||||||
|
"w3schools.com",
|
||||||
|
],
|
||||||
"heartbeatApiEndPoint": "/users/current/heartbeats",
|
"heartbeatApiEndPoint": "/users/current/heartbeats",
|
||||||
"hostname": "",
|
"hostname": "",
|
||||||
"loggingEnabled": true,
|
"loggingEnabled": true,
|
||||||
@@ -51,16 +53,22 @@ describe('wakatime config', () => {
|
|||||||
"loggingType": "domain",
|
"loggingType": "domain",
|
||||||
"logoutUserUrl": "https://wakatime.com/logout",
|
"logoutUserUrl": "https://wakatime.com/logout",
|
||||||
"name": "WakaTime",
|
"name": "WakaTime",
|
||||||
"socialMediaSites": "https://www.facebook.com/
|
"nonTrackableSites": [
|
||||||
https://www.instagram.com/
|
"chrome://",
|
||||||
https://www.linkedin.com/
|
"about:",
|
||||||
https://www.pinterest.com/
|
],
|
||||||
https://www.reddit.com/
|
"socialMediaSites": [
|
||||||
https://www.snapchat.com/
|
"facebook.com",
|
||||||
https://www.tiktok.com/
|
"instagram.com",
|
||||||
https://twitter.com/
|
"linkedin.com",
|
||||||
https://www.whatsapp.com/
|
"pinterest.com",
|
||||||
https://www.youtube.com/",
|
"reddit.com",
|
||||||
|
"snapchat.com",
|
||||||
|
"tiktok.com",
|
||||||
|
"twitter.com",
|
||||||
|
"whatsapp.com",
|
||||||
|
"youtube.com",
|
||||||
|
],
|
||||||
"states": [
|
"states": [
|
||||||
"allGood",
|
"allGood",
|
||||||
"notLogging",
|
"notLogging",
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export interface Config {
|
|||||||
*/
|
*/
|
||||||
detectionIntervalInSeconds: number;
|
detectionIntervalInSeconds: number;
|
||||||
|
|
||||||
devSites: string;
|
devSites: string[];
|
||||||
/**
|
/**
|
||||||
* Url to which to send the heartbeat
|
* Url to which to send the heartbeat
|
||||||
*/
|
*/
|
||||||
@@ -87,7 +87,8 @@ export interface Config {
|
|||||||
* Extension name
|
* Extension name
|
||||||
*/
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
socialMediaSites: string;
|
nonTrackableSites: string[];
|
||||||
|
socialMediaSites: string[];
|
||||||
states: ApiStates[];
|
states: ApiStates[];
|
||||||
/**
|
/**
|
||||||
* Get stats from the wakatime api
|
* Get stats from the wakatime api
|
||||||
@@ -132,8 +133,18 @@ const config: Config = {
|
|||||||
|
|
||||||
detectionIntervalInSeconds: 60,
|
detectionIntervalInSeconds: 60,
|
||||||
|
|
||||||
devSites:
|
devSites: [
|
||||||
'https://codepen.io/\nhttps://www.codewars.com/\nhttps://dev.to/\nhttps://github.com/\nhttps://www.hackerrank.com/\nhttps://leetcode.com/\nhttps://developer.mozilla.org/en-US/\nhttps://stackoverflow.com/\nhttps://www.udemy.com/\nhttps://www.w3schools.com/',
|
'codepen.io',
|
||||||
|
'codewars.com',
|
||||||
|
'dev.to',
|
||||||
|
'github.com',
|
||||||
|
'hackerrank.com',
|
||||||
|
'leetcode.com',
|
||||||
|
'developer.mozilla.org',
|
||||||
|
'stackoverflow.com',
|
||||||
|
'udemy.com',
|
||||||
|
'w3schools.com',
|
||||||
|
],
|
||||||
|
|
||||||
heartbeatApiEndPoint: process.env.HEARTBEAT_API_URL ?? '/users/current/heartbeats',
|
heartbeatApiEndPoint: process.env.HEARTBEAT_API_URL ?? '/users/current/heartbeats',
|
||||||
|
|
||||||
@@ -149,7 +160,20 @@ const config: Config = {
|
|||||||
|
|
||||||
name: 'WakaTime',
|
name: 'WakaTime',
|
||||||
|
|
||||||
socialMediaSites: `https://www.facebook.com/\nhttps://www.instagram.com/\nhttps://www.linkedin.com/\nhttps://www.pinterest.com/\nhttps://www.reddit.com/\nhttps://www.snapchat.com/\nhttps://www.tiktok.com/\nhttps://twitter.com/\nhttps://www.whatsapp.com/\nhttps://www.youtube.com/`,
|
nonTrackableSites: ['chrome://', 'about:'],
|
||||||
|
|
||||||
|
socialMediaSites: [
|
||||||
|
'facebook.com',
|
||||||
|
'instagram.com',
|
||||||
|
'linkedin.com',
|
||||||
|
'pinterest.com',
|
||||||
|
'reddit.com',
|
||||||
|
'snapchat.com',
|
||||||
|
'tiktok.com',
|
||||||
|
'twitter.com',
|
||||||
|
'whatsapp.com',
|
||||||
|
'youtube.com',
|
||||||
|
],
|
||||||
|
|
||||||
states: ['allGood', 'notLogging', 'notSignedIn', 'blacklisted', 'whitelisted'],
|
states: ['allGood', 'notLogging', 'notSignedIn', 'blacklisted', 'whitelisted'],
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { IS_FIREFOX, generateProjectFromDevSites } from '../utils';
|
|||||||
import { getApiKey } from '../utils/apiKey';
|
import { getApiKey } from '../utils/apiKey';
|
||||||
import changeExtensionState from '../utils/changeExtensionState';
|
import changeExtensionState from '../utils/changeExtensionState';
|
||||||
import contains from '../utils/contains';
|
import contains from '../utils/contains';
|
||||||
import getDomainFromUrl from '../utils/getDomainFromUrl';
|
import getDomainFromUrl, { getDomain } from '../utils/getDomainFromUrl';
|
||||||
|
|
||||||
class WakaTimeCore {
|
class WakaTimeCore {
|
||||||
tabsWithDevtoolsOpen: Tabs.Tab[];
|
tabsWithDevtoolsOpen: Tabs.Tab[];
|
||||||
@@ -149,8 +149,16 @@ class WakaTimeCore {
|
|||||||
url = document.URL;
|
url = document.URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const site of config.nonTrackableSites) {
|
||||||
|
if (url.startsWith(site)) {
|
||||||
|
// Don't send a heartbeat on sites like 'chrome://newtab/' or 'about:newtab'
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostname = getDomain(url);
|
||||||
if (!items.trackSocialMedia) {
|
if (!items.trackSocialMedia) {
|
||||||
if (contains(url, items.socialMediaSites as string)) {
|
if ((items.socialMediaSites as string[]).includes(hostname)) {
|
||||||
return changeExtensionState('blacklisted');
|
return changeExtensionState('blacklisted');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,5 +33,5 @@
|
|||||||
"page": "options.html"
|
"page": "options.html"
|
||||||
},
|
},
|
||||||
"permissions": ["alarms", "tabs", "storage", "idle"],
|
"permissions": ["alarms", "tabs", "storage", "idle"],
|
||||||
"version": "3.0.12"
|
"version": "3.0.13"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,5 +46,5 @@
|
|||||||
"storage",
|
"storage",
|
||||||
"idle"
|
"idle"
|
||||||
],
|
],
|
||||||
"version": "3.0.12"
|
"version": "3.0.13"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,16 @@ export default function getDomainFromUrl(url: string): string {
|
|||||||
|
|
||||||
return parts[0] + '//' + parts[2];
|
return parts[0] + '//' + parts[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns domain from given URL.
|
||||||
|
*/
|
||||||
|
export function getDomain(url: string): string {
|
||||||
|
const splittedUrl = url.replace(/(https?:\/\/)?(www.)?/i, '').split('.');
|
||||||
|
const domain = splittedUrl.slice(splittedUrl.length - 2).join('.');
|
||||||
|
if (domain.includes('/')) {
|
||||||
|
return domain.split('/')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user