MediaWiki:Common.js: Difference between revisions

From PsychoactiveWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
                 format: 'json'
                 format: 'json'
             }).done(function (data) {
             }).done(function (data) {
                 // FIX: MediaWiki stores wikitext under ['*']
                 // MediaWiki stores wikitext under ['*']
                 textbox.value = data.parse.wikitext['*'];
                 textbox.value = data.parse.wikitext['*'];
             });
             });
Line 26: Line 26:
});
});


//aesthetic
// ==========================
// Aesthetic – Psychedelic 70s frame (with saved state)
// ==========================
/* Psychedelic 70s frame – dark mode + white text */
mw.loader.using('jquery', function () {
    var body = document.body;
    var STORAGE_KEY = 'psy70-frame-state'; // 'on' or 'off'


/*********************************
    // Turn on the theme base class
* 70s Prog / Psych Sunburst BG
    body.classList.add('psy70');
*********************************/


:root {
    // Restore saved on/off state from localStorage (default: ON)
     --prog70s-bg: #050009;
     var storedState = null;
     --prog70s-color-a: #ff9a00;
     try {
     --prog70s-color-b: #ff005c;
        storedState = window.localStorage.getItem(STORAGE_KEY);
    --prog70s-color-c: #7b5cff;
     } catch (e) {
     --prog70s-color-d: #00f0ff;
        // localStorage not available (privacy mode, etc.) – ignore
}
     }


/* Turned on from Common.js */
    if (storedState === 'off') {
body.prog70s-bg {
        body.classList.add('psy70-off');
    background: var(--prog70s-bg);
     }
     color: #f5f5f5;
    overflow-x: hidden;
}


/* Content card styling so background peeks around edges */
    // Grain overlay element
body.prog70s-bg #content,
    var grain = document.createElement('div');
body.prog70s-bg .mw-body {
     grain.id = 'psy70-grain';
    background: rgba(6, 3, 22, 0.92);
     body.appendChild(grain);
     border-radius: 14px;
     box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 30px 80px rgba(0, 0, 0, 0.9);
}


/* Keep header areas clean-ish */
    // Color palettes with 70s prog/psych vibes
body.prog70s-bg #mw-page-base,
    var palettes = [
body.prog70s-bg #mw-head-base {
        {
    background: transparent;
            name: 'Sunburst',
}
            a: '#ff9a00',
            b: '#ff005c',
            c: '#7b5cff',
            d: '#00f0ff'
        },
        {
            name: 'Pastoral',
            a: '#ffb347',
            b: '#ff6a88',
            c: '#48c6ef',
            d: '#3fffa8'
        },
        {
            name: 'Cosmic',
            a: '#ff4b1f',
            b: '#1fddff',
            c: '#7f00ff',
            d: '#ffe000'
        },
        {
            name: 'Acid',
            a: '#fdfc47',
            b: '#24fe41',
            c: '#ff00aa',
            d: '#ff5f6d'
        }
    ];


/* Rotating conic sunburst – big 70s record/poster vibe */
    function applyPalette(p) {
body.prog70s-bg::before {
        var root = document.documentElement;
    content: "";
        root.style.setProperty('--psy70-color-a', p.a);
    position: fixed;
        root.style.setProperty('--psy70-color-b', p.b);
    inset: -40vh;
        root.style.setProperty('--psy70-color-c', p.c);
    z-index: -2;
        root.style.setProperty('--psy70-color-d', p.d);
     pointer-events: none;
     }


     background:
     // Start with a random palette
        radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.9), transparent 60%),
    var index = Math.floor(Math.random() * palettes.length);
        conic-gradient(
    applyPalette(palettes[index]);
            from 0deg,
            var(--prog70s-color-a) 0deg,
            var(--prog70s-color-b) 45deg,
            var(--prog70s-color-c) 90deg,
            var(--prog70s-color-d) 135deg,
            var(--prog70s-color-a) 180deg,
            var(--prog70s-color-b) 225deg,
            var(--prog70s-color-c) 270deg,
            var(--prog70s-color-d) 315deg,
            var(--prog70s-color-a) 360deg
        );


     filter: blur(1px) saturate(1.3);
     // Slowly rotate palettes
    mix-blend-mode: screen;
    window.setInterval(function () {
     animation: prog70s-spin 80s linear infinite;
        index = (index + 1) % palettes.length;
    opacity: 0.85;
        applyPalette(palettes[index]);
}
     }, 70000); // ~70 seconds per switch


