(function () {
  'use strict';

  var IMG = '/assets/ctrluu.webp';

  var DETECT_DEVTOOLS = true;

  function showImage() {
    try { window.location.href = IMG; } catch (e) { /* abaikan */ }
  }

  document.addEventListener('contextmenu', function (e) {
    e.preventDefault();
    return false;
  }, true);

  function keyHandler(e) {
    var key = (e.key || '').toLowerCase();
    var code = e.keyCode || e.which;

    if (e.key === 'F12' || code === 123) {
      e.preventDefault();
      showImage();
      return false;
    }

    if (e.ctrlKey && (key === 'u' || code === 85)) {
      e.preventDefault();
      showImage();
      return false;
    }

    if (e.ctrlKey && (key === 's' || key === 'p' || code === 83 || code === 80)) {
      e.preventDefault();
      return false;
    }

    if (e.ctrlKey && e.shiftKey && (key === 'i' || key === 'j' || key === 'c' ||
        code === 73 || code === 74 || code === 67)) {
      e.preventDefault();
      showImage();
      return false;
    }

    if (e.metaKey && e.altKey && (key === 'i' || key === 'j' || key === 'c')) {
      e.preventDefault();
      showImage();
      return false;
    }

    if (e.metaKey && (key === 'u')) {
      e.preventDefault();
      showImage();
      return false;
    }
    if (e.metaKey && (key === 's')) {
      e.preventDefault();
      return false;
    }
  }

  window.addEventListener('keydown', keyHandler, true);
  document.addEventListener('keydown', keyHandler, true);
  document.addEventListener('keyup', function (e) {

    var key = (e.key || '').toLowerCase();
    if ((e.ctrlKey || e.metaKey) && (key === 'u' || (e.keyCode || e.which) === 85)) {
      e.preventDefault();
      showImage();
      return false;
    }
  }, true);

  if (DETECT_DEVTOOLS) {
    var fired = false;
    function caught() {
      if (fired) return;
      fired = true;
      showImage();
    }
    setInterval(function () {
      var t0 = (window.performance && performance.now) ? performance.now() : Date.now();

      debugger;
      var dt = ((window.performance && performance.now) ? performance.now() : Date.now()) - t0;
      if (dt > 200) caught();
    }, 1000);
  }
})();
