1- function getCookie ( name ) {
2- const value = `; ${ document . cookie } ` ;
3- const parts = value . split ( `; ${ name } =` ) ;
4- if ( parts . length === 2 ) return parts . pop ( ) . split ( ';' ) . shift ( ) ;
5- }
1+ // Constants
2+ const CONSENT_KEY = 'deepl_cookie_consent' ;
3+ const CONSENT_ACCEPTED = 'accepted' ;
4+ const CONSENT_REJECTED = 'rejected' ;
65
76const showCookieBanner = ( ) => {
8- // TODO check if this needs to use the same cookie field as deepl.com
9- if ( getCookie ( 'cookie_consent' ) === 'true' ) return ;
7+ // Check localStorage for consent
8+ const consent = localStorage . getItem ( CONSENT_KEY ) ;
9+
10+ // Only hide banner if user has explicitly accepted or rejected
11+ if ( consent === CONSENT_ACCEPTED || consent === CONSENT_REJECTED ) return ;
1012
1113 const banner = document . createElement ( 'div' ) ;
1214 banner . id = 'cookie-banner' ;
13- banner . style . position = 'fixed' ;
14- banner . style . bottom = '0' ;
15- banner . style . left = '0' ;
16- banner . style . width = '100%' ;
17- banner . style . background = '#222' ;
18- banner . style . color = '#fff' ;
19- banner . style . padding = '16px' ;
20- banner . style . display = 'flex' ;
21- banner . style . justifyContent = 'space-between' ;
22- banner . style . alignItems = 'center' ;
23- banner . style . zIndex = '10000' ;
15+
2416 banner . innerHTML = `
25- <span>DeepL uses cookies to deliver its service. Please find more information in our <a href="https://www.deepl.com/privacy" style="color:#4FC3F7;text-decoration:underline;">privacy policy</a>.</span>
26- <button id="cookie-accept" style="background:transparent;color:#fff;padding:8px 16px;border:1px solid #fff;border-radius:4px;cursor:pointer;">Close</button>
17+ <div id="cookie-banner-content">
18+ <p id="cookie-banner-text">
19+ We use cookies and similar technologies to improve your experience and analyze site usage.
20+ By clicking "Accept", you consent to telemetry and analytics.
21+ Learn more in our <a href="https://www.deepl.com/privacy" target="_blank">privacy policy</a>.
22+ </p>
23+ </div>
24+ <div id="cookie-banner-buttons">
25+ <button id="cookie-reject">Reject</button>
26+ <button id="cookie-accept">Accept</button>
27+ </div>
2728 ` ;
2829
2930 document . body . appendChild ( banner ) ;
3031
31- const ONE_YEAR_SECONDS = 60 * 60 * 24 * 365 ;
32+ const acceptBtn = document . getElementById ( 'cookie-accept' ) ;
33+ const rejectBtn = document . getElementById ( 'cookie-reject' ) ;
3234
33- document . getElementById ( 'cookie-accept' ) . onclick = function ( ) {
34- document . cookie = 'cookie_consent=true; path=/; max-age=' + ONE_YEAR_SECONDS ;
35+ acceptBtn . onclick = function ( ) {
36+ localStorage . setItem ( CONSENT_KEY , CONSENT_ACCEPTED ) ;
37+ banner . remove ( ) ;
38+ // Reload to enable telemetry
39+ window . location . reload ( ) ;
40+ } ;
41+
42+ rejectBtn . onclick = function ( ) {
43+ localStorage . setItem ( CONSENT_KEY , CONSENT_REJECTED ) ;
3544 banner . remove ( ) ;
3645 } ;
3746}
38- showCookieBanner ( )
47+
48+ // Show banner when DOM is ready
49+ if ( document . readyState === 'loading' ) {
50+ document . addEventListener ( 'DOMContentLoaded' , showCookieBanner ) ;
51+ } else {
52+ showCookieBanner ( ) ;
53+ }
0 commit comments