File tree Expand file tree Collapse file tree 5 files changed +50
-5
lines changed
Expand file tree Collapse file tree 5 files changed +50
-5
lines changed Original file line number Diff line number Diff line change 1+ export function isEmpty ( obj :any ) : boolean {
2+ for ( var prop in obj ) {
3+ if ( obj . hasOwnProperty ( prop ) )
4+ return false ;
5+ }
6+
7+ return JSON . stringify ( obj ) === JSON . stringify ( { } ) ;
8+ }
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ import { StorageParams } from "../storage/storage-params";
44export async function isInBlackList ( url : string ) : Promise < boolean > {
55 const storage = injecStorage ( ) ;
66 const blackList = await storage . getValue ( StorageParams . BLACK_LIST ) as string [ ] ;
7- return blackList . indexOf ( url ) != - 1 ? true : false ;
7+ return blackList != undefined && blackList . indexOf ( url ) != - 1 ? true : false ;
88}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { IStorage } from "./storage-interface";
22import { StorageParams } from "./storage-params" ;
33import { Tab } from "../entity/tab" ;
44import Browser from 'webextension-polyfill' ;
5+ import { isEmpty } from "../common/utility" ;
56
67export class LocalStorage implements IStorage {
78 getTabs ( ) : Promise < Tab [ ] > {
@@ -23,8 +24,12 @@ export class LocalStorage implements IStorage {
2324 } ) ;
2425 }
2526
26- async getValue ( name : StorageParams ) : Promise < any > {
27- const value = await Browser . storage . local . get ( name ) ;
27+ async getValue ( name : StorageParams , defaultValue ?: any ) : Promise < any > {
28+ let value = await Browser . storage . local . get ( name ) ;
29+ if ( isEmpty ( value ) && defaultValue != undefined ) {
30+ await this . saveValue ( name , defaultValue ) ;
31+ return defaultValue ;
32+ }
2833 return value [ name ] ;
2934 }
3035}
Original file line number Diff line number Diff line change @@ -5,5 +5,5 @@ export interface IStorage {
55 getTabs ( ) : Promise < Tab [ ] > ;
66 saveTabs ( value :Tab [ ] ) : Promise < void > ;
77 saveValue ( name :StorageParams , value : any ) : Promise < void > ;
8- getValue ( name :StorageParams ) : Promise < any > ;
8+ getValue ( name :StorageParams , defaultValue ?: any ) : Promise < any > ;
99}
Original file line number Diff line number Diff line change @@ -12,4 +12,36 @@ export enum StorageParams {
1212 VIEW_TIME_IN_BADGE = 'view_time_in_badge' ,
1313 BLOCK_DEFERRAL = 'view_block_deferral' ,
1414 SHOW_HINT = 'show_hint' ,
15- }
15+ }
16+
17+ export enum InactivityInterval {
18+ Seconds_30 = 30 ,
19+ Seconds_45 = 45 ,
20+ Min_1 = 60 ,
21+ Min_2 = 120 ,
22+ Min_5 = 300 ,
23+ Min_10 = 600 ,
24+ Min_20 = 1200 ,
25+ Min_30 = 1800
26+ } ;
27+
28+ export enum RangeForDays {
29+ Days_2 = 'days2' ,
30+ Days_3 = 'days3' ,
31+ Days_4 = 'days4' ,
32+ Days_5 = 'days5' ,
33+ Days_6 = 'days6' ,
34+ Days_7 = 'days7' ,
35+ Month_1 = 'month1' ,
36+ Month_2 = 'month2' ,
37+ Month_3 = 'month3'
38+ } ;
39+
40+ export const NOTIFICATION_MESSAGE_DEFAULT = 'You have spent a lot of time on this site' ;
41+ export const INTERVAL_INACTIVITY_DEFAULT = InactivityInterval . Seconds_30 ;
42+ export const INTERVAL_SAVE_STORAGE_DEFAULT = 5000 ;
43+ export const INTERVAL_RANGE_DEFAULT = RangeForDays . Days_7 ;
44+ export const DARK_MODE_DEFAULT = false ;
45+ export const VIEW_TIME_IN_BADGE_DEFAULT = true ;
46+ export const BLOCK_DEFERRAL_DEFAULT = true ;
47+ export const SHOW_HINT_DEFAULT = true ;
You can’t perform that action at this time.
0 commit comments