add vanilla-cookieconsent

This commit is contained in:
rustdesk 2024-09-18 15:09:16 +08:00
parent e7f46cdba8
commit 1225f99306
6 changed files with 182 additions and 2 deletions

9
v3/package-lock.json generated
View File

@ -18,7 +18,8 @@
"astro-icon": "^1.1.1",
"limax": "4.1.0",
"lodash.merge": "^4.6.2",
"unpic": "^3.18.0"
"unpic": "^3.18.0",
"vanilla-cookieconsent": "^3.0.1"
},
"devDependencies": {
"@astrojs/check": "^0.9.3",
@ -10031,6 +10032,12 @@
"dev": true,
"license": "MIT"
},
"node_modules/vanilla-cookieconsent": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/vanilla-cookieconsent/-/vanilla-cookieconsent-3.0.1.tgz",
"integrity": "sha512-gqc4x7O9t1I4xWr7x6/jtQWPr4PZK26SmeA0iyTv1WyoECfAGnu5JEOExmMEP+5Fz66AT9OiCBO3GII4wDQHLw==",
"license": "MIT"
},
"node_modules/vfile": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz",

View File

@ -32,7 +32,8 @@
"astro-icon": "^1.1.1",
"limax": "4.1.0",
"lodash.merge": "^4.6.2",
"unpic": "^3.18.0"
"unpic": "^3.18.0",
"vanilla-cookieconsent": "^3.0.1"
},
"devDependencies": {
"@astrojs/check": "^0.9.3",

View File

@ -0,0 +1,52 @@
.cc--elegant-black {
--cc-bg: #000;
--cc-primary-color: rgb(239, 244, 246);
--cc-secondary-color: #b1bdc3 !important;
--cc-btn-primary-bg: #ffffff;
--cc-btn-primary-color: #000;
--cc-btn-primary-hover-bg: #ccd4d8;
--cc-btn-primary-hover-color: #000;
--cc-btn-primary-border-color: var(--cc-btn-primary-bg);
--cc-btn-secondary-bg: rgba(255, 255, 255, 0.039);
--cc-btn-secondary-color: var(--cc-primary-color);
--cc-btn-secondary-border-color: #252729;
--cc-btn-secondary-hover-bg: #252729;
--cc-btn-secondary-hover-color: #fff;
--cc-btn-secondary-hover-border-color: #252729;
--cc-cookie-category-block-bg: #101111;
--cc-cookie-category-block-border: #1d1e1f;
--cc-cookie-category-block-hover-bg: #151516;
--cc-cookie-category-block-hover-border: #1d1e1f;
--cc-cookie-category-expanded-block-hover-bg: #1d1e1f;
--cc-cookie-category-expanded-block-bg: #101111;
--cc-toggle-readonly-bg: #2f3132;
--cc-overlay-bg: rgba(0, 0, 0, 0.9) !important;
--cc-toggle-on-bg: var(--cc-btn-primary-bg);
--cc-toggle-off-bg: #525f6b;
--cc-toggle-on-knob-bg: var(--cc-bg);
--cc-toggle-off-knob-bg: var(--cc-btn-primary-color);
--cc-toggle-readonly-knob-bg: var(--cc-cookie-category-block-bg);
--cc-toggle-enabled-icon-color: var(--cc-btn-primary-color);
--cc-toggle-disabled-icon-color: var(--cc-btn-primary-color);
--cc-toggle-readonly-knob-icon-color: var(--cc-toggle-readonly-bg);
--cc-section-category-border: #1e2428;
--cc-webkit-scrollbar-bg: var(--cc-section-category-border);
--cc-webkit-scrollbar-hover-bg: var(--cc-btn-primary-hover-bg);
--cc-separator-border-color: #252729;
--cc-footer-bg: #000;
--cc-footer-color: var(--cc-secondary-color);
--cc-footer-border-color: #212529;
}
.cc--elegant-black #cc-main .cm,
.cc--elegant-black #cc-main .pm {
color-scheme: dark;
border: 1px solid var(--cc-separator-border-color);
}

View File

@ -0,0 +1,16 @@
---
import 'vanilla-cookieconsent/dist/cookieconsent.css';
import '../assets/styles/ccElegantBlack.css';
---
<button type="button" data-cc="show-preferencesModal">Show preferences modal</button>
<script>
import { run } from 'vanilla-cookieconsent';
import { config } from './CookieConsentConfig';
// toggle custom black theme
document.body.classList.add('cc--elegant-black');
run(config);
</script>

View File

@ -0,0 +1,102 @@
import type { CookieConsentConfig } from 'vanilla-cookieconsent';
export const config: CookieConsentConfig = {
guiOptions: {
consentModal: {
layout: 'box inline',
position: 'bottom left',
},
preferencesModal: {
layout: 'box',
position: 'right',
equalWeightButtons: true,
flipButtons: false,
},
},
categories: {
necessary: {
readOnly: true,
},
functionality: {},
analytics: {
services: {
ga4: {
label:
'<a href="https://marketingplatform.google.com/about/analytics/terms/us/" target="_blank">Google Analytics 4 (dummy)</a>',
onAccept: () => {
console.log('ga4 accepted');
// TODO: load ga4
},
onReject: () => {
console.log('ga4 rejected');
},
cookies: [
{
name: /^_ga/,
},
],
},
another: {
label: 'Another one (dummy)',
},
},
},
},
language: {
default: 'en',
autoDetect: 'browser',
translations: {
en: {
consentModal: {
title: "Hello traveller, it's cookie time!",
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.',
acceptAllBtn: 'Accept all',
acceptNecessaryBtn: 'Reject all',
showPreferencesBtn: 'Manage preferences',
footer:
'<a href="#link">Privacy Policy</a>\n<a href="#link">Terms and conditions</a>',
},
preferencesModal: {
title: 'Consent Preferences Center',
acceptAllBtn: 'Accept all',
acceptNecessaryBtn: 'Reject all',
savePreferencesBtn: 'Save preferences',
closeIconLabel: 'Close modal',
serviceCounterLabel: 'Service|Services',
sections: [
{
title: 'Cookie Usage',
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
},
{
title:
'Strictly Necessary Cookies <span class="pm__badge">Always Enabled</span>',
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
linkedCategory: 'necessary',
},
{
title: 'Functionality Cookies',
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
linkedCategory: 'functionality',
},
{
title: 'Analytics Cookies',
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
linkedCategory: 'analytics',
},
{
title: 'More information',
description:
'For any query in relation to my policy on cookies and your choices, please <a class="cc__link" href="#yourdomain.com">contact me</a>.',
},
],
},
},
},
},
};

View File

@ -11,6 +11,7 @@ import Metadata from '~/components/common/Metadata.astro';
import SiteVerification from '~/components/common/SiteVerification.astro';
import Analytics from '~/components/common/Analytics.astro';
import BasicScripts from '~/components/common/BasicScripts.astro';
import CookieConsent from '../components/CookieConsent.astro';
// Comment the line below to disable View Transitions
import { ViewTransitions } from 'astro:transitions';
@ -44,5 +45,6 @@ const { language, textDirection } = I18N;
<slot />
<BasicScripts />
<CookieConsent />
</body>
</html>