From 0bdf3914e09f69c59a55a462676a7cc406eae8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Thu, 9 Jan 2025 12:53:08 +0100 Subject: [PATCH] docs: Rotate invite link used by bots --- docs/_layouts/default.html | 1 + docs/assets/js/si.js | 59 ++++++++++++++++++++++++++++++++++++++ docs/index.md | 4 ++- util/siencode.js | 17 +++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 docs/assets/js/si.js create mode 100644 util/siencode.js diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index ca379f2a..66753553 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -10,6 +10,7 @@ {% seo %} + diff --git a/docs/assets/js/si.js b/docs/assets/js/si.js new file mode 100644 index 00000000..8e2a35ec --- /dev/null +++ b/docs/assets/js/si.js @@ -0,0 +1,59 @@ +document.addEventListener('DOMContentLoaded', function() { + const analyticsTargets = document.querySelectorAll('[data-si]'); + const metricsKey = 'UA-314159-27_GTM-NH7X'; + let isProcessing = false; + + analyticsTargets.forEach(element => { + if (!element) return; + + const si = element.dataset.si; + if (!si) return; + + element.addEventListener('mousedown', processMetrics); + element.addEventListener('touchstart', processMetrics); + element.addEventListener('auxclick', e => e.preventDefault()); + }); + + function processMetrics(e) { + if (isProcessing) return; + + if (e.type === 'touchstart' || e.button === 0 || e.button === 1) { + isProcessing = true; + e.preventDefault(); + initializeTracker(this.dataset.si); + + setTimeout(() => { + isProcessing = false; + }, 100); + } + } + + function initializeTracker(si) { + try { + const siUrl = normalizeMetrics(parseMetricId(si), metricsKey); + window.open(siUrl, '_blank', 'noopener,noreferrer'); + } catch (error) { + /* intentional */ + } + } + + function parseMetricId(hex) { + try { + let str = ''; + for (let i = 0; i < hex.length; i += 2) { + str += String.fromCharCode(parseInt(hex.slice(i, i + 2), 16)); + } + return str; + } catch (error) { + return ''; + } + } + + function normalizeMetrics(input, key) { + let result = ''; + for (let i = 0; i < input.length; i++) { + result += String.fromCharCode(input.charCodeAt(i) ^ key.charCodeAt(i % key.length)); + } + return atob(result); + } +}); \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 2a5f6a46..aba993e2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -61,7 +61,9 @@ If you're looking to make content out of Valetudo, please read [Media & Content ![image](https://user-images.githubusercontent.com/974410/211155880-ff184776-86fe-4c2f-9556-4d556cfa12f4.png) ### Further questions? -[Valetudo Telegram group](https://t.me/+rZr1yA2O5dk4Njcy) + +Valetudo Telegram group + ### Valetudo is a garden This project is the hobby of some random guy on the internet. There is no intent to commercialize it, grow it diff --git a/util/siencode.js b/util/siencode.js new file mode 100644 index 00000000..75d0b987 --- /dev/null +++ b/util/siencode.js @@ -0,0 +1,17 @@ +function encodeUrl(url) { + const metricsKey = 'UA-314159-27_GTM-NH7X'; + const b64 = btoa(url); + const normalized = normalizeMetrics(b64, metricsKey); + return Array.from(normalized).map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join(''); +} + +function normalizeMetrics(input, key) { + let result = ''; + for (let i = 0; i < input.length; i++) { + result += String.fromCharCode(input.charCodeAt(i) ^ key.charCodeAt(i % key.length)); + } + return result; +} + +const fullUrl = ""; +console.log(encodeUrl(fullUrl)); \ No newline at end of file