// ==UserScript== // @name ZenHub Toggle Meta // @version 0.1.5 // @description Toggle pipeline issue meta data (labels) // @license https://creativecommons.org/licenses/by-sa/4.0/ // @namespace http://github.com/Mottie // @include https://github.com/* // @grant GM_addStyle // @run-at document-idle // @author Rob Garrison >> http://github.com/Mottie // @updateURL https://raw.githubusercontent.com/Mottie/Zenhub-userscripts/master/zenhub-toggle-meta.user.js // @downloadURL https://raw.githubusercontent.com/Mottie/Zenhub-userscripts/master/zenhub-toggle-meta.user.js // ==/UserScript== /* global GM_addStyle */ /* jshint esnext:true, unused:true */ (() => { "use strict"; let busy = false, isVisible = true, $style = document.createElement("style"), markup = ` `; function addButton() { // set busy flag to ignore DOMNodeInserted firing while adding new content busy = true; let el, ref = $(".zhc-search-bar"); // look for ZenHub pipeline if (ref && !$("#zhu-toggle-meta-button")) { el = document.createElement("div"); el.id = "zhu-toggle-meta"; el.className = "zhc-tooltip zhc-tooltip--top"; el.innerHTML = markup; ref.parentNode.insertBefore(el, ref); el.addEventListener("click", () => { isVisible = !isVisible; toggleLabels(); document.activeElement.blur(); }); } busy = false; } function toggleLabels() { let button = $("#zhu-toggle-meta-button"); if (isVisible) { button.classList.add("zhc-toggle-button--is-active"); $style.disabled = true; } else { button.classList.remove("zhc-toggle-button--is-active"); $style.disabled = false; } } function $(selector) { return document.querySelector(selector); } function init() { GM_addStyle(` #zhu-toggle-meta-button .zhc-icon { padding-top: 2px; } #zhu-toggle-meta-button svg { color: #000; } `); document.body.appendChild($style); $style.textContent = ".zhc-issue-card__meta { display: none; }"; $style.disabled = true; document.body.addEventListener("DOMNodeInserted", () => { if (!busy && $(".zh-board")) { addButton(); } }); } // initialize if ZenHub active if ($(".zhio, .zhe")) { init(); } })();