Skip to content

Commit

Permalink
docs: Rotate invite link used by bots
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jan 9, 2025
1 parent f795e2e commit 0bdf391
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

{% seo %}
<link rel="stylesheet" href="{{ "/assets/css/style.css?v=" | append: site.github.build_revision | relative_url }}">
<script src="{{ "/assets/js/si.js?v=" | append: site.github.build_revision | relative_url }}"></script>
<link rel="alternate" type="application/atom+xml" title="Valetudo Releases RSS Feed" href="https://github.com/Hypfer/Valetudo/releases.atom" />

</head>
Expand Down
59 changes: 59 additions & 0 deletions docs/assets/js/si.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<a href="https://t.me/+F00lFE1NVUc2NTAy" data-si="34097f03527c7c0375540b07132a652161373c7b0d3b031c6a640d4556614159600b09351b1c087d">Valetudo Telegram group</a>


### Valetudo is a garden <a id="garden"></a>
This project is the hobby of some random guy on the internet. There is no intent to commercialize it, grow it
Expand Down
17 changes: 17 additions & 0 deletions util/siencode.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 0bdf391

Please sign in to comment.