User:Tark/Page.js

From Team Fortress Wiki
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function eShowErr(e, time) {
    setTimeout(function () {
        mw.notify(e.text1 || "", {
            autoHide: true,
            tag: e.id,
            title: e.text2 || "",
            autoHideSeconds: "short",
            visibleTimeout: true
        });

        if (e.sound) {
            const errSnd = new Audio(e.sound);
            errSnd.volume = 0.3;
            errSnd.play();
        }
    }, time);
}

function eBird() {
    // Set up
    const d = false;
    const c = d ? "http://tempmedia.localhost/tfwiki/" : "https://cage.espacorede.workers.dev/tfwiki/eggnier/";
    const tap = new Audio(`${c}/se_wm_tap_blackbird.wav`);
    const fly = new Audio(`${c}/se_wm_fly_blackbird.wav`);
    const noise = new Audio(`${c}/se_ui_costume_emblem_noiseloop.wav`);
    const err1 = `${c}/core_92.wav`;
    const err2 = `${c}/core_16.wav`;
    const notifications = [{ text1: "Bird Found", sound: err1, id: "tbcjs" }, { text1: "Bird Found", sound: err2, id: "tbcjs2" }, { text1: "Bird Found", text2: "Alert", sound: err1, id: "tbcjs3" }, { text1: "Alert!", sound: err2, id: "tbcjs4" }, { text1: "Help", sound: err2, id: "tbcjs8" }, { text1: "Error", sound: err1, id: "tbcjs5" }, { text1: "Error", text2: "Warning!", sound: err2, id: "tbcjs6" }, { text1: "Me", sound: err2, id: "tbcjs8" }, { text1: "Bird Found", sound: err2, id: "tbcjs7" }, { text1: "Error", sound: err2, id: "tbcjs2" }, { text1: "This", sound: err2, id: "tbcjs9" }, { text1: "Alert", text2: "Error", sound: err1, id: "tbcjs3" }, { text1: "Found", id: "tbcjs" }, { text1: "You", id: "tbcjs" }, { text1: "An unknown error occurred", id: "tbcjs2" }, { text1: "Mystery", id: "tbcjs4" }, { text1: "An unknown error occurred", id: "tbcjs5" }, { text1: "  ■■■■  ", text2: "Warning!", id: "tbcjs6" }, { text1: "An unknown error occurred", id: "tbcjs" }, { text1: "Data corruption", sound: err2, id: "tbcjs8" }, { text1: "Solve?", sound: err2, id: "tbcjs7" }, { text1: "Unauthorized access", id: "tbcjs9" }, { text1: "Exception", id: "tbcjs4" }, { text1: "Lost signal", sound: err2, id: "tbcjs7" }];
    tap.volume = 0.5;
    fly.volume = 0.5;
    fly.volume = 0.5;

    // Do the thing
    tap.play();
    document.body.classList.add("emil");
    noise.play();
    document.getElementById("footer-poweredbyico").classList.add("emil");
    notifications.forEach(function (n, i) {
        eShowErr(n, i * 150);
    });
    fly.play();

    // Bye
    setTimeout(function () {
        document.body.classList.remove("emil");
        document.getElementById("footer-poweredbyico").removeEventListener("click", eBird);
        noise.pause();
    }, 5500);
};

function initTark() {
    // Divergence
    var fields = ["_minus_", "_empty_", "_0_", "_1_"];
    var field = fields[Math.floor(Math.random() * fields.length)];
    var loopMax = Math.floor(Math.random() * 15) + 5;
    var loops = 0;
    var meterDiv = document.getElementById("tark-div");
    var tubes = meterDiv.getElementsByTagName("i");
    var tubeMap = {
        "-": "minus",
        "+": "plus",
        ".": "dot",
        "?": "qmark",
        ",": "comma"
    };

    function updateTubes(value) {
        for (var i = 2; i < tubes.length; i++) {
            var randomDelay = Math.floor(Math.random() * 200) + 100;
            setTimeout(function (i) {
                if (tubes[i] && value[i - 2]) {
                    var iconClass = tubeMap[value[i - 2]] || "_" + value[i - 2] + "_";
                    tubes[i].className = "dm dm-divmeter-" + iconClass;
                }
            }, randomDelay * (tubes.length - i - 2), i);
        }
    }

    function updateField() {
        tubes[1].className = "dm dm-divmeter-_dot_";

        setTimeout(function () {
            tubes[0].className = "dm dm-divmeter-" + field;
        }, 600);
    }

    var timer = setInterval(function () {
        var randomValue = ("00000" + Math.floor(Math.random() * 999999)).slice(-6);
        updateTubes(randomValue);

        if (loops === loopMax) {
            clearInterval(timer);
            updateField();
            meterDiv.classList.add("end");
        }
        loops++;
    }, 100);

    if (new Date().getUTCDate() === 28) {
        // NE
        document.getElementById("footer-poweredbyico").classList.add("bird");
        document.getElementById("footer-poweredbyico").addEventListener("click", eBird);
    } else if (((day) => day % 9 === 0 ? 9 : day % 9)(new Date().getUTCDate()) === 9) {
        // ZE
        document.body.classList.add("snail");
    }
}

if (mw.config.get("wgUserName")) {
    initTark();
}