Raw Source
magma / okc-filter-likes

// ==UserScript==
// @name        okc-filter-likes
// @description Unmatch any user that has liked you based on keywords found in their profile.
// @copyright   2021, Ben Tucker (https://github.com/bentucker)
// @license     MIT
// @homepageURL https://github.com/bentucker/okc-filter-likes
// @updateURL   https://openuserjs.org/meta/magma/okc-filter-likes.user.js
// @downloadURL https://github.com/bentucker/okc-filter-likes/raw/main/okc-filter-likes.user.js
// @author      Ben Tucker
// @version     1.2
// @namespace   https://github.com/bentucker
// @compatibile firefox
// @match       https://www.okcupid.com/who-likes-you
// @grant       none
// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==

// ==OpenUserJS==
// @author magma
// ==/OpenUserJS==

(function() {
  "use strict";
  const profileMatcher = "div.incoming-likes-voting-list > div > div > div.card-with-actions > div > a";
  var opInt;
  var fpInt;
  var likeIdx = 0;
  var openAttempts = 0;

  $(window).keydown(function(e){
    if (e.which == 27){
      // stop filtering if 'esc' is pressed
      stop();
    } else if (e.ctrlKey && e.key === 'f') {
      // filter current profile if 'ctrl-f' is pressed
      console.log("Checking if profile matches preferences ...")
      fpInt = setInterval(filterunfit, 1500);
    } else if (e.key === 's') {
      // start filtering if 's' is pressed
      start();
    }
  });

  var stop = function() {
    console.log("Stopping who-likes-you filtering ...");
    clearInterval(opInt);
    clearInterval(fpInt);
  };
  
  var start = function() {
    console.log("Starting to filter users that like you based on your preferences ...");
    clearInterval(opInt);
    opInt = setInterval(openProfile, 1500);
  }

  var openProfile = function() {
    clearInterval(fpInt);

    console.log("Opening like #" + likeIdx);
    openAttempts++;
    let nextCard = jQuery(profileMatcher).get(likeIdx);

    if (nextCard != undefined) {
      openAttempts = 0;
      clearInterval(opInt);
      nextCard.click();
      fpInt = setInterval(
        function() {
          filterunfit();
          opInt = setInterval(openProfile, 1500);
        }, 1500);
    } else {
      if (openAttempts > 2) {
        stop();
        return;
      }
      window.scrollTo(0, 0);
      window.scrollBy(0, likeIdx * 306);
    }
  };
  
  const cardMatcher = ".matchprofile-details-text";
  const rejectSelector = "button.pill-button > div.pass-pill-button-inner";
  const mustHave = new Array("woman");
  const block = new Array("smokes cigarettes", "overweight", "full figured", "curvy", "a little extra", "queer", "trans", "transfeminine", "transgender", "transsexual", "nonconforming", "genderqueer", "pansexual", "demisexual", "questioning", "asexual", "heteroflexible", "gay", "lesbian", "homoflexible", "vegetarian", "vegan", "acab", "blm", "black lives matter");
  var rejectButton = null;
  var url = null;

  var filterunfit = function() {
    clearInterval(opInt);
    
    var plaintext = "";
    var blockreason = "";
    jQuery(cardMatcher).each(function(element) {
        plaintext += this.innerText.toLowerCase();
    });

    if (plaintext == "") {
        return;
    }

    block.forEach(function(element) {
        blockreason += plaintext.includes(element) ? "+" + element : "";
    });

    mustHave.forEach(function(element) {
        blockreason += !plaintext.includes(element) ? "-" + element + "," : "";
    });

    if (blockreason != "") {
      clearInterval(fpInt);
      var url = $(".cardsummary-profile-link > a");
      if (url.length > 0 && url[0].attributes.length > 0) {
          url = this.origin + url[0].attributes[0].value;
      }
      console.log("Filtered: [" + blockreason + "] " + url);
      var rejButton = $(rejectSelector)[0];
      if (rejButton != undefined) {
        rejButton.click();
      }
    } else {
      clearInterval(fpInt);
      likeIdx += 1;
      window.history.back();
    }
  };
})();