OkCupid Utils

Unblurs those who like you on OkCupid, add keybinds for easy navigation

/*
 * Change CSS property - Userscript
 * Copyright (c) 2023, kelo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


// ==UserScript==
// @name        OkCupid Utils
// @match       https://www.okcupid.com/*
// @grant       none
// @version     1.1
// @author      kelo & Asafff
// @license BSD
// @description Unblurs those who like you on OkCupid, add keybinds for easy navigation
// @namespace https://greasyfork.org/users/1090195
// ==/UserScript==



(function() {
    'use strict';
    function waitForElementToDisplay(selector, time) {
        if(document.querySelector(selector)!=null) {
            removePaywallClickEvent();
            hideElement();
            changeFilterProperty();
            allowOverflow();
            return;
        }
        else {
            setTimeout(function() {
                waitForElementToDisplay(selector, time);
            }, time);
        }
    }
    /* Who Likes Unblur*/
    function changeFilterProperty(){
        let elements = document.querySelectorAll(".usercard-placeholder-thumb");

        elements.forEach(function(element) {
            element.style.filter = "none";
        });
    }

    function allowOverflow() {
        let usercardElem = document.querySelector('.usercard-placeholder');
        let parent = usercardElem.parentElement
        let grandparent = parent.parentElement

        // Remove fading gradient
        parent.style.width = '81.5%'
        parent.style.zIndex = 0

        // Allow overflow
        grandparent.style.height = '100%'
        grandparent.style.maxHeight = '100%'
    }

    function hideElement() {
        let elementToHide = document.querySelector(".likes-you-paywall-explainer-cta");

        if(elementToHide) {
            elementToHide.style.display = "none";
        }
    }

    function removePaywallClickEvent() {
        const elementToReplace = document.querySelector('.likes-you-paywall-with-likes-link');

        if (elementToReplace) {
            const newDiv = document.createElement('div');
            newDiv.innerHTML = elementToReplace.innerHTML;
            elementToReplace.parentNode.replaceChild(newDiv, elementToReplace);
        }
    }

    /* Navigation keybind */
    let keyPressHandler = (ctx) => {
        let passBtn = document.querySelector('button.dt-action-buttons-button.pass');
        let likeBtn = document.querySelector('button.dt-action-buttons-button.like');
        let picturesPrev = document.querySelector('button.sliding-pagination-button.prev');
        let picturesNext = document.querySelector('button.sliding-pagination-button.next');
        let picSliderDiv = document.querySelector('div.sliding-pagination-inner-content');

        switch(ctx.code) {
            case 'KeyX':
                passBtn.click();
                break;
            case 'KeyV':
                likeBtn.click();
                break;
            case 'ArrowRight':
            case 'KeyF':
                if (picturesNext) {
                    picturesNext.click();
                }
                break;
            case 'ArrowLeft':
            case 'KeyD':
                if (picturesPrev) {
                    picturesPrev.click();
                }
                break;
            case 'Space':
                picSliderDiv.firstChild.click();
                break;
            default:
                break;
        }
    };
    document.addEventListener('keydown', keyPressHandler);

    waitForElementToDisplay(".userrows-main", 4000);
})();