function setConsent(consent) {
console.log('Setting consent to:', consent);
localStorage.setItem('tarteaucitronConsent', consent);
console.log('Consent set in localStorage:', localStorage.getItem('tarteaucitronConsent'));
}
function getConsent() {
const consent = localStorage.getItem('tarteaucitronConsent');
console.log('Retrieved consent:', consent);
return consent !== null ? consent : 'unknown'; // 返回默认值
}
function checkConsent() {
const consent = getConsent();
if (consent === 'true') {
tarteaucitron.userInterface.respondAll(true);
} else if (consent === 'false') {
tarteaucitron.userInterface.respondAll(false);
} else {
// 只有在未作出选择时才初始化
tarteaucitron.init({
"privacyUrl": "https://toolhaven.org/privacy", // 隐私政策链接
"hashtag": "#tarteaucitron",
"cookieName": "tarteaucitron",
"orientation": "middle",
"showAlertSmall": false,
"cookieslist": true,
"adblocker": false,
"AcceptAllCta": true,
"highPrivacy": true,
"handleBrowserDNTRequest": false,
"removeCredit": false,
"moreInfoLink": true,
"useExternalCss": false,
"readmoreLink": "/Privacy",
"mandatory": true,
"onAccept": function() {
console.log('User accepted cookies');
setConsent('true');
tarteaucitron.userInterface.respondAll(true);
},
"onDeny": function() {
console.log('User denied cookies');
setConsent('false');
tarteaucitron.userInterface.respondAll(false);
}
});
}
}