Skip to content

Commit 0e38b0d

Browse files
committed
persist cookie
1 parent 6a5eca5 commit 0e38b0d

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/youtube_changeCountry.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,36 @@ export default {
8686

8787
function 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

96113
function 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_gl=([^;]+)/)?.[1];
100119
return code || "default";
101120
}
102121

0 commit comments

Comments
 (0)