mirror of
https://github.com/rustdesk/doc.rustdesk.com.git
synced 2026-10-23 08:30:30 +00:00
287 lines
10 KiB
Plaintext
287 lines
10 KiB
Plaintext
---
|
|
import { UI } from 'astrowind:config';
|
|
---
|
|
|
|
<script is:inline define:vars={{ defaultTheme: UI.theme }}>
|
|
if (window.basic_script) {
|
|
return;
|
|
}
|
|
|
|
window.basic_script = true;
|
|
|
|
function applyTheme(theme) {
|
|
if (theme === 'dark') {
|
|
document.documentElement.classList.add('dark');
|
|
} else {
|
|
document.documentElement.classList.remove('dark');
|
|
}
|
|
}
|
|
|
|
const initTheme = function () {
|
|
if ((defaultTheme && defaultTheme.endsWith(':only')) || (!localStorage.theme && defaultTheme !== 'system')) {
|
|
applyTheme(defaultTheme.replace(':only', ''));
|
|
} else if (
|
|
localStorage.theme === 'dark' ||
|
|
(!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
) {
|
|
applyTheme('dark');
|
|
} else {
|
|
applyTheme('light');
|
|
}
|
|
};
|
|
initTheme();
|
|
|
|
function attachEvent(selector, event, fn) {
|
|
const matches = typeof selector === 'string' ? document.querySelectorAll(selector) : selector;
|
|
if (matches && matches.length) {
|
|
matches.forEach((elem) => {
|
|
elem.addEventListener(event, (e) => fn(e, elem), false);
|
|
});
|
|
}
|
|
}
|
|
|
|
const onLoad = function () {
|
|
let lastKnownScrollPosition = window.scrollY;
|
|
let ticking = true;
|
|
|
|
attachEvent('#languageSelect', 'click', function () {
|
|
document.getElementById('languages')?.classList.remove('hidden');
|
|
});
|
|
|
|
/*
|
|
attachEvent('#languages', 'mouseleave', function () {
|
|
document.getElementById('languages')?.classList.add('hidden');
|
|
});
|
|
*/
|
|
|
|
document.addEventListener('click', function (event) {
|
|
const languagesDropdown = document.getElementById('languages');
|
|
const languageSelect = document.getElementById('languageSelect');
|
|
if (languagesDropdown && !languagesDropdown.contains(event.target) && !languageSelect.contains(event.target)) {
|
|
languagesDropdown.classList.add('hidden');
|
|
}
|
|
});
|
|
|
|
attachEvent('#header nav', 'click', function () {
|
|
document.querySelector('[data-aw-toggle-menu]')?.classList.remove('expanded');
|
|
document.body.classList.remove('overflow-hidden');
|
|
document.getElementById('header')?.classList.remove('h-screen');
|
|
document.getElementById('header')?.classList.remove('expanded');
|
|
document.getElementById('header')?.classList.remove('bg-page');
|
|
document.querySelector('#header nav')?.classList.add('hidden');
|
|
document.querySelector('#header > div > div:last-child')?.classList.add('hidden');
|
|
});
|
|
|
|
attachEvent('[data-aw-toggle-menu]', 'click', function (_, elem) {
|
|
elem.classList.toggle('expanded');
|
|
document.getElementById('languages')?.classList.toggle('expanded');
|
|
document.body.classList.toggle('overflow-hidden');
|
|
document.getElementById('header')?.classList.toggle('h-screen');
|
|
document.getElementById('header')?.classList.toggle('expanded');
|
|
document.getElementById('header')?.classList.toggle('bg-page');
|
|
document.querySelector('#header nav')?.classList.toggle('hidden');
|
|
document.querySelector('#header > div > div:last-child')?.classList.toggle('hidden');
|
|
});
|
|
|
|
attachEvent('[data-aw-toggle-color-scheme]', 'click', function () {
|
|
if (defaultTheme.endsWith(':only')) {
|
|
return;
|
|
}
|
|
document.documentElement.classList.toggle('dark');
|
|
localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
|
|
});
|
|
|
|
attachEvent('[data-aw-social-share]', 'click', function (_, elem) {
|
|
const network = elem.getAttribute('data-aw-social-share');
|
|
const url = encodeURIComponent(elem.getAttribute('data-aw-url'));
|
|
const text = encodeURIComponent(elem.getAttribute('data-aw-text'));
|
|
|
|
let href;
|
|
switch (network) {
|
|
case 'facebook':
|
|
href = `https://www.facebook.com/sharer.php?u=${url}`;
|
|
break;
|
|
case 'twitter':
|
|
href = `https://twitter.com/intent/tweet?url=${url}&text=${text}`;
|
|
break;
|
|
case 'linkedin':
|
|
href = `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${text}`;
|
|
break;
|
|
case 'whatsapp':
|
|
href = `https://wa.me/?text=${text}%20${url}`;
|
|
break;
|
|
case 'mail':
|
|
href = `mailto:?subject=%22${text}%22&body=${text}%20${url}`;
|
|
break;
|
|
|
|
default:
|
|
return;
|
|
}
|
|
|
|
const newlink = document.createElement('a');
|
|
newlink.target = '_blank';
|
|
newlink.href = href;
|
|
newlink.click();
|
|
});
|
|
|
|
const screenSize = window.matchMedia('(max-width: 767px)');
|
|
screenSize.addEventListener('change', function () {
|
|
document.querySelector('[data-aw-toggle-menu]')?.classList.remove('expanded');
|
|
document.body.classList.remove('overflow-hidden');
|
|
document.getElementById('header')?.classList.remove('h-screen');
|
|
document.getElementById('header')?.classList.remove('expanded');
|
|
document.getElementById('header')?.classList.remove('bg-page');
|
|
document.querySelector('#header nav')?.classList.add('hidden');
|
|
document.querySelector('#header > div > div:last-child')?.classList.add('hidden');
|
|
});
|
|
|
|
function applyHeaderStylesOnScroll() {
|
|
const header = document.querySelector('#header[data-aw-sticky-header]');
|
|
if (!header) return;
|
|
if (lastKnownScrollPosition > 60 && !header.classList.contains('scroll')) {
|
|
header.classList.add('scroll');
|
|
} else if (lastKnownScrollPosition <= 60 && header.classList.contains('scroll')) {
|
|
header.classList.remove('scroll');
|
|
}
|
|
ticking = false;
|
|
}
|
|
applyHeaderStylesOnScroll();
|
|
|
|
attachEvent([document], 'scroll', function () {
|
|
lastKnownScrollPosition = window.scrollY;
|
|
|
|
if (!ticking) {
|
|
window.requestAnimationFrame(() => {
|
|
applyHeaderStylesOnScroll();
|
|
});
|
|
ticking = true;
|
|
}
|
|
});
|
|
};
|
|
const onPageShow = function () {
|
|
document.documentElement.classList.add('motion-safe:scroll-smooth');
|
|
const elem = document.querySelector('[data-aw-toggle-menu]');
|
|
if (elem) {
|
|
elem.classList.remove('expanded');
|
|
}
|
|
document.body.classList.remove('overflow-hidden');
|
|
document.getElementById('header')?.classList.remove('h-screen');
|
|
document.getElementById('header')?.classList.remove('expanded');
|
|
document.querySelector('#header nav')?.classList.add('hidden');
|
|
};
|
|
|
|
window.onload = onLoad;
|
|
window.onpageshow = onPageShow;
|
|
|
|
document.addEventListener('astro:after-swap', () => {
|
|
initTheme();
|
|
onLoad();
|
|
onPageShow();
|
|
loadPrice();
|
|
});
|
|
|
|
function loadPrice() {
|
|
if (!document.getElementById('users')) return;
|
|
let users = 10;
|
|
let devices = 100;
|
|
window.submit = function () {
|
|
redirectUrl =
|
|
'https://rustdesk.com/api/lic/stripe/checkout?type=Customized&users=' + users + '&devices=' + devices;
|
|
gotoBuy(redirectUrl);
|
|
};
|
|
function calculatePrice() {
|
|
users = parseInt(document.getElementById('users').value);
|
|
devices = parseInt(document.getElementById('devices').value);
|
|
if (!users || users < 10) users = 10;
|
|
if (devices < 100) devices = 100;
|
|
const price = 19.9 + (Math.min(users, devices) - 10) + (Math.max(devices, users) - 100) * 0.1;
|
|
document.getElementById('cprice').innerText = price.toFixed(price >= 100 ? 1 : 2);
|
|
}
|
|
|
|
document.getElementById('users').oninput = function () {
|
|
document.getElementById('usersSlider').value = this.value;
|
|
calculatePrice();
|
|
};
|
|
|
|
document.getElementById('devices').oninput = function () {
|
|
document.getElementById('devicesSlider').value = this.value;
|
|
calculatePrice();
|
|
};
|
|
|
|
document.getElementById('usersSlider').oninput = function () {
|
|
document.getElementById('users').value = this.value;
|
|
calculatePrice();
|
|
};
|
|
|
|
document.getElementById('devicesSlider').oninput = function () {
|
|
document.getElementById('devices').value = this.value;
|
|
calculatePrice();
|
|
};
|
|
|
|
let users2 = 10;
|
|
let devices2 = 100;
|
|
let conns = 1;
|
|
window.submit2 = function () {
|
|
redirectUrl =
|
|
'https://rustdesk.com/api/lic/stripe/checkout?type=Customized&users=' +
|
|
users2 +
|
|
'&devices=' +
|
|
devices2 +
|
|
'&conns=' +
|
|
conns;
|
|
gotoBuy(redirectUrl);
|
|
};
|
|
function calculatePrice2() {
|
|
users2 = parseInt(document.getElementById('users2').value);
|
|
devices2 = parseInt(document.getElementById('devices2').value);
|
|
conns = parseInt(document.getElementById('conns').value);
|
|
if (!users2 || users2 < 10) users2 = 10;
|
|
if (devices2 < 100) devices2 = 100;
|
|
if (conns < 1) conns = 1;
|
|
const price = 19.9 + (Math.min(users2, devices2) - 10) + (Math.max(devices2, users2) - 100) * 0.1 + (conns - 1) * 20;
|
|
document.getElementById('cprice2').innerText = price.toFixed(price >= 100 ? 1 : 2);
|
|
}
|
|
|
|
if (window.location.href.indexOf('custom2') > 0) {
|
|
setTimeout(function () {
|
|
window.location = '#custom2';
|
|
}, 150);
|
|
} else {
|
|
setTimeout(function () {
|
|
document.getElementById('custom2').parentElement.parentElement.parentElement.style.display = 'none';
|
|
}, 0);
|
|
}
|
|
|
|
document.getElementById('users2').oninput = function () {
|
|
document.getElementById('usersSlider2').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
|
|
document.getElementById('devices2').oninput = function () {
|
|
document.getElementById('devicesSlider2').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
|
|
document.getElementById('conns').oninput = function () {
|
|
document.getElementById('connsSlider').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
|
|
document.getElementById('usersSlider2').oninput = function () {
|
|
document.getElementById('users2').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
|
|
document.getElementById('devicesSlider2').oninput = function () {
|
|
document.getElementById('devices2').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
|
|
document.getElementById('connsSlider').oninput = function () {
|
|
document.getElementById('conns').value = this.value;
|
|
calculatePrice2();
|
|
};
|
|
}
|
|
document.addEventListener('DOMContentLoaded', loadPrice);
|
|
</script>
|