Skip to content

Instantly share code, notes, and snippets.

@kotobukid
Created May 8, 2024 06:32
Show Gist options
  • Save kotobukid/279e0ec5694546b2a68d3eda8befd4c8 to your computer and use it in GitHub Desktop.
Save kotobukid/279e0ec5694546b2a68d3eda8befd4c8 to your computer and use it in GitHub Desktop.
Redmine右上の検索欄に数値を入れたときにチケットにダイレクトジャンプしてしまう問題を回避する微ハック
// ==UserScript==
// @name Redmine query trick
// @namespace http://tampermonkey.net/
// @version 2024-05-08
// @description try to take over the world!
// @author You
// @match http://example.com/*
// @icon
// @grant none
// ==/UserScript==
(function() {
'use strict';
const initialize = ($element, next) => {
$element.setAttribute('type', 'text');
$element.setAttribute('size', '20');
$element.setAttribute('class', 'small');
$element.setAttribute('autocomplete', 'off');
$element.setAttribute('style', `
height: 24px;
box-sizing: border-box;
vertical-align: middle;
margin-right: 5px;
border: 1px solid #ccc;
border-radius: 3px;`);
if (next) {
return next($element);
} else {
return $element;
}
};
const $word_query = initialize(document.createElement('input'), ($e) => {
$e.setAttribute('placeholder', '非ダイレクト');
$e.setAttribute('style', `${$e.getAttribute('style')} width: 130px; background-color: lightblue;`);
$e.addEventListener('change', (e) => {
e.preventDefault();
const value = e.target.value;
// const current_value = $q.value;
// $q.value = [current_value, `${value} ${value}`].join(' ');
$q.value = `${value} ${value}`;
$q.parentElement.submit();
});
return $e;
});
const $ticket_direct = initialize(document.createElement('input'), ($e) => {
$e.setAttribute('placeholder', 'チケットNo.');
$e.setAttribute('style', `${$e.getAttribute('style')} width: 60px; background-color: #d2ffd2;`);
$e.addEventListener('change', (e) => {
e.preventDefault();
const id = e.target.value.replace(/\D/g, '');
location.assign(`${document.location.origin}/issues/${id}`);
});
return $e;
});
const $q = document.getElementById('q');
$q.setAttribute('style', 'display: none;');
$q.parentElement.appendChild($word_query);
$q.parentElement.appendChild($ticket_direct);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment