brobada / My HSC JIRA Tweaks

// ==UserScript==
// @name         My HSC JIRA Tweaks
// @version      0.15
// @description  My HSC JIRA Tweaks
// @author       Obada Kadri
// @match        *://jira.oraclecorp.com/jira/secure/RapidBoard.jspa*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

var COLS_TO_SHOW = 4;

// Create the "Hide Inactive Columns" button
var note = document.createTextNode("Toggle Inactive Columns");
var btn = document.createElement('button');
btn.className += " hide-inactive-columns";
btn.addEventListener("click", toggleHideActive);
btn.appendChild(note);
document.querySelector("body#jira").appendChild(btn);
var currentStateIsHidden = false;

function toggleHideActive() {
  currentStateIsHidden = !currentStateIsHidden;
  Array.from(document.querySelectorAll("ul#ghx-column-headers .ghx-column")).forEach((cl, i) => {
    if (i >= COLS_TO_SHOW) {
      cl.style.display = currentStateIsHidden ? "none" : "table-cell";
    }
  });
  Array.from(document.querySelectorAll("ul.ghx-columns")).forEach(cls => {
    Array.from(cls.querySelectorAll("li.ghx-column")).forEach((cl, i) => {
      if (i < COLS_TO_SHOW) {
        $("ul.ghx-columns li.ghx-column").sortable(currentStateIsHidden ? "disable" : "enable");
      }
      else {
        cl.style.display = currentStateIsHidden ? "none" : "table-cell";
      }
    });
  });
}

// Styling Stuff
var bm_css_src = `
button.hide-inactive-columns {
    position: fixed;
    bottom: 0;
    right: 5em;
    color: #fff;
    background-color: #d9534f;
    border-color: #d43f3a;
    display: inline-block;
    padding: 3px 6px;
    margin-bottom: 0;
    font-size: 11px;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -ms-touch-action: manipulation;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 5px 5px 0 0;
    z-index: 999;
}

`;
GM_addStyle(bm_css_src);