@jarijokinen/consent 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/package.json +5 -2
- package/src/consent.js +19 -0
package/README.md
CHANGED
|
@@ -51,13 +51,18 @@ argument to the consent() function.
|
|
|
51
51
|
dialogTitle: 'Cookies',
|
|
52
52
|
dialogMessage: 'We would like to get your permission to use cookies for:',
|
|
53
53
|
dialogClass: 'consent',
|
|
54
|
-
settingsLinkSelector: '.consent-settings-link'
|
|
54
|
+
settingsLinkSelector: '.consent-settings-link',
|
|
55
|
+
countryCookie: 'cf_country',
|
|
56
|
+
countries: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR',
|
|
57
|
+
'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL',
|
|
58
|
+
'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'IS', 'LI', 'NO',
|
|
59
|
+
'GB', 'CH', 'MC', 'SM', 'VA', 'JE', 'GG', 'IM']
|
|
55
60
|
};
|
|
56
61
|
|
|
57
62
|
consent(options);
|
|
58
63
|
|
|
59
64
|
## License
|
|
60
65
|
|
|
61
|
-
MIT License. Copyright (c) 2022 [Jari Jokinen](https://jarijokinen.com).
|
|
62
|
-
[LICENSE](https://github.com/jarijokinen/consent/blob/main/LICENSE.txt)
|
|
66
|
+
MIT License. Copyright (c) 2022 - 2025 [Jari Jokinen](https://jarijokinen.com).
|
|
67
|
+
See [LICENSE](https://github.com/jarijokinen/consent/blob/main/LICENSE.txt)
|
|
63
68
|
for further details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarijokinen/consent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A zero-dependency, vanilla JavaScript consent manager with native Consent Mode support.",
|
|
5
5
|
"main": "src/consent.js",
|
|
6
6
|
"repository": {
|
|
@@ -12,5 +12,8 @@
|
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/jarijokinen/consent/issues"
|
|
14
14
|
},
|
|
15
|
-
"homepage": "https://github.com/jarijokinen/consent#readme"
|
|
15
|
+
"homepage": "https://github.com/jarijokinen/consent#readme",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
}
|
|
16
19
|
}
|
package/src/consent.js
CHANGED
|
@@ -19,6 +19,11 @@ export const consent = (options) => {
|
|
|
19
19
|
dialogMessage: 'We would like to get your permission to use cookies for:',
|
|
20
20
|
dialogClass: 'consent',
|
|
21
21
|
settingsLinkSelector: '.consent-settings-link',
|
|
22
|
+
countryCookie: 'cf_country',
|
|
23
|
+
countries: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR',
|
|
24
|
+
'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL',
|
|
25
|
+
'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'IS', 'LI', 'NO',
|
|
26
|
+
'GB', 'CH', 'MC', 'SM', 'VA', 'JE', 'GG', 'IM'],
|
|
22
27
|
...options
|
|
23
28
|
};
|
|
24
29
|
|
|
@@ -33,6 +38,19 @@ export const consent = (options) => {
|
|
|
33
38
|
let dialog = document.createElement('div');
|
|
34
39
|
dialog.classList.add(opts.dialogClass);
|
|
35
40
|
|
|
41
|
+
const detectCountry = () => {
|
|
42
|
+
const country = document.cookie.split('; ').find(r =>
|
|
43
|
+
r.startsWith(opts.countryCookie + '=')
|
|
44
|
+
)?.split('=')[1];
|
|
45
|
+
if (country ? opts.countries.includes(country) : true) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
Object.keys(opts.storages).forEach((storage) => {
|
|
49
|
+
consentState[storage] = 'granted';
|
|
50
|
+
});
|
|
51
|
+
updateConsent();
|
|
52
|
+
};
|
|
53
|
+
|
|
36
54
|
const getConsent = (storage) => {
|
|
37
55
|
return localStorage.getItem('consent_' + storage);
|
|
38
56
|
};
|
|
@@ -150,6 +168,7 @@ export const consent = (options) => {
|
|
|
150
168
|
showDialog();
|
|
151
169
|
};
|
|
152
170
|
|
|
171
|
+
detectCountry();
|
|
153
172
|
loadConsentState();
|
|
154
173
|
createDialog();
|
|
155
174
|
};
|