kompisn90 / Camdevils.com link directly to cam

// ==UserScript==
// @name            Camdevils.com link directly to cam
// @description     Makes the links to performers on Camdevils.com link directly to the performer, or their profile, without going to the Camdevils.com presentation-and-embed-site.
// @version         1.0.1
// @grant           none
// @license         MIT
// @copyright       2018, kompisn90 (https://openuserjs.org/users/kompisn90)
// @include         https://camdevils.com/*
// ==/UserScript==

// ==OpenUserJS==
// @author kompisn90
// ==/OpenUserJS==

const urlRules = {
  streamate: 'https://streamate.com/cam/',
  chaturbate: 'https://chaturbate.com/',
  bongacams: 'https://bongacams.com/',
  livejasmin: 'http://www.livejasmin.com/en/chat/',
  xlovecam: 'https://www.xlovecam.com/en/model/',
}

document.body.addEventListener('mousedown', e => {
  let target = e.target
  if (target.src) {
    target = target.parentNode
  }
  if (target.href.match(/\/sites\/[a-z]+\/[a-zA-Z0-9_]+/)) {
    let url = target.href.split('/sites/')[1]
    url = url.split('/')
    url = urlRules[url[0]] + url[1]
    target.dataset.url = target.href
    target.href = url
  }
})

document.body.addEventListener('mouseup', e => {
  let target = e.target
  if (target.src) {
    target = target.parentNode
  }
  if (target.dataset.url) {
    setTimeout(() => {
      target.href = target.dataset.url
    }, 0)
  }
})