Last active
December 10, 2015 22:08
-
-
Save azu/4499689 to your computer and use it in GitHub Desktop.
Redmineのチケット作成時に担当者を自分にして、バージョンはプロジェクト毎に前回選択したもの記憶する
This file contains hidden or 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 Redmine new Tickets | |
// @version 1.0 | |
// @namespace http://efcl.info/ | |
// @author azu | |
// @description Redmineのチケット作成時に担当者を自分にして、バージョンはプロジェクト毎に前回選択したもの記憶する | |
// @include http://redmine.your.domain/projects/*/issues/new* | |
// @run-at document-end | |
// ==/UserScript== | |
(function(){ | |
function isProjectID(element, index, array){ | |
if (element.length === 0){ | |
return; | |
} | |
var idx = [ | |
"projects", | |
"issues", | |
"new" | |
].indexOf(element); | |
if (idx !== -1){ | |
return; | |
} | |
return element; | |
} | |
var projectID = location.pathname.split("/").filter(isProjectID); | |
var userID = document.querySelector("#loggedas > a").href.split("/").pop(); | |
(function main(){ | |
setSelectEvent(); | |
selectVersionOptionByPrev(); | |
selectOwnerOption(userID); | |
})(); | |
function setSelectEvent(){ | |
var selectTag = document.getElementById("issue_fixed_version_id"); | |
selectTag.addEventListener('change', function(evt){ | |
var selectTag = evt.target; | |
var selectedIndex = selectTag.selectedIndex; | |
var selectOption = selectTag[selectedIndex]; | |
var selectValue = selectOption.value; | |
if (selectValue){ | |
GM_setValue(projectID, parseInt(selectValue, 10)); | |
} | |
}, false); | |
} | |
function selectOwnerOption(userID){ | |
var optionsElements = document.querySelectorAll("#issue_assigned_to_id > option"); | |
if (optionsElements.length === 0){ | |
return; | |
} | |
var options = [].slice.call(optionsElements) | |
var matchOptionTags = options.filter(function(element, index, array){ | |
if (element.value == userID){ | |
return element; | |
} | |
}); | |
// ない場合は終了 | |
if (matchOptionTags.length <= 0){ | |
return; | |
} | |
// あるなら選択する | |
var selectOption = matchOptionTags[0]; | |
selectOption.selected = true; | |
} | |
function selectVersionOptionByPrev(){ | |
// 保存するキーはプロジェクト毎に異なる | |
var savedOptionValue = GM_getValue(projectID, false); | |
// 保存した値が無いならセットはしない | |
if (!savedOptionValue){ | |
return; | |
} | |
var optionsElements = document.querySelectorAll("#issue_fixed_version_id > option"); | |
if (optionsElements.length === 0){ | |
return; | |
} | |
var options = [].slice.call(optionsElements) | |
var matchOptionTags = options.filter(function(element, index, array){ | |
if (element.value == savedOptionValue){ | |
return element; | |
} | |
}); | |
// ない場合は終了 | |
if (matchOptionTags.length <= 0){ | |
return; | |
} | |
// あるなら選択する | |
var selectOption = matchOptionTags[0]; | |
selectOption.selected = true; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment