@@ -12,20 +12,21 @@ if (form && input) {
1212 event . preventDefault ( ) ;
1313 try {
1414 // isInTabMode is declared in main.js
15- if ( isInTabMode ) await processUrl ( input . value , "" ) ;
16- else await processUrl ( input . value , "/tabs" ) ;
15+ if ( isInTabMode ) await navigate ( input . value , "" ) ;
16+ else await navigate ( input . value , "/tabs" ) ;
1717 } catch {
18- await processUrl ( input . value , "/tabs" ) ;
18+ await navigate ( input . value , "/tabs" ) ;
1919 }
2020 } ) ;
2121}
22- function useScramjetPxy ( proxyOverride ) {
23- const p = proxyOverride ?? localStorage . getItem ( "pchoice" ) ;
24- return p === "sj" ;
22+
23+ function isScramjet ( proxyOverride ) {
24+ const choice = proxyOverride ?? localStorage . getItem ( "pchoice" ) ;
25+ return choice === "sj" ;
2526}
2627
27- async function getPxyUrl ( url , proxyOverride ) {
28- if ( useScramjetPxy ( proxyOverride ) ) {
28+ async function encodeUrl ( url , proxyOverride ) {
29+ if ( isScramjet ( proxyOverride ) ) {
2930 if ( window . __isSjReady ) {
3031 await window . __isSjReady ;
3132 }
@@ -37,49 +38,44 @@ async function getPxyUrl(url, proxyOverride) {
3738 return `/uv/${ __uv$config . encodeUrl ( url ) } ` ;
3839}
3940
40- async function processUrl ( value , path , proxyOverride ) {
41+ async function navigate ( value , path , proxyOverride ) {
4142 let url = value . trim ( ) ;
4243 const engine = localStorage . getItem ( "engine" ) ;
4344 const searchUrl = engine ? engine : "https://search.brave.com/search?q=" ;
4445
45- if ( ! isUrl ( url ) ) {
46+ if ( ! isValidUrl ( url ) ) {
4647 url = searchUrl + url ;
4748 } else if ( ! ( url . startsWith ( "https://" ) || url . startsWith ( "http://" ) ) ) {
4849 url = `https://${ url } ` ;
4950 }
5051
5152 const pchoice = proxyOverride ?? localStorage . getItem ( "pchoice" ) ;
52- const pxyUrl = await getPxyUrl ( url , pchoice ) ;
53- sessionStorage . setItem ( "GoUrl" , pxyUrl ) ;
53+ const proxyUrl = await encodeUrl ( url , pchoice ) ;
54+ sessionStorage . setItem ( "GoUrl" , proxyUrl ) ;
5455
5556 if ( pchoice === "dy" ) {
5657 window . location . href = `/uv/dynamic/${ __uv$config . encodeUrl ( url ) } ` ;
5758 } else if ( path ) {
5859 location . href = path ;
5960 } else {
60- window . location . href = pxyUrl ;
61+ window . location . href = proxyUrl ;
6162 }
6263}
6364
65+ // Open link in the tabs page
6466function go ( value , proxyOverride ) {
65- processUrl ( value , "/tabs" , proxyOverride ) ;
67+ navigate ( value , "/tabs" , proxyOverride ) ;
6668}
6769
70+ // Open link in about:blank
6871function blank ( value , proxyOverride ) {
69- processUrl ( value , "" , proxyOverride ) ;
70- }
71-
72- function now ( value , proxyOverride ) {
73- processUrl ( value , "" , proxyOverride ) ;
72+ navigate ( value , "" , proxyOverride ) ;
7473}
7574
76- function dy ( value ) {
77- processUrl ( value , `/uv/dynamic/${ __uv$config . encodeUrl ( value ) } ` , "dy" ) ;
75+ function useDynamic ( value ) {
76+ navigate ( value , `/uv/dynamic/${ __uv$config . encodeUrl ( value ) } ` , "dy" ) ;
7877}
7978
80- function isUrl ( val = "" ) {
81- if ( / ^ h t t p ( s ? ) : \/ \/ / . test ( val ) || ( val . includes ( "." ) && val . substr ( 0 , 1 ) !== " " ) ) {
82- return true ;
83- }
84- return false ;
85- }
79+ function isValidUrl ( val = "" ) {
80+ return / ^ h t t p ( s ? ) : \/ \/ / . test ( val ) || ( val . includes ( "." ) && val [ 0 ] !== " " ) ;
81+ }
0 commit comments