11import initStorage from "./storage/init" ;
2- import storage from "./storage" ;
3- import findRule from "./helpers/find-rule" ;
4- import * as counterHelper from "./helpers/counter" ;
5- import getBlockedUrl from "./helpers/get-blocked-url" ;
2+ import blockSite from "./helpers/block-site" ;
3+ import createContextMenu from "./helpers/create-context-menu" ;
64
7- chrome . runtime . onInstalled . addListener ( ( ) => {
8- initStorage ( ) ;
9- } ) ;
5+ initStorage ( createContextMenu ) ;
106
117chrome . action . onClicked . addListener ( ( ) => {
128 chrome . runtime . openOptionsPage ( ) ;
@@ -18,42 +14,5 @@ chrome.webNavigation.onBeforeNavigate.addListener((details) => {
1814 return ;
1915 }
2016
21- storage . get ( [ "enabled" , "blocked" ] , ( { enabled, blocked } ) => {
22- if ( ! enabled || blocked . length === 0 ) {
23- return ;
24- }
25-
26- const foundRule = findRule ( url , blocked ) ;
27- if ( ! foundRule || foundRule . type === "allow" ) {
28- storage . get ( [ "counter" ] , ( { counter } ) => {
29- counterHelper . flushObsoleteEntries ( { blocked, counter } ) ;
30- storage . set ( { counter } ) ;
31- } ) ;
32- return ;
33- }
34-
35- storage . get ( [ "counter" , "counterShow" , "counterPeriod" , "resolution" ] , ( { counter, counterShow, counterPeriod, resolution } ) => {
36- counterHelper . flushObsoleteEntries ( { blocked, counter } ) ;
37- const count = counterHelper . add ( foundRule . path , timeStamp , {
38- counter,
39- countFromTimeStamp : counterHelper . counterPeriodToTimeStamp ( counterPeriod , new Date ( ) . getTime ( ) ) ,
40- } ) ;
41- storage . set ( { counter } ) ;
42-
43- switch ( resolution ) {
44- case "CLOSE_TAB" :
45- chrome . tabs . remove ( tabId ) ;
46- break ;
47- case "SHOW_BLOCKED_INFO_PAGE" : {
48- chrome . tabs . update ( tabId , {
49- url : getBlockedUrl ( {
50- url,
51- rule : foundRule . path ,
52- countParams : counterShow ? { count, period : counterPeriod } : undefined } ,
53- ) } ,
54- ) ;
55- break ;
56- } }
57- } ) ;
58- } ) ;
17+ blockSite ( { tabId, url, timeStamp } ) ;
5918} ) ;
0 commit comments