31 lines
963 B
JavaScript
31 lines
963 B
JavaScript
function getCookie(name) {
|
|
console.log("Getting cookie:", name);
|
|
const value = `; ${document.cookie}`;
|
|
console.log("Document cookie string:", value);
|
|
const parts = value.split(`; ${name}=`);
|
|
console.log("Cookie parts:", parts);
|
|
if (parts.length === 2) {
|
|
var text = parts.pop().split(';').shift();
|
|
console.log("Cookie value found:", text);
|
|
return text;
|
|
}
|
|
}
|
|
|
|
function setCookie(name, value, days) {
|
|
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Strict; Secure`;
|
|
}
|
|
|
|
function deleteCookie(name) {
|
|
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
}
|
|
|
|
// 获取浏览器语言
|
|
function getBrowserLanguage() {
|
|
return navigator.language || navigator.userLanguage || 'zh-Hans';
|
|
}
|
|
|
|
// 设置HTML lang属性
|
|
function setHtmlLang(lang) {
|
|
document.documentElement.lang = lang;
|
|
} |