WhichFaceIsReal Score Keeper

Test your human identification skills! This script keeps score for you on whichfaceisreal.com since they don't have that built in

当前为 2022-02-19 提交的版本,查看 最新版本

// ==UserScript==
// @name        WhichFaceIsReal Score Keeper
// @namespace   Violentmonkey Scripts
// @namespace2  https://github.com/deltabravozulu
// @match       *://www.whichfaceisreal.com/*
// @grant       none
// @version     4.18
// @author      DeltaBravoZulu
// @description Test your human identification skills! This script keeps score for you on whichfaceisreal.com since they don't have that built in
// @description 2/18/2022, 1:23:53 PM
// @run-at      document-idle
// @license     PayMe
// ==/UserScript==


// Make sure page loads before starting
new MutationObserver(check).observe(document, {
    childList: true,
    subtree: true,
});

function check(changes, observer) {
    if (
        document.querySelector("#bs-example-navbar-collapse-1 > ul > li:nth-child(6)")
    ) {
        observer.disconnect();
        doIt();

    }
}

function doIt() {
    var cor = 0
    var incor = 0
    var correct, corElement = document.querySelector('html>body>div>div>div>p');
    if (corElement != null) {
        correct = document.querySelector('html>body>div>div>div>p').textContent.includes("You are correct")
    } else {
        correct == false;
    }
    var incorrect, incorElement = document.querySelector('html>body>div>div>div>p');
    if (incorElement != null) {
        incorrect = document.querySelector('html>body>div>div>div>p').textContent.includes("You are incorrect")
    } else {
        incorrect == false;
    }



    function corScore() {
        // Get Item from LocalStorage or correctCount === 0
        var correctCount = parseInt(localStorage.getItem('correctCount')) || parseInt(0);

        if (typeof correct !== 'undefined') {
            if (correct == true) {
                cor++
            }
        }
        if (cor > 0) {
            // Set the score to the users' current points 
            correctCount = parseInt(correctCount) + parseInt(cor);
            // Store the score
            localStorage.setItem('correctCount', parseInt(correctCount));
        }

        // Return the high score
        return correctCount;
    }

    function incorScore() {
        // Get Item from LocalStorage or incorrectCount === 0
        var incorrectCount = parseInt(localStorage.getItem('incorrectCount')) || parseInt(0);

        if (incorrect == true) { incor++ }
        if (incor > 0) {
            // Set the score to the users' current points 
            incorrectCount = parseInt(incorrectCount) + parseInt(incor);
            // Store the score
            localStorage.setItem('incorrectCount', parseInt(incorrectCount));
        }

        // Return the high score
        return incorrectCount;
    }



    function getScore() {
        var currentCorScore = parseInt(localStorage.getItem('correctCount'))
        var currentInCorScore = parseInt(localStorage.getItem('incorrectCount'))

        function nukeScore() {
            localStorage.setItem('correctCount', 0)
            localStorage.setItem('incorrectCount', 0)
            document.querySelector("#inject").remove()
            getScore();
        }
        console.log("Correct: " + currentCorScore)
        console.log("Incorrect: " + currentInCorScore)
        htmlInject = '<div id="inject"></div>'
        document.querySelector('body > nav').insertAdjacentHTML('afterend', htmlInject)
        scoreInject = '<div id="score"><center><span class="correct" id="correct" style="color:#137333">&nbsp;&nbsp;Correct: <strong>' + currentCorScore + '</strong></span><span>&nbsp;&#09;&nbsp;&#09;&nbsp;</span><span class="incorrect" id="incorrect" style="color:#B31412"> Incorrect: <strong>' + currentInCorScore + '</strong></span></center></div>'
        document.querySelector('#inject').insertAdjacentHTML('afterbegin', scoreInject)
        buttonInject = '<div><center><button id="resetter" style="font-size:.5em">Reset?</button></center></div>'
        document.querySelector("#score").insertAdjacentHTML('afterend', buttonInject)
        document.getElementById("resetter").addEventListener("click", nukeScore);

    }
    corScore();
    incorScore();
    getScore();
}