theonedemon / Netpeak Redmine Usability

// ==UserScript==
// @name         Netpeak Redmine Usability
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       nomedeno.netpeak@gmail.com
// @match        https://redmine.netpeak.net/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  jQuery("head").append(
    '<link ' +
    'href="//cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" ' +
    'rel="stylesheet" type="text/css"/>'
  );

  if (jQuery('.description a.external').length) {
    jQuery('.description a.external').each(function (i, el) {
      jQuery(el).attr('target', '_blank');
    });
  }

  if (jQuery('.description img').length) {
    jQuery('.description img').each(function (i, el) {
      var container = jQuery(document.createElement('a'));
      jQuery(container).attr('data-fancybox', 'description');
      jQuery(container).attr('href', jQuery(el).attr('src'));
      jQuery(container).addClass('fancybox');
      var image = jQuery('<div>').append(jQuery(el).clone()).html();
      jQuery(container).html(image);
      jQuery(el).replaceWith(container);
    });
    //jQuery('.fancybox').fancybox();
  }
  if (jQuery('.journal img').length) {
    jQuery('.journal img').each(function (i, el) {
      var container = jQuery(document.createElement('a'));
      jQuery(container).attr('data-fancybox', 'journal');
      jQuery(container).attr('href', jQuery(el).attr('src'));
      jQuery(container).addClass('fancybox');
      var image = jQuery('<div>').append(jQuery(el).clone()).html();
      jQuery(container).html(image);
      jQuery(el).replaceWith(container);
    });
    //jQuery('.fancybox').fancybox();
  }

  if (jQuery('#time_entry_comments').length) {
    var textbox = jQuery(document.createElement('textarea'));
    jQuery(textbox).attr('id', jQuery('#time_entry_comments').attr('id'));
    jQuery(textbox).attr('name', jQuery('#time_entry_comments').attr('name'));
    jQuery(textbox).attr('rows', 10);
    jQuery(textbox).text(jQuery('#time_entry_comments').val());
    jQuery('#time_entry_comments').replaceWith(textbox);
  }
  if (jQuery('#time_entry_activity_id').length) {
    jQuery('#time_entry_activity_id').val('9');
  }

  var t;

  function replace_select_to_select2() {
    var is_load = false;
    if (jQuery('#issue_custom_field_values_27:visible').length) {
      jQuery('#issue_custom_field_values_27').select2();
      is_load = true;
    }
    if (jQuery('#issue_assigned_to_id:visible').length) {
      jQuery('#issue_assigned_to_id').select2();
      is_load = true;
    }
    if (is_load) {
      clearInterval(t);
    }
  }
  t = setInterval(replace_select_to_select2, 1000);

  jQuery(document).on('change', '#issue_status_id', function () {
    t = setInterval(replace_select_to_select2, 1000);
  });
})();