Files
background.js
content.css
content.js
manifest.json
popup.css
popup.html
popup.js
Code
7 826
content.js
// Dream state
let dreamActive = false;
let currentWorld = 'nexus';
let intensity = 5;
let randomEventsEnabled = true;
let glitchEnabled = true;
let randomInterval = null;
let glitchInterval = null;
// Initialize on load
chrome.storage.local.get(['dreamActive', 'currentWorld', 'intensity', 'randomEvents', 'glitchFx'], (data) => {
dreamActive = data.dreamActive || false;
currentWorld = data.currentWorld || 'nexus';
intensity = data.intensity || 5;
randomEventsEnabled = data.randomEvents !== false;
glitchEnabled = data.glitchFx !== false;
if (dreamActive) {
activateDream();
}
});
// Listen for messages from popup
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'enableDream') {
dreamActive = true;
activateDream();
} else if (message.action === 'disableDream') {
dreamActive = false;
deactivateDream();
} else if (message.action === 'changeWorld') {
currentWorld = message.world;
if (dreamActive) {
applyWorldEffects();
}
} else if (message.action === 'changeIntensity') {
intensity = message.intensity;
if (dreamActive) {
applyWorldEffects();
}
} else if (message.action === 'toggleRandomEvents') {
randomEventsEnabled = message.enabled;
if (dreamActive) {
if (randomEventsEnabled) {
startRandomEvents();
} else {
stopRandomEvents();
}
}
} else if (message.action === 'toggleGlitch') {
glitchEnabled = message.enabled;
if (dreamActive) {
if (glitchEnabled) {
startGlitchEffects();
} else {
stopGlitchEffects();
}
}
}
sendResponse({ success: true });
return true;
});
function activateDream() {
document.body.classList.add('dream-active');
applyWorldEffects();
if (randomEventsEnabled) {
startRandomEvents();
}
if (glitchEnabled) {
startGlitchEffects();
}
}
function deactivateDream() {
document.body.classList.remove('dream-active');
document.body.removeAttribute('data-dream-world');
document.body.removeAttribute('data-dream-intensity');
stopRandomEvents();
stopGlitchEffects();
// Remove random transformations
document.querySelectorAll('.dream-distorted').forEach(el => {
el.classList.remove('dream-distorted');
el.style.transform = '';
el.style.filter = '';
});
}
function applyWorldEffects() {
document.body.setAttribute('data-dream-world', currentWorld);
document.body.setAttribute('data-dream-intensity', intensity);
}
function startRandomEvents() {
stopRandomEvents();
const baseInterval = 5000;
const intervalTime = baseInterval - (intensity * 300);
randomInterval = setInterval(() => {
randomDistortElement();
}, Math.max(intervalTime, 1000));
}
function stopRandomEvents() {
if (randomInterval) {
clearInterval(randomInterval);
randomInterval = null;
}
}
function startGlitchEffects() {
stopGlitchEffects();
const baseInterval = 8000;
const intervalTime = baseInterval - (intensity * 500);
glitchInterval = setInterval(() => {
applyGlitchEffect();
}, Math.max(intervalTime, 2000));
}
function stopGlitchEffects() {
if (glitchInterval) {
clearInterval(glitchInterval);
glitchInterval = null;
}
}
function randomDistortElement() {
// Get random visible element
const elements = Array.from(document.querySelectorAll('p, h1, h2, h3, img, div, span, a, button'))
.filter(el => {
const rect = el.getBoundingClientRect();
return rect.width > 20 && rect.height > 20 && rect.top < window.innerHeight && rect.bottom > 0;
});
if (elements.length === 0) return;
const element = elements[Math.floor(Math.random() * elements.length)];
const duration = 2000 + Math.random() * 3000;
element.classList.add('dream-distorted');
const transforms = [
`skewX(${(Math.random() - 0.5) * intensity * 2}deg)`,
`skewY(${(Math.random() - 0.5) * intensity * 2}deg)`,
`rotate(${(Math.random() - 0.5) * intensity}deg)`,
`scale(${1 + (Math.random() - 0.5) * intensity * 0.1})`,
`translateX(${(Math.random() - 0.5) * intensity * 3}px)`
];
const filters = [
`hue-rotate(${Math.random() * intensity * 20}deg)`,
`saturate(${100 + (Math.random() - 0.5) * intensity * 30}%)`,
`brightness(${100 + (Math.random() - 0.5) * intensity * 20}%)`
];
element.style.transform = transforms[Math.floor(Math.random() * transforms.length)];
element.style.filter = filters.join(' ');
element.style.transition = `all ${duration}ms ease-in-out`;
// Reset after duration
setTimeout(() => {
element.classList.remove('dream-distorted');
element.style.transform = '';
element.style.filter = '';
}, duration);
}
function applyGlitchEffect() {
document.body.classList.add('dream-glitching');
setTimeout(() => {
document.body.classList.remove('dream-glitching');
}, 300);
}