Skip to content

Commit

Permalink
extension: use browser name instead of somewhat cryptic 'local'
Browse files Browse the repository at this point in the history
thanks @koo5 for the idea (#147)
  • Loading branch information
karlicoss committed Nov 3, 2020
1 parent ed6e735 commit 0bff67c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 4 additions & 7 deletions extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type {Locator, Src, Url, Second, JsonArray, JsonObject, AwareDate, NaiveDate} from './common';
import {Visit, Visits, Blacklisted, unwrap, Methods, ldebug, linfo, lerror, lwarn} from './common';
import {get_options_async, setOptions} from './options';
import {get_options_async, setOptions, THIS_BROWSER_TAG} from './options';
import {chromeTabsExecuteScriptAsync, chromeTabsInsertCSS, chromeTabsQueryAsync, chromeRuntimeGetPlatformInfo, chromeTabsGet} from './async_chrome';
import {showTabNotification, showBlackListedNotification, showIgnoredNotification, defensify, notify} from './notifications';
import {Blacklist} from './blacklist'
Expand Down Expand Up @@ -103,9 +103,6 @@ function getDelayMs(/*url*/) {
return 10 * 1000;
}

// TODO: make it configurable in options?
const LOCAL_TAG = 'local';


async function getBrowserVisits(url: Url): Promise<Visits> {
const android = await isAndroid();
Expand Down Expand Up @@ -133,7 +130,7 @@ async function getBrowserVisits(url: Url): Promise<Visits> {
normalise_url(url),
((t: any): AwareDate),
((t: any): NaiveDate), // there is no TZ info in history anyway, so not much else we can do
[LOCAL_TAG],
[THIS_BROWSER_TAG],
));
return new Visits(url, url, visits);
}
Expand Down Expand Up @@ -222,10 +219,10 @@ function getIconStyle(visits: Result): IconStyle {
return {icon: 'images/ic_relatives_48.png' , title: `${vcount} visits, ${ctext}`, text: btext};
}
// TODO a bit ugly, but ok for now.. maybe cut off by time?
const boring = visits.visits.every(v => v.tags.length == 1 && v.tags[0] == LOCAL_TAG);
const boring = visits.visits.every(v => v.tags.length == 1 && v.tags[0] == THIS_BROWSER_TAG);
if (boring) {
// TODO not sure if really worth distinguishing..
return {icon: "images/ic_boring_48.png" , title: `${vcount} visits (${LOCAL_TAG} only)`, text: ''};
return {icon: "images/ic_boring_48.png" , title: `${vcount} visits (${THIS_BROWSER_TAG} only)`, text: ''};
} else {
return {icon: "images/ic_blue_48.png" , title: `${vcount} visits`, text: ''};
}
Expand Down
15 changes: 15 additions & 0 deletions extension/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,18 @@ export function safeSetInnerHTML(element: HTMLElement, html: string) {
export type JsonArray = Array<Json>
export type JsonObject = $Shape<{ [string]: any }>
export type Json = JsonArray | JsonObject


export function getBrowser(): string {
// https://stackoverflow.com/questions/12489546/getting-a-browsers-name-client-side
const agent = window.navigator.userAgent.toLowerCase()
switch (true) {
case agent.indexOf("chrome") > -1 && !! window.chrome: return "chrome";
case agent.indexOf("firefox") > -1 : return "firefox";
case agent.indexOf("safari") > -1 : return "safari";
case agent.indexOf("edge") > -1 : return "edge";
case agent.indexOf("opr") > -1 && !!window.opr : return "opera";
case agent.indexOf("trident") > -1 : return "ie";
default: return "browser";
}
}
4 changes: 4 additions & 0 deletions extension/src/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */
import type {Src} from './common';
import {getBrowser} from './common'

// $FlowFixMe
import OptionsSync from 'webext-options-sync';
Expand Down Expand Up @@ -44,6 +45,9 @@ export const USE_ORIGINAL_TZ = true;

export const GROUP_CONSECUTIVE_SECONDS = 20 * 60;

// TODO: make it configurable in options?
export const THIS_BROWSER_TAG = getBrowser()

// TODO allow to export settings
// https://github.com/fregante/webext-options-sync/issues/23
function defaultOptions(): Options {
Expand Down

0 comments on commit 0bff67c

Please sign in to comment.