File tree 5 files changed +64
-8
lines changed
5 files changed +64
-8
lines changed Original file line number Diff line number Diff line change 10
10
"appDescription" : {
11
11
"message" : " Always use WayBack machine (archive.org) for reddit links" ,
12
12
"description" : " The description of the application"
13
+ },
14
+ "actionTitle" : {
15
+ "message" : " Reddit to WBM" ,
16
+ "description" : " Tooltip for browser action icon"
13
17
}
14
18
}
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ </ head >
6
+
7
+ < body >
8
+ < div >
9
+ < input type ="checkbox " id ="enableRWBM " name ="enableRWBM " value ="enabled " />
10
+ < label for ="enableRWBM "> Enable redirect to WBM</ label >
11
+ </ div >
12
+ < script src ="../scripts/settings.js "> </ script >
13
+ </ body >
14
+ </ html >
Original file line number Diff line number Diff line change 2
2
"name" : " __MSG_appName__" ,
3
3
"short_name" : " __MSG_appShortName__" ,
4
4
"description" : " __MSG_appDescription__" ,
5
- "version" : " 1 .0.0" ,
5
+ "version" : " 2 .0.0" ,
6
6
"manifest_version" : 2 ,
7
7
"default_locale" : " en" ,
8
8
"icons" : {
11
11
},
12
12
"permissions" : [
13
13
" *://*.reddit.com/*" ,
14
- " https://web.archive.org/*" ,
14
+ " *://web.archive.org/*" ,
15
+ " storage" ,
15
16
" webRequest" ,
16
17
" webRequestBlocking"
17
18
],
18
19
"background" : {
19
20
"scripts" : [
20
21
" scripts/background.js"
21
22
]
23
+ },
24
+ "page_action" : {
25
+ "default_title" : " __MSG_actionTitle__" ,
26
+ "default_popup" : " html/settings.html" ,
27
+ "default_icon" : " images/icon-128.png" ,
28
+ "show_matches" : [" *://*.reddit.com/*" , " https://web.archive.org/*" ]
29
+ },
30
+ "options_ui" : {
31
+ "page" : " html/settings.html"
22
32
}
23
33
}
Original file line number Diff line number Diff line change 1
- browser . webRequest . onBeforeRequest . addListener (
2
- checkWBM ,
3
- { urls : [ "*://*.reddit.com/*" ] , types : [ "main_frame" ] } ,
4
- [ "blocking" ]
5
- ) ;
6
-
7
1
browser . webRequest . onBeforeRequest . addListener (
8
2
( details ) => { return { upgradeToSecure : true } } ,
9
3
{ urls : [ "http://*.archive.org/*" ] , types : [ "main_frame" ] } ,
10
4
[ "blocking" ]
11
5
) ;
12
6
7
+ browser . storage . local . get ( 'enableRWBM' ) . then ( ( value ) => {
8
+ if ( ! value . enableRWBM ) setRWBMEnabled ( true ) ;
9
+ } ) ;
10
+
11
+ browser . storage . local . onChanged . addListener ( ( changes ) => {
12
+ if ( changes . enableRWBM ) setRWBMEnabled ( changes . enableRWBM . newValue ) ;
13
+ } ) ;
14
+
15
+ function setRWBMEnabled ( enabled : boolean ) {
16
+ browser . webRequest . onBeforeRequest . removeListener ( checkWBM ) ;
17
+
18
+ if ( enabled ) {
19
+ browser . webRequest . onBeforeRequest . addListener (
20
+ checkWBM ,
21
+ { urls : [ "*://*.reddit.com/*" ] , types : [ "main_frame" ] } ,
22
+ [ "blocking" ]
23
+ ) ;
24
+ }
25
+ }
26
+
13
27
async function checkWBM ( details : browser . webRequest . _OnBeforeRequestDetails ) : Promise < browser . webRequest . BlockingResponse > {
14
28
if ( details . tabId === - 1 || details . method !== "GET" ) {
15
29
return { } ;
Original file line number Diff line number Diff line change
1
+
2
+ ( ( ) => {
3
+ const enableRWBM = document . getElementById ( 'enableRWBM' ) as HTMLInputElement ;
4
+ if ( ! enableRWBM ) return ;
5
+ enableRWBM . addEventListener ( 'change' , ( event ) => {
6
+ browser . storage . local . set ( {
7
+ enableRWBM : ( event . target as HTMLInputElement ) . checked
8
+ } ) ;
9
+ } ) ;
10
+
11
+ browser . storage . local . get ( 'enableRWBM' ) . then ( ( value ) => {
12
+ enableRWBM . checked = value . enableRWBM ?? true ;
13
+ } ) ;
14
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments