// ==UserScript==
// @license MIT
// @name Style forum Black Russia Surgut By J.Washington
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Скрипт для форума Black Russia
// @author J.Washington
// @match https://forum.blackrussia.online/*
// @icon https://example.com/icon.png
// @homepageURL https://example.com/homepage
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @require https://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
fixBlackScreenBug();
} else if (mutation.type === 'attributes') {
fixBlackScreenBug();
}
});
});
const config = {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class']
};
observer.observe(document.body, config);
window.addEventListener('load', () => {
if (window.location.pathname.includes('/members/')) {
return;
}
const posts = document.querySelectorAll('article, .message, .post, .thread');
if (posts.length === 0) {
return;
}
let existingButton = document.querySelector('.copy-button');
if (!existingButton) {
const copyButton = document.createElement('button');
copyButton.textContent = 'Копировать текст';
copyButton.className = 'copy-button';
copyButton.style.position = 'absolute';
copyButton.style.top = '400px';
copyButton.style.left = '245px';
copyButton.style.padding = '10px 20px';
copyButton.style.backgroundColor = '#4CAF50';
copyButton.style.color = 'white';
copyButton.style.border = 'none';
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
copyButton.style.zIndex = '9999';
document.body.appendChild(copyButton);
copyButton.addEventListener('click', () => {
let postText = '';
posts.forEach(post => {
postText += post.innerText + '\n';
});
const textarea = document.createElement('textarea');
textarea.value = postText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
copyButton.textContent = 'Скопировано';
setTimeout(() => {
copyButton.textContent = 'Копировать';
}, 2000);
});
}
});
// Функция для удаления анимации снежинок
function removeSnowflakesAnimation() {
const snowContainer = document.querySelector('.snow-container');
if (snowContainer && snowContainer.parentNode) {
snowContainer.parentNode.removeChild(snowContainer);
}
}
if (localStorage.getItem('snowEnabled') === 'true') {
createSnowflakes();
} else {
removeSnowflakesAnimation();
}
let isEffectActive = localStorage.getItem('isEffectActive') === 'true';
const hoverEffectToggleButton = document.createElement('button');
hoverEffectToggleButton.innerText = isEffectActive ? '✨ Выключить' : '✨ Включить';
hoverEffectToggleButton.style.position = 'fixed';
hoverEffectToggleButton.style.top = '670px';
hoverEffectToggleButton.style.left = '20px';
hoverEffectToggleButton.style.padding = '8px 14px';
hoverEffectToggleButton.style.backgroundColor = '#4CAF50';
hoverEffectToggleButton.style.color = '#fff';
hoverEffectToggleButton.style.border = 'none';
hoverEffectToggleButton.style.borderRadius = '5px';
hoverEffectToggleButton.style.cursor = 'pointer';
hoverEffectToggleButton.style.zIndex = '99999';
hoverEffectToggleButton.style.fontSize = '14px';
hoverEffectToggleButton.style.transition = 'all 0.3s ease';
document.body.appendChild(hoverEffectToggleButton);
let hoverHandlers = [];
function addHoverEffect() {
const elements = document.querySelectorAll('a, .button, .message-cell--user, .message-cell--main');
elements.forEach(element => {
const computedStyle = window.getComputedStyle(element);
let originalBackgroundColor = computedStyle.backgroundColor;
const originalColor = computedStyle.color;
const hoverBackgroundColor =
!originalBackgroundColor || originalBackgroundColor === 'rgba(0, 0, 0, 0)' || originalBackgroundColor === 'transparent'
? '#2c2f33'
: originalBackgroundColor;
element.dataset.originalBackground = originalBackgroundColor;
element.dataset.originalColor = originalColor;
const mouseoverHandler = () => {
element.style.transform = 'scale(1.1)';
element.style.boxShadow = '0 0 20px rgba(255, 255, 255, 0.8)';
element.style.backgroundColor = hoverBackgroundColor;
};
const mouseoutHandler = () => {
element.style.transform = 'scale(1)';
element.style.boxShadow = 'none';
element.style.backgroundColor = element.dataset.originalBackground;
};
element.addEventListener('mouseover', mouseoverHandler);
element.addEventListener('mouseout', mouseoutHandler);
hoverHandlers.push({ element, mouseoverHandler, mouseoutHandler });
});
}
function removeHoverEffect() {
hoverHandlers.forEach(({ element, mouseoverHandler, mouseoutHandler }) => {
element.removeEventListener('mouseover', mouseoverHandler);
element.removeEventListener('mouseout', mouseoutHandler);
element.style.transform = 'scale(1)';
element.style.boxShadow = 'none';
element.style.backgroundColor = element.dataset.originalBackground;
});
hoverHandlers = [];
}
hoverEffectToggleButton.addEventListener('click', () => {
if (isEffectActive) {
removeHoverEffect();
isEffectActive = false;
localStorage.setItem('isEffectActive', 'false');
hoverEffectToggleButton.innerText = '✨ Включить';
} else {
addHoverEffect();
isEffectActive = true;
localStorage.setItem('isEffectActive', 'true');
hoverEffectToggleButton.innerText = '✨ Выключить';
}
});
if (isEffectActive) {
addHoverEffect();
}
let effectsEnabled = localStorage.getItem('effectsEnabled') === 'true';
function createEffects() {
const canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.id = 'effects-canvas';
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '9998';
canvas.style.backgroundColor = 'transparent';
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
const particles = [];
const maxParticles = 100;
function createParticle() {
const size = Math.random() * 5 + 2;
const x = Math.random() * canvas.width;
const y = Math.random() * canvas.height;
const opacity = Math.random() * 0.8 + 0.2;
const speedX = (Math.random() - 0.5) * 2;
const speedY = (Math.random() - 0.5) * 2;
const type = Math.random() < 0.5 ? 'firefly' : 'fog';
return { x, y, size, opacity, speedX, speedY, type };
}
for (let i = 0; i < maxParticles; i++) {
particles.push(createParticle());
}
function drawFirefly(p) {
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255, 255, 255, ${p.opacity})`;
ctx.fill();
}
function drawFog(p) {
const gradient = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 10);
gradient.addColorStop(0, `rgba(255, 255, 255, ${p.opacity * 0.2})`);
gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * 10, 0, Math.PI * 2);
ctx.fill();
}
function drawParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach((p) => {
if (p.type === 'firefly') {
drawFirefly(p);
} else if (p.type === 'fog') {
drawFog(p);
}
p.x += p.speedX;
p.y += p.speedY;
if (p.x < 0 || p.x > canvas.width) p.x = Math.random() * canvas.width;
if (p.y < 0 || p.y > canvas.height) p.y = Math.random() * canvas.height;
if (p.type === 'firefly') {
p.opacity += (Math.random() - 0.5) * 0.02;
p.opacity = Math.min(1, Math.max(0.2, p.opacity));
}
});
requestAnimationFrame(drawParticles);
}
drawParticles();
}
function createButton() {
const button = document.createElement('button');
button.textContent = effectsEnabled ? 'Выключить эффекты' : 'Запустить эффекты';
button.style.position = 'fixed';
button.style.bottom = '20px';
button.style.left = '20px';
button.style.padding = '10px';
button.style.backgroundColor = '#4CAF50';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.style.zIndex = '10000';
button.addEventListener('click', () => {
if (!effectsEnabled) {
createEffects();
effectsEnabled = true;
localStorage.setItem('effectsEnabled', 'true');
button.textContent = 'Выключить эффекты';
} else {
document.getElementById('effects-canvas')?.remove();
effectsEnabled = false;
localStorage.setItem('effectsEnabled', 'false');
button.textContent = 'Запустить эффекты';
}
});
document.body.appendChild(button);
}
if (effectsEnabled) {
createEffects();
}
createButton();
function createSnowflakes() {
if (!document.querySelector('#snowflakes') && document.body) {
const snowflakes = [];
const canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.id = 'snowflakes';
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '9999';
canvas.style.backgroundColor = 'transparent';
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
function createSnowflake() {
const size = Math.random() * 7 + 1;
const speedY = Math.random() * 2 + 1;
const speedX = (Math.random() - 1) * 1;
return { x: Math.random() * window.innerWidth, y: -size, size, speedY, speedX };
}
function updateSnowflakes() {
for (let i = 0; i < snowflakes.length; i++) {
const snowflake = snowflakes[i];
snowflake.y += snowflake.speedY;
snowflake.x += snowflake.speedX;
if (snowflake.y > window.innerHeight) {
snowflakes[i] = createSnowflake();
}
ctx.beginPath();
ctx.arc(snowflake.x, snowflake.y, snowflake.size, 0, Math.PI * 2);
ctx.fillStyle = 'white';
ctx.fill();
ctx.closePath();
}
}
for (let i = 0; i < 200; i++) {
snowflakes.push(createSnowflake());
}
function animate() {
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
updateSnowflakes();
requestAnimationFrame(animate);
}
animate();
}
}
function removeSnowflakes() {
const snowCanvas = document.querySelector('#snowflakes');
if (snowCanvas && snowCanvas.parentNode) {
snowCanvas.parentNode.removeChild(snowCanvas);
}
}
const snowToggleButton = document.createElement('button');
snowToggleButton.innerText = 'Снег ❄️';
snowToggleButton.style.position = 'fixed';
snowToggleButton.style.top = '630px';
snowToggleButton.style.left = '20px';
snowToggleButton.style.padding = '8px 14px';
snowToggleButton.style.backgroundColor = '#4CAF50';
snowToggleButton.style.color = '#fff';
snowToggleButton.style.border = 'none';
snowToggleButton.style.borderRadius = '5px';
snowToggleButton.style.cursor = 'pointer';
snowToggleButton.style.zIndex = '99999';
snowToggleButton.style.fontSize = '14px';
snowToggleButton.style.transition = 'all 0.3s ease';
document.body.appendChild(snowToggleButton);
const snowSound = new Audio('https://zvukipro.com/uploads/files/2021-01/1611814953_forest_winter_birds_calm.mp3');
snowSound.loop = true;
snowToggleButton.addEventListener('mouseover', () => {
snowToggleButton.style.backgroundColor = '#4CAF50';
});
snowToggleButton.addEventListener('mouseout', () => {
snowToggleButton.style.backgroundColor = '#4CAF50';
});
snowToggleButton.addEventListener('click', () => {
if (localStorage.getItem('snowEnabled') === 'true') {
removeSnowflakes();
snowSound.pause();
localStorage.setItem('snowEnabled', 'false');
} else {
createSnowflakes();
snowSound.play();
localStorage.setItem('snowEnabled', 'true');
}
});
if (localStorage.getItem('snowEnabled') === 'true') {
createSnowflakes();
}
function holographicLogoEffect() {
const uixLogo = document.querySelector('a.uix_logo img');
if (!uixLogo) return;
const logoContainer = document.createElement('div');
logoContainer.classList.add('holographic-container');
uixLogo.parentNode.insertBefore(logoContainer, uixLogo);
logoContainer.appendChild(uixLogo);
const holographicStyle = document.createElement('style');
holographicStyle.textContent = `
/* Контейнер для логотипа */
.holographic-container {
position: relative;
display: inline-block;
perspective: 800px; /* Создаем 3D-эффект */
}
/* Логотип внутри контейнера */
.holographic-container img {
display: block;
transform-style: preserve-3d;
animation: holographicSpin 8s infinite linear, colorShift 5s infinite alternate;
transition: transform 0.3s ease;
}
/* Анимация вращения */
@keyframes holographicSpin {
0% { transform: rotateY(0deg) rotateX(0deg); }
100% { transform: rotateY(360deg) rotateX(360deg); }
}
/* Анимация изменения цветов */
@keyframes colorShift {
0% {
filter: hue-rotate(0deg) drop-shadow(0 0 10px rgba(255, 0, 255, 0.7));
}
100% {
filter: hue-rotate(360deg) drop-shadow(0 0 20px rgba(0, 255, 255, 0.7));
}
}
/* При наведении курсора - усиление эффекта */
.holographic-container:hover img {
animation: holographicSpin 4s infinite linear, colorShift 2s infinite alternate;
transform: scale(1.2);
}
`;
document.head.appendChild(holographicStyle);
}
holographicLogoEffect();
function starryBackground() {
// Create canvas for stars
const canvas = document.createElement('canvas');
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.width = '100%';
canvas.style.height = '100%';
canvas.style.zIndex = '-1';
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
const stars = [];
const meteors = [];
let isDarkTheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
for (let i = 0; i < 100; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 2 + 1,
opacity: Math.random(),
});
}
function drawStars() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (isDarkTheme) {
stars.forEach(star => {
ctx.beginPath();
ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255, 255, 255, ${star.opacity * 0.5})`;
ctx.fill();
});
}
}
function animateMeteors() {
if (isDarkTheme && Math.random() < 0.05) {
meteors.push({
x: Math.random() * canvas.width,
y: 0,
length: Math.random() * 100 + 50,
speed: Math.random() * 5 + 2,
angle: Math.random() * Math.PI / 4 - Math.PI / 8,
});
}
meteors.forEach((meteor, index) => {
meteor.x += meteor.speed * Math.cos(meteor.angle);
meteor.y += meteor.speed * Math.sin(meteor.angle);
if (isDarkTheme) {
ctx.beginPath();
ctx.moveTo(meteor.x, meteor.y);
ctx.lineTo(
meteor.x - meteor.length * Math.cos(meteor.angle),
meteor.y - meteor.length * Math.sin(meteor.angle)
);
ctx.strokeStyle = 'rgba(255, 255, 255, 0.7)';
ctx.lineWidth = 2;
ctx.stroke();
}
if (meteor.y > canvas.height || meteor.x > canvas.width || meteor.x < 0) {
meteors.splice(index, 1);
}
});
}
function loop() {
drawStars();
animateMeteors();
requestAnimationFrame(loop);
}
loop();
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
darkModeMediaQuery.addEventListener('change', (e) => {
isDarkTheme = e.matches;
ctx.clearRect(0, 0, canvas.width, canvas.height);
});
}
starryBackground();
function fixBlackScreenBug() {
const elementsToFix = [
document.querySelector('#snowflakes'),
document.getElementById('effects-canvas'),
document.getElementById('cursor-particles')
];
elementsToFix.forEach(el => {
if (el) {
el.style.backgroundColor = 'transparent';
el.style.pointerEvents = 'none';
}
});
document.body.style.backgroundColor = '';
}
let isDarkTheme = localStorage.getItem('isDarkTheme') === 'true';
if (localStorage.getItem('isDarkTheme') === null) {
localStorage.setItem('isDarkTheme', 'false');
isDarkTheme = false;
}
function createThemeSwitcher() {
const themeToggleButton = document.createElement('button');
themeToggleButton.textContent = isDarkTheme ? '🌙 Темная тема' : '☀️ Светлая тема';
themeToggleButton.style.position = 'fixed';
themeToggleButton.style.top = '585px';
themeToggleButton.style.left = '20px';
themeToggleButton.style.padding = '10px 15px';
themeToggleButton.style.backgroundColor = '#4CAF50';
themeToggleButton.style.color = '#fff';
themeToggleButton.style.border = 'none';
themeToggleButton.style.borderRadius = '5px';
themeToggleButton.style.cursor = 'pointer';
themeToggleButton.style.zIndex = '99999';
themeToggleButton.style.fontSize = '14px';
themeToggleButton.style.transition = 'all 0.3s ease';
if (document.body) {
document.body.appendChild(themeToggleButton);
applyTheme(isDarkTheme);
}
themeToggleButton.addEventListener('click', () => {
if (document.body) {
isDarkTheme = !isDarkTheme;
localStorage.setItem('isDarkTheme', isDarkTheme);
applyTheme(isDarkTheme);
themeToggleButton.textContent = isDarkTheme ? '🌙 Темная тема' : '☀️ Светлая тема';
}
});
}
function applyTheme(isDarkTheme) {
fixBlackScreenBug();
const root = document.documentElement;
if (isDarkTheme) {
root.style.setProperty('--background-color', '#121212');
root.style.setProperty('--text-color', '#ffffff');
document.querySelectorAll('*').forEach(el => {
if (!el.closest('button') && !el.closest('.uix_logo')) {
el.style.backgroundColor = '#121212';
el.style.color = '#ffffff';
}
});
} else {
root.style.setProperty('--background-color', '#ffffff');
root.style.setProperty('--text-color', '#000000');
document.querySelectorAll('*').forEach(el => {
if (!el.closest('button') && !el.closest('.uix_logo')) {
el.style.backgroundColor = '';
el.style.color = '';
}
});
}
const logo = document.querySelector('.uix_logo img');
if (logo) {
logo.style.backgroundColor = 'transparent';
}
}
createThemeSwitcher();
applyTheme(isDarkTheme);
function createMagicParticlesWithCursor() {
const particles = [];
const canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.id = 'cursor-particles';
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '9999';
canvas.style.backgroundColor = 'transparent';
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
function createParticle(x, y) {
const size = Math.random() * 3 + 1;
const speedX = (Math.random() - 0.5) * 2;
const speedY = (Math.random() - 0.5) * 2;
const alpha = 1;
const color = `hsl(${Math.random() * 360}, 100%, 70%)`;
return { x, y, size, speedX, speedY, alpha, color };
}
function updateParticles() {
for (let i = 0; i < particles.length; i++) {
const particle = particles[i];
particle.x += particle.speedX;
particle.y += particle.speedY;
particle.alpha -= 0.02;
if (particle.alpha <= 0) {
particles.splice(i, 1);
i--;
}
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(${parseInt(particle.color.slice(4, 7))},${parseInt(particle.color.slice(9, 12))},${parseInt(particle.color.slice(15, 18))},${particle.alpha})`;
ctx.fill();
ctx.closePath();
}
}
document.addEventListener('mousemove', (e) => {
if (localStorage.getItem('particlesEnabled') === 'true') {
for (let i = 0; i < 5; i++) {
particles.push(createParticle(e.clientX, e.clientY));
}
}
});
function animate() {
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
updateParticles();
requestAnimationFrame(animate);
}
animate();
}
const particlesToggleButton = document.createElement('button');
particlesToggleButton.textContent = 'Включить частицы';
particlesToggleButton.style.position = 'fixed';
particlesToggleButton.style.bottom = '63px';
particlesToggleButton.style.left = '20px';
particlesToggleButton.style.padding = '8px 6px';
particlesToggleButton.style.backgroundColor = '#4CAF50';
particlesToggleButton.style.color = 'white';
particlesToggleButton.style.border = 'none';
particlesToggleButton.style.borderRadius = '5px';
particlesToggleButton.style.cursor = 'pointer';
particlesToggleButton.style.zIndex = '10000';
particlesToggleButton.style.fontSize = '14px';
particlesToggleButton.style.transition = 'all 0.3s ease';
document.body.appendChild(particlesToggleButton);
particlesToggleButton.addEventListener('mouseover', () => {
particlesToggleButton.style.backgroundColor = '#45a049';
});
particlesToggleButton.addEventListener('mouseout', () => {
particlesToggleButton.style.backgroundColor = '#4CAF50';
});
particlesToggleButton.addEventListener('click', () => {
if (localStorage.getItem('particlesEnabled') === 'true') {
localStorage.setItem('particlesEnabled', 'false');
particlesToggleButton.textContent = 'Запустить эффекты';
} else {
localStorage.setItem('particlesEnabled', 'true');
createMagicParticlesWithCursor();
particlesToggleButton.textContent = 'Выключить эффекты';
}
});
if (localStorage.getItem('particlesEnabled') === 'true') {
createMagicParticlesWithCursor();
}
const contentWrapper = document.createElement('div');
contentWrapper.style.position = 'absolute';
contentWrapper.style.width = '100%';
contentWrapper.style.height = '100%';
contentWrapper.style.transition = 'opacity 1s cubic-bezier(0.68, -0.55, 0.27, 1.55), transform 1s cubic-bezier(0.68, -0.55, 0.27, 1.55), filter 1s ease';
contentWrapper.style.opacity = '0';
contentWrapper.style.transform = 'scale(0.9) translateY(20px)';
contentWrapper.style.filter = 'blur(10px)';
contentWrapper.style.zIndex = '1';
const allChildren = Array.from(document.body.children);
allChildren.forEach(child => {
if (
child.tagName !== 'BUTTON' &&
child.tagName !== 'INPUT' &&
child.tagName !== 'SELECT' &&
child.tagName !== 'A' &&
child !== contentWrapper
) {
contentWrapper.appendChild(child);
}
});
document.body.appendChild(contentWrapper);
const hideContent = () => {
contentWrapper.style.opacity = '0';
contentWrapper.style.transform = 'scale(0.9) translateY(20px)';
contentWrapper.style.filter = 'blur(10px)';
};
const showContent = () => {
contentWrapper.style.opacity = '1';
contentWrapper.style.transform = 'scale(1) translateY(0)';
contentWrapper.style.filter = 'blur(0px)';
};
window.addEventListener('load', () => {
if (contentWrapper) {
setTimeout(showContent, 100);
}
});
window.addEventListener('beforeunload', () => {
hideContent();
});
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
showContent();
}
});
window.addEventListener('pageshow', (event) => {
if (event.persisted) {
showContent();
}
});
const originalOnLoad = window.onload;
if (typeof originalOnLoad === 'function') {
window.addEventListener('load', originalOnLoad);
}
const originalBeforeUnload = window.onbeforeunload;
if (typeof originalBeforeUnload === 'function') {
window.addEventListener('beforeunload', originalBeforeUnload);
}
let currentInput = '',
operator = '',
previousInput = '',
calculatorVisible = false,
calculator, toggleButton;
function createCalculator() {
const savedState = localStorage.getItem('calculatorVisible');
calculatorVisible = savedState === null ? false : JSON.parse(savedState);
toggleButton = document.createElement('button');
toggleButton.textContent = calculatorVisible ? 'Скрыть калькулятор' : 'Показать калькулятор';
toggleButton.id = 'toggleButton';
toggleButton.style.position = 'fixed';
toggleButton.style.top = '20px';
toggleButton.style.right = '20px';
toggleButton.style.width = '160px';
toggleButton.style.height = '45px';
toggleButton.style.fontSize = '16px';
toggleButton.style.cursor = 'pointer';
toggleButton.style.borderRadius = '5px';
toggleButton.style.zIndex = '10001';
toggleButton.addEventListener('click', toggleCalculator);
document.body.appendChild(toggleButton);
calculator = document.createElement('div');
calculator.style.position = 'absolute';
calculator.style.right = '20px';
calculator.style.top = '80px';
calculator.style.padding = '20px';
calculator.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
calculator.style.color = '#fff';
calculator.style.borderRadius = '8px';
calculator.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.2)';
calculator.style.fontFamily = 'Arial, sans-serif';
calculator.style.zIndex = '10000';
calculator.style.display = calculatorVisible ? 'block' : 'none';
const display = document.createElement('input');
display.type = 'text';
display.id = 'display';
display.disabled = true;
display.style.width = '160px';
display.style.height = '40px';
display.style.fontSize = '20px';
display.style.textAlign = 'right';
display.style.marginBottom = '10px';
display.value = currentInput || '0';
calculator.appendChild(display);
const buttons = [
['7', '8', '9', '/'],
['4', '5', '6', '*'],
['1', '2', '3', '-'],
['0', '.', '+', '=']
];
buttons.forEach((row) => {
const rowDiv = document.createElement('div');
rowDiv.style.marginBottom = '10px';
row.forEach((button) => {
const buttonElement = document.createElement('button');
buttonElement.textContent = button;
buttonElement.style.width = '40px';
buttonElement.style.height = '40px';
buttonElement.style.margin = '5px';
buttonElement.style.fontSize = '16px';
buttonElement.style.cursor = 'pointer';
buttonElement.style.borderRadius = '5px';
buttonElement.addEventListener('click', () => {
if (button === '=') {
calculateResult();
} else if ('0123456789'.includes(button)) {
appendNumber(button);
} else if ('+-/*'.includes(button)) {
appendOperator(button);
} else if (button === 'C') {
clearDisplay();
}
});
rowDiv.appendChild(buttonElement);
});
calculator.appendChild(rowDiv);
});
const deleteButton = document.createElement('button');
deleteButton.textContent = '⌫';
deleteButton.style.width = '40px';
deleteButton.style.height = '40px';
deleteButton.style.margin = '5px';
deleteButton.style.fontSize = '16px';
deleteButton.style.cursor = 'pointer';
deleteButton.style.borderRadius = '5px';
deleteButton.addEventListener('click', deleteLastDigit);
calculator.appendChild(deleteButton);
document.body.appendChild(calculator);
document.addEventListener('keydown', handleKeyPress);
window.addEventListener('scroll', updateCalculatorPosition);
}
function handleKeyPress(event) {
if ('0123456789'.includes(event.key)) {
appendNumber(event.key);
} else if ('+-/*'.includes(event.key)) {
appendOperator(event.key);
} else if (event.key === 'Enter') {
calculateResult();
} else if (event.key === 'Backspace') {
deleteLastDigit();
} else if (event.key === 'Escape') {
clearDisplay();
}
}
function appendNumber(number) {
currentInput += number;
updateDisplay();
}
function appendOperator(op) {
if (currentInput === '') return;
previousInput = currentInput;
operator = op;
currentInput = '';
updateDisplay();
}
function calculateResult() {
let result;
const prev = parseFloat(previousInput);
const current = parseFloat(currentInput);
if (isNaN(prev) || isNaN(current)) return;
switch (operator) {
case '+':
result = prev + current;
break;
case '-':
result = prev - current;
break;
case '*':
result = prev * current;
break;
case '/':
result = current === 0 ? 'Ошибка' : prev / current;
break;
default:
return;
}
currentInput = result.toString();
operator = '';
previousInput = '';
updateDisplay();
}
function updateDisplay() {
const display = document.getElementById('display');
display.value = currentInput || '0';
}
function toggleCalculator() {
if (calculator && toggleButton) {
calculatorVisible = !calculatorVisible;
calculator.style.display = calculatorVisible ? 'block' : 'none';
toggleButton.textContent = calculatorVisible ? 'Скрыть калькулятор' : 'Показать калькулятор';
localStorage.setItem('calculatorVisible', JSON.stringify(calculatorVisible));
}
}
function deleteLastDigit() {
currentInput = currentInput.slice(0, -1) || '0';
updateDisplay();
}
function clearDisplay() {
currentInput = '';
previousInput = '';
operator = '';
updateDisplay();
}
function updateCalculatorPosition() {
const scrollPosition = window.scrollY;
if (calculator) {
calculator.style.top = 80 + scrollPosition + 'px';
}
}
createCalculator();
const vkButton = document.createElement('button');
vkButton.style.position = 'fixed';
vkButton.style.bottom = '750px';
vkButton.style.right = '1460px';
vkButton.style.padding = '10px 20px';
vkButton.style.backgroundColor = '#white';
vkButton.style.border = 'none';
vkButton.style.borderRadius = '5px';
vkButton.style.cursor = 'pointer';
vkButton.style.zIndex = '9999';
const vkLogo = document.createElement('img');
vkLogo.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/VK_Full_Logo_%282021-present%29.svg/414px-VK_Full_Logo_%282021-present%29.svg.png';
vkLogo.style.width = '160px';
vkLogo.style.height = '20px';
vkLogo.style.margin = 'auto';
vkLogo.style.display = 'block';
vkButton.appendChild(vkLogo);
document.body.appendChild(vkButton);
vkButton.addEventListener('click', () => {
window.location.href = 'https://vk.com/im';
});
const element = document.querySelector('.animated-element');
let angle = 0;
function animate() {
angle += 1;
element.style.transform = `rotate(${angle}deg)`;
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
function elementExists(selector) {
return document.querySelector(selector) !== null;
}
function initCustomFunctionality() {
const forumPosts = document.querySelectorAll('.forum-post');
if (forumPosts.length > 0) {
forumPosts.forEach(post => {
post.style.color = '#333';
});
}
}
document.addEventListener('DOMContentLoaded', function() {
if (elementExists('.forum-container')) {
initCustomFunctionality();
}
});
document.addEventListener('click', function(event) {
if (event.target.matches('.custom-button')) {
event.preventDefault();
alert('Кнопка нажата!');
}
});
})();