File tree Expand file tree Collapse file tree 6 files changed +169
-0
lines changed
Expand file tree Collapse file tree 6 files changed +169
-0
lines changed Original file line number Diff line number Diff line change 1+ setInterval ( countTimeSpentMinutes , 60000 ) ;
2+
3+ async function countTimeSpentMinutes ( ) {
4+ let seconds = 0 ;
5+ let today = new Date ;
6+ try {
7+ lastday = localStorage . getItem ( "ytb_last_session_day" ) ;
8+ // console.log("last day = "+lastday);
9+ } catch ( error ) {
10+ console . log ( error ) ;
11+ lastday = - 1 ;
12+ }
13+
14+ if ( today . getDate ( ) != lastday ) { // then reset time spent
15+ localStorage . setItem ( "ytb_time_spent" , 0 ) ;
16+ } // else do nothing
17+
18+ localStorage . setItem ( "ytb_last_session_day" , today . getDate ( ) ) ;
19+ console . log ( "today date = " + today . getDate ( ) ) ;
20+
21+ try {
22+ seconds = localStorage . getItem ( "ytb_time_spent" ) ;
23+ // console.log("s2 = "+seconds);
24+ } catch ( error ) {
25+ console . log ( error ) ;
26+ seconds = 0 ;
27+ }
28+ localStorage . setItem ( "ytb_time_spent" , ( Number ( seconds ) + 60 ) ) ;
29+ console . log ( "s3 = " + seconds ) ;
30+
31+ if ( seconds > 3600 ) {
32+ alert ( "Daily YouTube time limit of 1 hour reached !" ) ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ {
2+
3+ "manifest_version" : 2 ,
4+ "name" : " YouTube Daily Time Limiter" ,
5+ "version" : " 1.0" ,
6+
7+ "description" : " Limits daily time spent on YouTube website" ,
8+ "permissions" : [
9+ " storage"
10+ ],
11+ "content_scripts" : [
12+ {
13+ "matches" : [" *://*.youtube.com/*" ],
14+ "js" : [" main.js" ]
15+ }
16+ ]
17+
18+ }
19+
Original file line number Diff line number Diff line change 1+ // for test purposes
2+ localStorage . setItem ( "ytb_time_spent" , 59999 ) ;
3+ localStorage . setItem ( "ytb_last_session_day" , 1 ) ; // from 1 to 31
4+
5+ setInterval ( countTimeSpentMinutes , 60000 ) ; // convert to minutes after successful test
6+
7+ async function countTimeSpentMinutes ( ) {
8+ let seconds = 0 ;
9+ let today = new Date ;
10+ try {
11+ lastday = localStorage . getItem ( "ytb_last_session_day" ) ;
12+ // console.log("last day = "+lastday);
13+ } catch ( error ) {
14+ console . log ( error ) ;
15+ lastday = - 1 ;
16+ }
17+
18+ if ( today . getDate ( ) != lastday ) { // then reset time spent
19+ localStorage . setItem ( "ytb_time_spent" , 0 ) ;
20+ } // else do nothing
21+
22+ localStorage . setItem ( "ytb_last_session_day" , today . getDate ( ) ) ;
23+ console . log ( "today date = " + today . getDate ( ) ) ;
24+
25+ try {
26+ seconds = localStorage . getItem ( "ytb_time_spent" ) ;
27+ // console.log("s2 = "+seconds);
28+ } catch ( error ) {
29+ console . log ( error ) ;
30+ seconds = 0 ;
31+ }
32+ localStorage . setItem ( "ytb_time_spent" , ( Number ( seconds ) + 60 ) ) ; // convert to minutes after successful test
33+ console . log ( "s3 = " + seconds ) ;
34+
35+ if ( seconds > 3600 ) {
36+ alert ( "Daily YouTube time limit of 1 hour reached !" ) ;
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ {
2+
3+ "manifest_version" : 2 ,
4+ "name" : " YtbTimeLimiter" ,
5+ "version" : " 1.0" ,
6+
7+ "description" : " Limits daily time spent on YouTube website" ,
8+ "permissions" : [
9+ " storage"
10+ ],
11+ "content_scripts" : [
12+ {
13+ "matches" : [" *://*.youtube.com/*" ],
14+ "js" : [" main.js" ]
15+ }
16+ ]
17+
18+ }
19+
Original file line number Diff line number Diff line change 1+ // a non production ready branch which enables to quickly test the extension
2+
3+ // for test purposes
4+ // localStorage.setItem("ytb_time_spent", 59999);
5+ // localStorage.setItem("ytb_last_session_day", 1);
6+
7+ setInterval ( countTimeSpentSeconds , 1000 ) ;
8+
9+ async function countTimeSpentSeconds ( ) {
10+ let seconds = 0 ;
11+ let today = new Date ;
12+ try {
13+ lastday = await localStorage . getItem ( "ytb_last_session_day" ) ;
14+ console . log ( "last day = " + lastday ) ;
15+ } catch ( error ) {
16+ console . log ( error ) ;
17+ lastday = - 1 ;
18+ }
19+
20+ if ( today . getDate ( ) != lastday ) { // then reset time spent
21+ localStorage . setItem ( "ytb_time_spent" , 0 ) ;
22+ } // else do nothing
23+
24+ localStorage . setItem ( "ytb_last_session_day" , today . getDate ( ) ) ;
25+ console . log ( "today date = " + today . getDate ( ) ) ;
26+
27+ try {
28+ seconds = await localStorage . getItem ( "ytb_time_spent" ) ;
29+ console . log ( "s2 = " + seconds ) ;
30+ } catch ( error ) {
31+ console . log ( error ) ;
32+ seconds = 0 ;
33+ }
34+ localStorage . setItem ( "ytb_time_spent" , ( Number ( seconds ) + 1 ) ) ;
35+ console . log ( "s3 = " + seconds ) ;
36+
37+ if ( seconds > 10 ) {
38+ alert ( "Daily YouTube time limit reached !" ) ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ {
2+
3+ "manifest_version" : 2 ,
4+ "name" : " YtbTimeLimiter" ,
5+ "version" : " 1.0" ,
6+
7+ "description" : " Limits daily time spent on YouTube website" ,
8+ "permissions" : [
9+ " storage"
10+ ],
11+ "content_scripts" : [
12+ {
13+ "matches" : [" *://*.youtube.com/*" ],
14+ "js" : [" main.js" ]
15+ }
16+ ]
17+
18+ }
19+
You can’t perform that action at this time.
0 commit comments