JiraRoboScript

Jira helper to preselect some fields when creating dialog is shown

2020/04/16のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         JiraRoboScript
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Jira helper to preselect some fields when creating dialog is shown
// @author       Robo
// @homepage     https://greasyfork.org/sk/scripts/400374-jiraroboscript
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @match        https://pmjira.cz.tmo/browse/*
// @grant        none
// ==/UserScript==

(function () {
	'use strict';
	$.noConflict()

	let bodyMutationObserver = new MutationObserver(function (mutations) {
		for (let i = 0; i < mutations.length; i++) { //faster than forEach
			let mutation = mutations[i];
			//console.log(mutation);
			if (mutation.addedNodes.length > 0
					&& (mutation.addedNodes[0].id === "create-issue-dialog" || mutation.addedNodes[0].id === "create-subtask-dialog")) {
				//add inner dialog mutationObserver
				initializeDialogMutationObserver(mutation.addedNodes[0]);
			}
		}
	});

	// Starts listening for changes in the target HTML element of the page.
	let target = document.getElementById('jira');
	bodyMutationObserver.observe(target, {
		childList: true
	});

	function initializeDialogMutationObserver(dialog) {
		 let dialogMutationObserver = new MutationObserver(function (mutations) {
			for (let i = 0; i < mutations.length; i++) { //faster than forEach
				let mutation = mutations[i];
				//console.log(mutation);
				if (mutation.target.className.includes("jira-dialog-content-ready")) {
					//dialog is ready
					//don't disconnect observer, because changing project type cause reload of inner content and dialog panel class change is triggered
					makeMiracle(mutation.target);
					//createMiracleButton(mutation.target);
				}
			}
		});

		dialogMutationObserver.observe(dialog, {
			attributes: true,
			attributeFilter: ["class"]
		});
	}

	jQuery(document).ready(function () {
		//header buttons
		jQuery("header#header div.aui-header-primary ul.aui-nav").append(
			"<li>" +
			"<a class='aui-button aui-button-primary aui-style' title='Create a new TUS' href='http://www.google.com'>Create TUS</a>" +
			"</li>" +
			"<li>" +
			"<a class='aui-button aui-button-primary aui-style' title='Create a new BUS' href='http://www.google.com'>Create BUS</a>" +
			"</li>");
	});

	/*function createMiracleButton(dialog) {
		let dialogHeader = jQuery(dialog).find(".jira-dialog-heading h2");
		if (dialogHeader.find(".miracleButton").length === 0) {
			let miracleButton = jQuery("<a class='aui-button aui-button-primary aui-style miracleButton' title='Prefil form' href='#' style='margin-left:20px;'>Make miracle</a>");
			dialogHeader.append(miracleButton).one("click", makeMiracle);
		}
	}*/

	function makeMiracle(dialog) {
		let dialogContent = jQuery(dialog).find(".jira-dialog-content");
		//        var dialogContent = jQuery("#create-issue-dialog, #create-subtask-dialog").find(".jira-dialog-content");

		//Project type preselect
		let projectTypeAgile = dialogContent.find("label:contains('Agile')").prev();
		if (projectTypeAgile.prop('checked')) {
			return;
		}
		projectTypeAgile.prop('checked', true);

		//Epic preselect
		dialogContent.find("div.aui-field-labelpicker input[role='combobox']").val("OASK - Generic Epic");

		let teamSelect = dialogContent.find("label:contains('Team')").next();

		//Team deleting
		//         teamSelect.find("option").filter(function () {
		//             var optionText = jQuery.trim(jQuery(this).text());
		//             return optionText != "ST_SK - OneApp" && optionText != "ST_SK - One Shop";
		//         }).remove();

		//Team preselect
		teamSelect.val("16135"); //select only ST_SK - One App

		//Team scroll to selected
		setTimeout(function () {
			let optionTop = teamSelect.find("option:selected").offset().top;
			let selectTop = teamSelect.offset().top;
			teamSelect.scrollTop(teamSelect.scrollTop() + (optionTop - selectTop));
		}, 100);

        //Privaccy preselect
        let privacySelect = dialogContent.find("label:contains('Privacy Relevance')").next();
        privacySelect.val("14042"); //select No
	}

})();