「@dependabot rebase」をするブックマークレット
やりたいこと
Dependabotへのrebaseのコメントをよくする。いままで手動で打ってきたが、「dependabot」という文字列を間違えずに打つために神経を多少消耗するのでボタン一つでできるようにしたい。 デモ
https://gyazo.com/ec26ea868e185442ce136480c5b860f6
ブックマークレット
code:ブックマークレット
以下が内容。
code:js
(() => {
const textarea = window.new_comment_field;
const text = "@dependabot rebase";
textarea.dispatchEvent(new Event('focus'));
textarea.setRangeText(
text,
textarea.selectionStart || 0,
textarea.selectionEnd || 0,
'end' // Without this, the cursor is either at the beginning or text remains selected
);
textarea.dispatchEvent(new InputEvent('input', {
data: text,
inputType: 'insertText',
isComposing: false // TODO: fix @types/jsdom, this shouldn't be required
}));
const commentBtn = document.querySelector('div.bg-gray-light:nth-child(2) > button:nth-child(1)');
commentBtn.click();
})();
技術的なこと
少しハマったのは、GitHubのコメントはtextareaにfocusしてから入力しないとコメントボタンが押せないところ。 insert-text-textareaのコードを利用した。コメントに参照しているコードを書いている。