/* Horizontal psychedelic bands that drift + shimmer */
    // Toggle button
body.prog70s-bg::after {
    var $btn = $('<button>', {
    content: "";
        id: 'psy70-toggle',
    position: fixed;
        text: 'Psy Frame: On'
    inset: -20vh;
     });
    z-index: -1;
     pointer-events: none;


     background-image:
     function updateButton() {
        linear-gradient(
        if (body.classList.contains('psy70-off')) {
            0deg,
             $btn.text('Psy Frame: Off');
            rgba(0, 0, 0, 0.85),
         } else {
            rgba(0, 0, 0, 0.4),
            $btn.text('Psy Frame: On');
            rgba(0, 0, 0, 0.85)
         }
        ),
        repeating-linear-gradient(
            0deg,
            var(--prog70s-color-a) 0,
            var(--prog70s-color-a) 15px,
             var(--prog70s-color-b) 15px,
            var(--prog70s-color-b) 30px,
            var(--prog70s-color-c) 30px,
            var(--prog70s-color-c) 45px,
            var(--prog70s-color-d) 45px,
            var(--prog70s-color-d) 60px
        );
 
    background-size: 100% 100%, 100% 260%;
    mix-blend-mode: screen;
    animation:
         prog70s-bands-shift 55s ease-in-out infinite alternate,
        prog70s-bands-wobble 18s ease-in-out infinite alternate;
    opacity: 0.9;
}
 
/* “Off” state when user toggles it */
body.prog70s-bg.prog70s-off::before,
body.prog70s-bg.prog70s-off::after {
    opacity: 0;
    transition: opacity 0.6s ease-out;
}
 
/* Slight color shift when off to keep the page readable */
body.prog70s-bg.prog70s-off {
    background: #050009;
}
 
/* Rotating record / sunburst */
@keyframes prog70s-spin {
    0% {
        transform: rotate(0deg) scale(1.05);
    }
    50% {
         transform: rotate(180deg) scale(1.08);
    }
    100% {
        transform: rotate(360deg) scale(1.05);
     }
     }
}


/* Bands sliding up and down */
     $btn.on('click', function () {
@keyframes prog70s-bands-shift {
         body.classList.toggle('psy70-off');
     0% {
        background-position: 0 0, 0 0;
    }
    100% {
         background-position: 0 0, 0 -200%;
    }
}


/* Gentle wobble like a warped LP */
        // Save new state
@keyframes prog70s-bands-wobble {
        try {
    0% {
            if (body.classList.contains('psy70-off')) {
        transform: translate3d(0, 0, 0) skewY(0deg);
                window.localStorage.setItem(STORAGE_KEY, 'off');
        filter: hue-rotate(0deg);
            } else {
    }
                window.localStorage.setItem(STORAGE_KEY, 'on');
    50% {
            }
        transform: translate3d(0, -1.5%, 0) skewY(1.2deg);
         } catch (e) {
        filter: hue-rotate(25deg);
            // Ignore if localStorage fails
    }
        }
    100% {
        transform: translate3d(0, 1.5%, 0) skewY(-1.2deg);
         filter: hue-rotate(50deg);
    }
}


/* Optional: grain overlay for extra analog feel */
        updateButton();
body.prog70s-bg #prog70s-grain {
     });
    pointer-events: none;
    position: fixed;
    inset: -20vh;
    z-index: -1;
    opacity: 0.12;
    mix-blend-mode: soft-light;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.9'/%3E%3C/svg%3E");
     background-size: 160px 160px;
}


/* Toggle button */
     $('body').append($btn);
#prog70s-toggle {
     updateButton();
    position: fixed;
});
    right: 1.4rem;
    bottom: 1.4rem;
    z-index: 2000;
 
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
     border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
 
    background: radial-gradient(circle at 0% 0%, rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.85));
     color: #ffe8ff;
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
 
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.9),
        0 0 25px rgba(255, 0, 150, 0.4);
    backdrop-filter: blur(5px);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
 
