DarkPrinceX / Kinky Feed Cleanup

// ==UserScript==
// @name         Kinky Feed Cleanup
// @require      https://raw.github.com/odyniec/MonkeyConfig/master/monkeyconfig.js
// @namespace    http://tampermonkey.net/
// @version      0.1
// @updateURL    https://openuserjs.org/meta/DarkPrinceX/Kinky_Feed_Cleanup.meta.js
// @description  keep your FetLife celebrities from ruining a good thing
// @author       DarkPrinceX, inspired by WhyTrustTomHanks' Kinky Misanthropy script
// @copyright    2018, DarkPrinceX (https://openuserjs.org//users/DarkPrinceX)
// @license      MIT
// @match        *://fetlife.com/*
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_registerMenuCommand
// @grant       GM_addStyle
// ==/UserScript==

var cfg = new MonkeyConfig({
  title: 'Kinky Feed Cleanup Configuration',
  menuCommand: true,
  params: {
    muted_users: {
      type: 'text',
      long: true,
      default: 'TheSquirrel\nTheSensualEar'
    },
    show_loves: {
      type: 'checkbox',
      default: true
    }

  },
  onSave: cleanupGoGo
});

var forbidden_text_with_loves = ["became friends with", "followed", "commented", "responded", "is into", "is curious", "wall", "is going to"]
var forbidden_text_without_loves = ["loved", "became friends with", "followed", "commented", "responded", "is into", "is curious", "wall", "is going to"]

function shouldHide(story, muted_users) {
  var node = story.children('td.story').children('div.brace').children('p.mbn:first');
  if (node.length == 0) {
    node = story.children('td.story').children('div.brace:first');
  }
  var user = node.find('a:first').text();
  var is_muted = false;
  muted_users.forEach(function (u) {
    if (u.trim() == user) {
      is_muted = true;
    }
  });
  if (!is_muted) {
    return false;
  }
  var text = node.contents().not(node.children()).text();
  if (cfg.get('show_loves')) {
    return forbidden_text_with_loves.some(function (s) {
      return text.indexOf(s) !== -1;
    });
  }
  else {
    return forbidden_text_without_loves.some(function (s) {
      return text.indexOf(s) !== -1;
    });
  }
}

function cleanupGoGo() {
  var muted_users = cfg.get('muted_users').split('\n');
  $('#stories').each(function () {
    $(this).find('tr').each(function () {
      if (shouldHide($(this), muted_users)) {
        $(this).css("display", "none");
      }
    });
  });

  $('#mini_feed').each(function () {
    $(this).find('li').each(function () {
      if (shouldHide($(this), muted_users)) {
        $(this).css('display', 'none');
      }
    });
  });
}

$(document).ready(function () {
  cleanupGoGo();
});

var observer = new MutationObserver(function (mutations) {
  mutations.forEach(function (mutation) {
    cleanupGoGo();
  });
});

var observerConfig = {
  attributes: true,
  childList: true,
  subtree: true,
  characterData: true
};

var targetNode = document.body;
observer.observe(targetNode, observerConfig);