|
| 1 | +window.addEventListener("load", function () { |
| 2 | + window.cookieconsent.initialise({ |
| 3 | + palette: { |
| 4 | + popup: { background: "#000" }, |
| 5 | + button: { background: "#f1d600" } |
| 6 | + }, |
| 7 | + type: "opt-in", |
| 8 | + content: { |
| 9 | + message: "We use cookies to enable the AI chatbot on this site. These cookies help protect the chatbot from spam and abuse. By accepting, you can ask questions using the Polkadot AI assistant.", |
| 10 | + dismiss: "Accept", |
| 11 | + deny: "Decline", |
| 12 | + link: "See the Privacy Policy.", |
| 13 | + href: "https://docs.polkadot.com/privacy-policy/" |
| 14 | + }, |
| 15 | + onInitialise: function (status) { |
| 16 | + if (status === 'allow') { |
| 17 | + loadKapaWidget(); |
| 18 | + } else { |
| 19 | + disableKapaWidget(); |
| 20 | + } |
| 21 | + }, |
| 22 | + onStatusChange: function (status) { |
| 23 | + if (status === 'allow') { |
| 24 | + loadKapaWidget(); |
| 25 | + } else { |
| 26 | + disableKapaWidget(); |
| 27 | + } |
| 28 | + }, |
| 29 | + }); |
| 30 | + |
| 31 | + function loadKapaWidget() { |
| 32 | + if (window.kapaWidgetLoaded) return; // prevent multiple loads |
| 33 | + window.kapaWidgetLoaded = true; |
| 34 | + |
| 35 | + const script = document.createElement('script'); |
| 36 | + script.defer = true; |
| 37 | + script.src = 'https://widget.kapa.ai/kapa-widget.bundle.js'; |
| 38 | + |
| 39 | + // replicate all your data-* attributes here: |
| 40 | + script.setAttribute('data-website-id', 'f4bbad14-cc24-471c-8b7d-3267eafc6dc2'); |
| 41 | + script.setAttribute('data-project-name', 'Polkadot'); |
| 42 | + script.setAttribute('data-modal-title', 'Polkadot AI Chatbot'); |
| 43 | + script.setAttribute('data-project-color', '#1E1E1E'); |
| 44 | + script.setAttribute('data-button-bg-color', '#1C0533'); |
| 45 | + script.setAttribute('data-button-text-color', 'white'); |
| 46 | + script.setAttribute('data-button-height', '80px'); |
| 47 | + script.setAttribute('data-button-width', '72px'); |
| 48 | + script.setAttribute('data-font-size-xs', '12px'); |
| 49 | + script.setAttribute('data-font-size-sm', '14px'); |
| 50 | + script.setAttribute('data-font-size-md', '16px'); |
| 51 | + script.setAttribute('data-font-size-lg', '18px'); |
| 52 | + script.setAttribute('data-font-size-xl', '22px'); |
| 53 | + script.setAttribute('data-modal-title-font-size', '22px'); |
| 54 | + script.setAttribute('data-button-text-font-size', '18px'); |
| 55 | + script.setAttribute('data-query-input-font-size', '16px'); |
| 56 | + script.setAttribute('data-button-image-height', '24px'); |
| 57 | + script.setAttribute('data-button-image-width', '24px'); |
| 58 | + script.setAttribute('data-modal-image-height', '24px'); |
| 59 | + script.setAttribute('data-modal-image-width', '24px'); |
| 60 | + script.setAttribute('data-project-logo', 'https://1000logos.net/wp-content/uploads/2022/08/Polkadot-Symbol.png'); |
| 61 | + script.setAttribute('data-modal-header-bg-color', '#1C0533'); |
| 62 | + script.setAttribute('data-modal-title-color', 'white'); |
| 63 | + script.setAttribute('data-modal-disclaimer', `This is an AI chatbot trained to answer questions about Polkadot. As such, the answers it provides might not always be accurate or up-to-date. Please use your best judgement when evaluating its responses. Also, **please refrain from sharing any personal or private information with the bot**. By submitting a query, you agree that you have read and understood [these conditions](https://polkadot.com/legal-disclosures/). |
| 64 | + **If you need further assistance, you can reach out to [Polkadot Support](https://support.polkadot.network/support/tickets/new?ticket_form=i_have_a_support_request).**`); |
| 65 | + script.setAttribute('data-modal-example-questions', 'Where can I store my DOT?, How can I create a DOT account?, How can I stake my DOT?, How does Polkadot OpenGov work?'); |
| 66 | + script.setAttribute('data-modal-disclaimer-font-size', '12px'); |
| 67 | + script.setAttribute('data-search-mode-enabled', 'false'); |
| 68 | + script.setAttribute('data-search-mode-default', 'false'); |
| 69 | + script.setAttribute('data-search-result-primary-title-font-size', '16px'); |
| 70 | + script.setAttribute('data-button-position-top', '120px'); |
| 71 | + script.setAttribute('data-button-position-right', '0px'); |
| 72 | + script.setAttribute('data-user-analytics-cookie-enabled', 'false'); |
| 73 | + |
| 74 | + document.head.appendChild(script); |
| 75 | + } |
| 76 | + |
| 77 | + function disableKapaWidget() { |
| 78 | + // Remove the container if it exists |
| 79 | + const container = document.getElementById('kapa-widget-container'); |
| 80 | + if (container) container.remove(); |
| 81 | + |
| 82 | + // Also, remove the Kapa script tag if needed |
| 83 | + const scripts = document.querySelectorAll('script[src="https://widget.kapa.ai/kapa-widget.bundle.js"]'); |
| 84 | + scripts.forEach(script => script.remove()); |
| 85 | + |
| 86 | + // Reset flag so widget can be reloaded later if needed |
| 87 | + window.kapaWidgetLoaded = false; |
| 88 | + } |
| 89 | + |
| 90 | +}); |
0 commit comments