asyard / print_jira_card

// ==UserScript==
// @name         print_jira_card
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      MIT
// @description  try to convert jira issues to print-friendly format
// @author       asyard
// @match        http://TYPE_JIRA_ADDRESS_HERE/browse/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';
  XMLHttpRequest.prototype.send = function () {};

  function revertAjaxChanges() {
    $(".icon-edit").detach();
    // uzerine gelince edit yapilabilecek gibi olan alanlar oyle gorunmesin
    $('#priority-val').removeClass('editable-field');
    $('#versions-val').removeClass('editable-field');
    $('#components-val').removeClass('editable-field');
    $('#customfield_10002-val').removeClass('editable-field');
    $('#assignee-val').removeClass('editable-field');
    $('.type-gh-sprint').removeClass('editable-field');
    $('h1').removeClass('editable-field');
    $("a").removeAttr("href").css('cursor', 'text').click(function () {
      return false;
    });
    $("h1").click(function () {
      return false;
    });

    // uzerine tikyalinca edit yapilabilecek alanlar oyle yapamasin
    $("#priority-val").click(function () {
      return false;
    });
    $("#components-val").click(function () {
      return false;
    });
    $("#assignee-val").click(function () {
      return false;
    });
    $("#versions-val").click(function () {
      return false;
    });
    $("#customfield_10002-val").click(function () {
      return false;
    });
    $(".type-gh-sprint").click(function () {
      return false;
    });
    $(".overlay-icon").detach();

    $("a").css('color', 'black');
    $(".icon").css('display', 'none');
    $("strong").filter(function (index) {
      return $(this).text() === "Requirement/s:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Testcase/s:";
    }).parent().parent().detach();

    $(".shortener-expand").mouseenter(function () {
      $(this).css("background-color", "white");
    });
    $(".shortener-expand").mouseleave(function () {
      $(this).css("background-color", "white");
    });

    //$("a:focus, a:hover, a:active").css('text-decoration', 'overline');
    $("a").mouseenter(function () {
      $(this).css("text-decoration", "none");
    });

    $("a").mouseleave(function () {
      $(this).css("text-decoration", "none");
    });

    // tum title attribute lari silelim. Ilgili bilesenin uzerine gelince bir sey gostermesin
    $('[title]').removeAttr("title");
  }

  $(document).ready(function () {
    // reporter-assignee vb uzerine gelince popup gosterimini engellemek icin
    //$("#reporter-val").unbind('mouseenter mouseleave hover'); bu yemedi
    XMLHttpRequest.prototype.send = function () {};

    $("#header").detach();
    $("#details-module_heading").detach();
    $(".command-bar").detach();
    $(".full-width").detach();
    $(".icon-edit").detach();
    $(".status-view").detach();
    $("#addcomment").detach();
    $("#activitymodule").detach();
    $("#attachmentmodule").detach();
    $("#linkingmodule").detach();
    $(".tabs-menu").detach();
    $("#viewissue-devstatus-panel").detach();
    $("#customer-portal-web-panel").detach();
    $("#viewissue-devstatus-panel").detach();
    $("#greenhopper-agile-issue-web-panel").detach();
    $("#viewissue-devstatus-panel").detach();
    $("#bamboo-deployment-projects-right").detach();
    $("#descriptionmodule").detach();
    $("#footer").detach();
    $(".tt_graph").detach();
    $("dt").filter(function (index) {
      return $(this).text() === "Request participants:";
    }).parent().detach();
    $("dt").filter(function (index) {
      return $(this).text() === "Votes:";
    }).parent().detach();
    $("dt").filter(function (index) {
      return $(this).text() === "Watchers:";
    }).parent().detach();
    $("dt").filter(function (index) {
      return $(this).text() === "Resolved:";
    }).parent().detach();

    $("#tt_single_text_remain").parent().detach();
    $("#tt_single_text_spent").parent().detach();

    //$("strong").filter(function(index) { return $(this).text() === "Status:";}).parent().parent().css('display','none');
    $("strong").filter(function (index) {
      return $(this).text() === "Resolution:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Fix Version/s:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Bug Type:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Bug Level:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Privacy:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Task Type:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Task Class:";
    }).parent().parent().detach();
    $("strong").filter(function (index) {
      return $(this).text() === "Requirement/s:";
    }).parent().parent().detach();

    $(".item-right").empty();
    //$(".item-right").append($("#viewissuesidebar"));
    // sag menudekileri ice tasiyalim
    $(".item-right").append($('dt:contains("Created")').parent().parent());
    $(".item-right").append($('dt:contains("Estimated")').parent().parent());
    $("span#reporter-val  .aui-avatar").detach();
    $(".item-right").append($('dt:contains("Reporter")').parent().parent());
    // sag menuyu komple kaldiralim
    $("#viewissuesidebar").detach();

    // saga eklediklerimizde css duzenlemesi yapalim
    $('dt:contains("Created")').css('display', 'inline').css('line-height', '24px');
    $('dd.user-tz').css('display', 'inline');
    $('dt:contains("Estimated")').css('line-height', '24px');
    $('dt:contains("Updated")').css('display', 'inline').css('line-height', '24px');
    $('dt:contains("Reporter")').css('display', 'inline').css('line-height', '24px');
    $('.people-details>dl>dd').css('display', 'inline');

    // son rotuslar
    $("dt.tt_text").css('color', 'black').css('width', '67px');
    $(".dates").css('margin', '0px');
    $("body").css("background", "white");
    $("header").css("background", "white");
    $(".issue-body-content").css("padding", "0 20px 50px");

    // tepeye assignee koyalim
    $(".aui-page-header-inner").append($('span#assignee-val'));
    $('dt:contains("Assignee")').parent().detach();
    $('#assignee-val').css('font-size', '0px').css('float', 'right');
    var imgsrc = $('#assignee-val img').attr("src").replace("size=small&", "");
    $('#assignee-val img').attr("src", imgsrc);
    $("#assignee-val img").css("margin-left", "-10px").css("max-width", "80px").css("max-height", "80px").css("width", "80px").css("height", "80px");

    revertAjaxChanges();

    // bazi alanlar ajax load sonrasi geliyor. Onlari burada detach edelim
    $(document).ajaxComplete(function () {
      revertAjaxChanges();
    });

    //$(document).ajaxSuccess(function() {
    //    revertAjaxChanges();
    //});
    //$(document).ajaxError(function() {
    //    revertAjaxChanges();
    //});

  });

})();