#prog70s-toggle:hover {
    transform: translateY(-1px);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.9),
        0 0 35px rgba(0, 240, 255, 0.6);
}

Latest revision as of 08:13, 27 November 2025

/* Any JavaScript here will be loaded for all users on every page load. */

// Auto-preload template for Shared_Experiences new story form
mw.hook('wikipage.content').add(function () {
    // Only run on new-section add
    if (
        mw.config.get('wgPageName') === 'Shared_Experiences' &&
        mw.config.get('wgAction') === 'edit' &&
        new URLSearchParams(window.location.search).get('section') === 'new'
    ) {
        var textbox = document.getElementById('wpTextbox1');

        // Only insert if the textbox is empty
        if (textbox && textbox.value.trim() === '') {
            new mw.Api().get({
                action: 'parse',
                page: 'Template:SharedExperience/Preload',
                prop: 'wikitext',
                format: 'json'
            }).done(function (data) {
                // MediaWiki stores wikitext under ['*']
                textbox.value = data.parse.wikitext['*'];
            });
        }
    }
});

// ==========================
// Aesthetic – Psychedelic 70s frame (with saved state)
// ==========================
/* Psychedelic 70s frame – dark mode + white text */
mw.loader.using('jquery', function () {
    var body = document.body;
    var STORAGE_KEY = 'psy70-frame-state'; // 'on' or 'off'

    // Turn on the theme base class
    body.classList.add('psy70');

    // Restore saved on/off state from localStorage (default: ON)
    var storedState = null;
    try {
        storedState = window.localStorage.getItem(STORAGE_KEY);
    } catch (e) {
        // localStorage not available (privacy mode, etc.) – ignore
    }

    if (storedState === 'off') {
        body.classList.add('psy70-off');
    }

    // Grain overlay element
    var grain = document.createElement('div');
    grain.id = 'psy70-grain';
    body.appendChild(grain);

    // Color palettes with 70s prog/psych vibes
    var palettes = [
        {
            name: 'Sunburst',
            a: '#ff9a00',
            b: '#ff005c',
            c: '#7b5cff',
            d: '#00f0ff'
        },
        {
            name: 'Pastoral',
            a: '#ffb347',
            b: '#ff6a88',
            c: '#48c6ef',
            d: '#3fffa8'
        },
        {
            name: 'Cosmic',
            a: '#ff4b1f',
            b: '#1fddff',
            c: '#7f00ff',
            d: '#ffe000'
        },
        {
            name: 'Acid',
            a: '#fdfc47',
            b: '#24fe41',
            c: '#ff00aa',
            d: '#ff5f6d'
        }
    ];

    function applyPalette(p) {
        var root = document.documentElement;
        root.style.setProperty('--psy70-color-a', p.a);
        root.style.setProperty('--psy70-color-b', p.b);
        root.style.setProperty('--psy70-color-c', p.c);
        root.style.setProperty('--psy70-color-d', p.d);
    }

    // Start with a random palette
    var index = Math.floor(Math.random() * palettes.length);
    applyPalette(palettes[index]);

    // Slowly rotate palettes
    window.setInterval(function () {
        index = (index + 1) % palettes.length;
        applyPalette(palettes[index]);
    }, 70000); // ~70 seconds per switch

    // Toggle button
    var $btn = $('<button>', {
        id: 'psy70-toggle',
        text: 'Psy Frame: On'
    });

    function updateButton() {
        if (body.classList.contains('psy70-off')) {
            $btn.text('Psy Frame: Off');
        } else {
            $btn.text('Psy Frame: On');
        }
    }

    $btn.on('click', function () {
        body.classList.toggle('psy70-off');

        // Save new state
        try {
            if (body.classList.contains('psy70-off')) {
                window.localStorage.setItem(STORAGE_KEY, 'off');
            } else {
                window.localStorage.setItem(STORAGE_KEY, 'on');
            }
        } catch (e) {
            // Ignore if localStorage fails
        }

        updateButton();
    });

    $('body').append($btn);
    updateButton();
});