Created
May 24, 2022 01:52
-
-
Save yheihei/1f9b42172eb37bba81d87c3a1557dff6 to your computer and use it in GitHub Desktop.
tampermonkey JIRAタイトルコピー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name JIRA title copy | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @include https://yhei-web-design.atlassian.net/browse/* | |
// @exclude https://yhei-web-design.atlassian.net/browse/*oldIssueView* | |
// @exclude https://yhei-web-design.atlassian.net/browse/*focusedCommentId* | |
// @grant none | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
var $ = window.jQuery; | |
// 子タスクの場合チケットのURLが非同期で更新されるため、setTimeoutで数秒後に初期化する | |
setTimeout(function () { | |
let execCopy = function(string){ | |
let temp = document.createElement('div'); | |
temp.appendChild(document.createElement('pre')).textContent = string; | |
let s = temp.style; | |
s.position = 'fixed'; | |
s.left = '-100%'; | |
document.body.appendChild(temp); | |
document.getSelection().selectAllChildren(temp); | |
let result = document.execCommand('copy'); | |
document.body.removeChild(temp); | |
// true なら実行できている falseなら失敗か対応していないか | |
return result; | |
}; | |
console.log('hoge'); | |
// URLを取得してconsoleに出す | |
var thisUrl = location.href; | |
console.log(thisUrl); | |
var splitUrl = thisUrl.split("/"); | |
console.log(splitUrl); | |
let issueNo = ''; | |
if(splitUrl[4]) { | |
issueNo = splitUrl[4]; | |
if ( issueNo.indexOf('?') != -1) { | |
issueNo = splitUrl[4].split("?")[0]; // クエリストリングを含む場合は除去 | |
} | |
console.log("チケットタイトルコピーボタンを追加します"); | |
let appendClassName2 = "addJsClass_copyName2"; | |
let outputHTML2 = '<div style="position: absolute; top: 240px; right: 15px;">'; | |
//let outputHTML2 = '<div>'; | |
outputHTML2 += '[ <a style="color:#009;" href="#" class="' + appendClassName2 + '">スクラム用書式でコピー</a> ]'; | |
outputHTML2 += "</div>"; | |
// console.error( appendAryLink, outputHTML ); | |
//$("header").after( "<br>" + outputHTML2 ); | |
$("div#jira-frontend").after( "<br>" + outputHTML2 ); | |
let appendClassName2_2 = "addJsClass_copyName2_2"; | |
let outputHTML2_2 = '<div style="position: absolute; top:320px; right: 15px;">'; | |
outputHTML2_2 += '[ <a style="color:#009;" href="#" class="' + appendClassName2_2 + '">スクラム用書式でコピー(URLなし)</a> ]'; | |
outputHTML2_2 += "</div>"; | |
$("div#jira-frontend").after( "<br>" + outputHTML2_2 ); | |
} | |
$(".addJsClass_copyName2").on("click", function(){ | |
// スクラム用書式でコピー | |
var no = issueNo; | |
//var title = $("#summary-val").text(); | |
var title = $("h1:first").text(); | |
console.log(no, title); | |
execCopy( '* ' + `[${no}]` + title.replace(/\s+/g, "").replace(/\r?\n/g, '') + "(" + location.href + ")"); // | |
return false; | |
}); | |
$(".addJsClass_copyName2_2").on("click", function(){ | |
// スクラム用書式でコピー(URLなし) | |
var no = issueNo; | |
//var title = $("#summary-val").text(); | |
var title = $("h1:first").text(); | |
console.log(no, title); | |
execCopy( `[${no}]` + title.replace(/\s+/g, "").replace(/\r?\n/g, '')); // | |
return false; | |
}); | |
}, 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment