@@ -62,68 +62,21 @@ async function redirectAsync(url, type, initiator, forceRedirection) {
62
62
}
63
63
64
64
/**
65
- * @param {URL } url
66
- * @param {string } type
67
- * @param {URL } initiator
68
- * @param {boolean } forceRedirection
69
- * @returns {string | undefined }
65
+ * @param url
66
+ * @param frontend
67
+ * @param randomInstance
68
+ * @returns {undefined|string }
70
69
*/
71
- function redirect ( url , type , initiator , forceRedirection , incognito ) {
72
- if ( type != "main_frame" && type != "sub_frame" && type != "image" ) return
73
- let randomInstance
74
- let frontend
75
- if ( ! forceRedirection && options . redirectOnlyInIncognito == true && ! incognito ) return
76
- for ( const service in config . services ) {
77
- if ( ! forceRedirection && ! options [ service ] . enabled ) continue
78
-
79
- frontend = options [ service ] . frontend
80
-
81
-
82
- if ( config . services [ service ] . frontends [ frontend ] . desktopApp && type != "main_frame" && options [ service ] . redirectType != "main_frame" )
83
- frontend = options [ service ] . embedFrontend
84
-
85
-
86
- if ( ! regexArray ( service , url , config , frontend ) ) {
87
- frontend = null
88
- continue
89
- }
90
-
91
- if (
92
- config . services [ service ] . embeddable &&
93
- type != options [ service ] . redirectType && options [ service ] . redirectType != "both"
94
- ) {
95
- if ( options [ service ] . unsupportedUrls == 'block' ) return 'CANCEL'
96
- return
97
- }
98
-
99
- let instanceList = options [ frontend ]
100
- if ( instanceList === undefined ) break
101
- if ( instanceList . length === 0 ) return null
102
-
103
- if (
104
- initiator
105
- &&
106
- instanceList . includes ( initiator . origin )
107
- ) {
108
- if ( type != "main_frame" ) return null
109
- else return "BYPASSTAB"
110
- }
111
-
112
- randomInstance = utils . getRandomInstance ( instanceList )
113
- if ( config . services [ service ] . frontends [ frontend ] . localhost && options [ service ] . instance == "localhost" ) {
114
- randomInstance = `http://${ frontend } .localhost:8080`
115
- }
116
- break
117
- }
118
- if ( ! frontend ) return
119
-
70
+ function rewrite ( url , frontend , randomInstance ) {
71
+ if ( ! frontend || ! randomInstance ) return
120
72
switch ( frontend ) {
121
73
case "hyperpipe" : {
122
74
return `${ randomInstance } ${ url . pathname } ${ url . search } ` . replace ( / \/ s e a r c h \? q = .* / , searchQuery => searchQuery . replace ( "?q=" , "/" ) )
123
75
}
124
76
case "searx" :
125
- case "searxng" :
77
+ case "searxng" : {
126
78
return `${ randomInstance } /${ url . search } `
79
+ }
127
80
case "whoogle" : {
128
81
return `${ randomInstance } /search${ url . search } `
129
82
}
@@ -149,7 +102,6 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
149
102
case "freetubePwa" : {
150
103
return 'freetube://' + url . href
151
104
}
152
-
153
105
case "poketube" : {
154
106
if ( url . pathname . startsWith ( '/channel' ) ) {
155
107
const reg = / \/ c h a n n e l \/ ( .* ) \/ ? $ / . exec ( url . pathname )
@@ -557,6 +509,60 @@ function redirect(url, type, initiator, forceRedirection, incognito) {
557
509
}
558
510
}
559
511
512
+ /**
513
+ * @param {URL } url
514
+ * @param {string } type
515
+ * @param {URL } initiator
516
+ * @param {boolean } forceRedirection
517
+ * @returns {string | undefined }
518
+ */
519
+ function redirect ( url , type , initiator , forceRedirection , incognito ) {
520
+ if ( type != "main_frame" && type != "sub_frame" && type != "image" ) return
521
+ let randomInstance
522
+ let frontend
523
+ if ( ! forceRedirection && options . redirectOnlyInIncognito == true && ! incognito ) return
524
+ for ( const service in config . services ) {
525
+ if ( ! forceRedirection && ! options [ service ] . enabled ) continue
526
+
527
+ frontend = options [ service ] . frontend
528
+
529
+ if ( config . services [ service ] . frontends [ frontend ] . desktopApp && type != "main_frame" && options [ service ] . redirectType != "main_frame" )
530
+ frontend = options [ service ] . embedFrontend
531
+
532
+ if ( ! regexArray ( service , url , config , frontend ) ) {
533
+ frontend = null
534
+ continue
535
+ }
536
+
537
+ if (
538
+ config . services [ service ] . embeddable
539
+ &&
540
+ type != options [ service ] . redirectType && options [ service ] . redirectType != "both"
541
+ ) {
542
+ if ( options [ service ] . unsupportedUrls == 'block' ) return 'CANCEL'
543
+ return
544
+ }
545
+
546
+ let instanceList = options [ frontend ]
547
+ if ( instanceList === undefined ) break
548
+ if ( instanceList . length === 0 ) return null
549
+
550
+ if ( initiator && instanceList . includes ( initiator . origin ) ) {
551
+ if ( type != "main_frame" ) return null
552
+ else return "BYPASSTAB"
553
+ }
554
+
555
+ randomInstance = utils . getRandomInstance ( instanceList )
556
+ if ( config . services [ service ] . frontends [ frontend ] . localhost && options [ service ] . instance == "localhost" ) {
557
+ randomInstance = `http://${ frontend } .localhost:8080`
558
+ }
559
+ break
560
+ }
561
+ if ( ! frontend ) return
562
+
563
+ return rewrite ( url , frontend , randomInstance )
564
+ }
565
+
560
566
/**
561
567
* @param {URL } url
562
568
* @param {* } returnFrontend
0 commit comments