File tree Expand file tree Collapse file tree 4 files changed +52
-1
lines changed
Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 11export function isEmpty ( obj :any ) : boolean {
2- for ( var prop in obj ) {
2+ for ( const prop in obj ) {
33 if ( obj . hasOwnProperty ( prop ) )
44 return false ;
55 }
66
77 return JSON . stringify ( obj ) === JSON . stringify ( { } ) ;
8+ }
9+
10+ export function convertStringTimeToSummaryTime ( time :string ) {
11+ const timeValue = time . split ( ':' ) ;
12+ const hour = Number ( timeValue [ 0 ] ) ;
13+ const min = Number ( timeValue [ 1 ] ) ;
14+ let resultTimeValue = 0 ;
15+ if ( hour > 0 )
16+ resultTimeValue = hour * 3600 ;
17+ resultTimeValue += min * 60 ;
18+
19+ return resultTimeValue ;
820}
Original file line number Diff line number Diff line change 1+ import Browser from 'webextension-polyfill' ;
2+
3+ export async function useBlockPage ( url : string , summaryTime : number , summaryCounter : number ) : Promise < void > {
4+ const blockUrl = Browser . runtime . getURL ( "block.html" ) + '?url=' + url
5+ + '&summaryTime=' + summaryTime
6+ + '&summaryCounter=' + summaryCounter ;
7+ const tab = await Browser . tabs . query ( { currentWindow : true , active : true } )
8+ Browser . tabs . update ( tab [ 0 ] . id , { url : blockUrl } ) ;
9+ }
Original file line number Diff line number Diff line change 1+ import { Restriction } from "../entity/restriction" ;
2+ import { Tab } from "../entity/tab" ;
3+ import { injecStorage } from "../storage/inject-storage" ;
4+ import { StorageParams } from "../storage/storage-params" ;
5+ import { todayLocalDate } from "../utils/common" ;
6+
7+ export async function isLimitExceeded ( url : string , tab : Tab ) : Promise < boolean > {
8+ const storage = injecStorage ( ) ;
9+ const limitList = await storage . getValue ( StorageParams . RESTRICTION_LIST ) as Restriction [ ] ;
10+ const item = limitList ?. find ( x => x . domain == url ) ;
11+ if ( item != undefined ) {
12+ const date = tab . days . find ( x => x . date == todayLocalDate ( ) ) ;
13+ if ( date != undefined ) {
14+ return date . summary >= item . time ;
15+ }
16+ }
17+
18+ return false ;
19+ }
Original file line number Diff line number Diff line change 1+ import { convertStringTimeToSummaryTime } from "../common/utility" ;
2+
3+ export class Restriction {
4+ domain : string ;
5+ time : number ;
6+
7+ constructor ( domain : string , time : string ) {
8+ this . domain = domain ;
9+ this . time = convertStringTimeToSummaryTime ( time ) ;
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments