File tree Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -86,17 +86,36 @@ export default {
8686
8787function changeCountry ( value , persist ) {
8888 if ( value ) {
89- location . href =
90- "https://www.youtube.com/feed/trending?persist_gl=" +
91- ( persist ? "1" : "0" ) +
92- ( "&gl=" + value ) ;
89+ let href = "https://www.youtube.com/feed/trending" ;
90+ if ( persist ) {
91+ if ( value !== "default" ) {
92+ var date = new Date ( ) ;
93+ date . setTime ( date . getTime ( ) + 3.154e10 ) ;
94+
95+ document . cookie =
96+ "s_gl=" +
97+ value +
98+ "; path=/; domain=.youtube.com; expires=" +
99+ date . toGMTString ( ) ;
100+ } else {
101+ document . cookie =
102+ "s_gl=0; path=/; domain=.youtube.com; expires=Thu, 01 Jan 1970 00:00:01 GMT" ;
103+ }
104+
105+ window . location . href = href ;
106+ } else {
107+ href += `?persist_gl=0&gl=${ value } ` ;
108+ window . location . href = href ;
109+ }
93110 }
94111}
95112
96113function getCurrentCountry ( ) {
97114 const code =
98115 window ?. ytInitialData ?. topbar ?. desktopTopbarRenderer ?. countryCode ||
99- window . yt ?. config_ ?. GL ;
116+ window . yt ?. config_ ?. GL ||
117+ // regex in cookie
118+ document . cookie . match ( / s _ g l = ( [ ^ ; ] + ) / ) ?. [ 1 ] ;
100119 return code || "default" ;
101120}
102121
You can’t perform that action at this time.
0 commit comments