1- var currentURL = '' ;
1+ var currentURL = "" ;
22var isHTTPS = true ;
33var index = 0 ;
44var numberOfRedirects = 0 ;
55var redirecting = false ;
66
77var cacheURL = [
8- ' http://webcache.googleusercontent.com/search?q=cache:' ,
9- ' http://web.archive.org/web/*/' ,
10- ' .nyud.net'
8+ " http://webcache.googleusercontent.com/search?q=cache:" ,
9+ " http://web.archive.org/web/*/" ,
10+ " .nyud.net"
1111] ;
12- var cacheNames = [ ' google-cache-sortable' , ' wayback-machine-sortable' , ' coral-cdn-sortable' ] ;
12+ var cacheNames = [ " google-cache-sortable" , " wayback-machine-sortable" , " coral-cdn-sortable" ] ;
1313var URL_HASH = [
14- { name : ' google-cache-sortable' , URL : ' http://webcache.googleusercontent.com/search?q=cache:' } ,
15- { name : ' wayback-machine-sortable' , URL : ' http://web.archive.org/web/*/' } ,
16- { name : ' coral-cdn-sortable' , URL : ' .nyud.net' }
14+ { name : " google-cache-sortable" , URL : " http://webcache.googleusercontent.com/search?q=cache:" } ,
15+ { name : " wayback-machine-sortable" , URL : " http://web.archive.org/web/*/" } ,
16+ { name : " coral-cdn-sortable" , URL : " .nyud.net" }
1717] ;
1818
1919function getURL ( ) {
2020 ++ numberOfRedirects ;
2121 if ( cacheURL [ index ] == cacheURL . length ) {
2222 index = 0 ;
2323 }
24- if ( cacheURL [ index ] != ' .nyud.net' ) { // Google and Wayback Machine
25- return cacheURL [ index ] + ( isHTTPS ? currentURL . substr ( 8 ) : currentURL . substr ( 7 ) )
24+ if ( cacheURL [ index ] != " .nyud.net" ) { // Google and Wayback Machine
25+ return cacheURL [ index ] + ( isHTTPS ? currentURL . substr ( 8 ) : currentURL . substr ( 7 ) ) ;
2626 } else { // Coral CDN
27- if ( currentURL . slice ( - 1 ) == '/' ) {
28- return currentURL . substring ( 0 , currentURL . length - 1 ) + ' .nyud.net' ;
27+ if ( currentURL . slice ( - 1 ) == "/" ) {
28+ return currentURL . substring ( 0 , currentURL . length - 1 ) + " .nyud.net" ;
2929 } else {
30- return currentURL + ' .nyud.net' ;
30+ return currentURL + " .nyud.net" ;
3131 }
3232 }
3333}
3434
3535function handler ( details ) {
36- //console.log(' StatusLine is: ' + details.statusLine);
36+ //console.log(" StatusLine is: " + details.statusLine);
3737 if ( numberOfRedirects > cacheURL . length ) { // There is no cache available
3838 chrome . webRequest . onHeadersReceived . removeListener ( handler ) ;
3939 redirecting = false ;
4040 return { cancel : true } ;
4141 }
42- if ( ~ details . statusLine . search ( ' 404' ) ) { // Not found
42+ if ( ~ details . statusLine . search ( " 404" ) ) { // Not found
4343 ++ index ;
4444 return { redirectUrl :getURL ( ) } ;
4545 }
46- else if ( ~ details . statusLine . search ( ' 403' ) ) { // Forbidden
46+ else if ( ~ details . statusLine . search ( " 403" ) ) { // Forbidden
4747 ++ index ;
4848 return { redirectUrl :getURL ( ) } ;
4949 }
@@ -55,8 +55,8 @@ function handler(details) {
5555}
5656
5757function openPage ( currentTab ) {
58- chrome . storage . sync . get ( ' cacheOrder4' , function ( result ) {
59- var cacheOrder = result [ ' cacheOrder4' ] || cacheNames ;
58+ chrome . storage . sync . get ( " cacheOrder4" , function ( result ) {
59+ var cacheOrder = result [ " cacheOrder4" ] || cacheNames ;
6060
6161 URL_HASH . sort ( function ( a , b ) {
6262 return cacheOrder . indexOf ( a . name ) - cacheOrder . indexOf ( b . name ) ;
@@ -76,17 +76,17 @@ function openPage(currentTab) {
7676 chrome . webRequest . onHeadersReceived . addListener (
7777 handler ,
7878 {
79- urls : [ ' <all_urls>' ] ,
80- types : [ ' main_frame' ]
79+ urls : [ " <all_urls>" ] ,
80+ types : [ " main_frame" ]
8181 } ,
82- [ ' blocking' ]
82+ [ " blocking" ]
8383 ) ;
8484
8585 currentURL = currentTab . url ;
8686
87- isHTTPS = ( currentURL . substring ( 0 , 6 ) == ' https:' ) ;
87+ isHTTPS = ( currentURL . substring ( 0 , 6 ) == " https:" ) ;
8888
89- //console.log(' the tab id for the redirect is ' + currentTab.id + ' : The website is: ' + currentURL);
89+ //console.log(" the tab id for the redirect is " + currentTab.id + " : The website is: " + currentURL);
9090
9191 chrome . tabs . update ( currentTab . id , { url : getURL ( index ) } ) ;
9292
@@ -106,37 +106,37 @@ function autoRedirect(details) {
106106 if ( tab == null || redirecting )
107107 return ;
108108
109- if ( ~ details . statusLine . indexOf ( ' 408' ) ) {
110- console . log ( ' 408 redirect' ) ;
111- } else if ( ~ details . statusLine . indexOf ( ' 503' ) ) {
112- console . log ( ' 503 redirect' ) ;
109+ if ( ~ details . statusLine . indexOf ( " 408" ) ) {
110+ console . log ( " 408 redirect" ) ;
111+ } else if ( ~ details . statusLine . indexOf ( " 503" ) ) {
112+ console . log ( " 503 redirect" ) ;
113113 openPage ( tab ) ;
114- } else if ( ~ details . statusLine . indexOf ( ' 521' ) ) {
115- console . log ( ' 521 redirect' ) ;
114+ } else if ( ~ details . statusLine . indexOf ( " 521" ) ) {
115+ console . log ( " 521 redirect" ) ;
116116 openPage ( tab ) ;
117- } else if ( ~ details . statusLine . indexOf ( ' 522' ) ) {
118- console . log ( ' 522 redirect' ) ;
117+ } else if ( ~ details . statusLine . indexOf ( " 522" ) ) {
118+ console . log ( " 522 redirect" ) ;
119119 openPage ( tab ) ;
120120 }
121121 } ) ;
122122}
123123
124- chrome . storage . sync . get ( ' auto-detect' , function ( result ) {
125- if ( result [ ' auto-detect' ] == 'on' ) {
124+ chrome . storage . sync . get ( " auto-detect" , function ( result ) {
125+ if ( result [ " auto-detect" ] == "on" ) {
126126 chrome . webRequest . onHeadersReceived . addListener (
127127 autoRedirect ,
128- { urls : [ ' <all_urls>' ] }
128+ { urls : [ " <all_urls>" ] }
129129 ) ;
130130 }
131131} ) ;
132132
133133// Set defaults on install or update
134134chrome . runtime . onInstalled . addListener ( function ( details ) {
135- chrome . storage . sync . get ( ' cacheOrder' , function ( result ) {
135+ chrome . storage . sync . get ( " cacheOrder" , function ( result ) {
136136 if ( Object . keys ( result ) . length == 0 ) {
137137 var saveObject = {
138- ' cacheOrder4' : cacheNames ,
139- ' auto-detect' : ' off'
138+ " cacheOrder4" : cacheNames ,
139+ " auto-detect" : " off"
140140 } ;
141141 chrome . storage . sync . set ( saveObject ) ;
142142 }
0 commit comments