Skip to content

Instantly share code, notes, and snippets.

@fujimogn
Created November 30, 2024 08:09
Show Gist options
  • Save fujimogn/72b79c678807631b5bae0fd8fad01184 to your computer and use it in GitHub Desktop.
Save fujimogn/72b79c678807631b5bae0fd8fad01184 to your computer and use it in GitHub Desktop.
freee - ファイルボックス(ファイル詳細) - カスタムショートカット
// ==UserScript==
// @name freee - ファイルボックス(ファイル詳細) - カスタムショートカット
// @namespace https:// miraius.co.jp
// @version 1.2.0
// @description freeeのファイルボックス(ファイル詳細)でカスタムショートカットを有効にする
// @author fujimogn
// @match https://secure.freee.co.jp/receipts/*
// @icon https://www.google.com/s2/favicons?domain=freee.co.jp
// @require http://cdn.craig.is/js/mousetrap/mousetrap.min.js?9d308
// @grant none
// ==/UserScript==
(function () {
'use strict';
const Mousetrap = window.Mousetrap;
/**
* 指定されたセレクターの要素をクリックする関数
* @param {string} selector
*/
const clickElement = (selector) => {
const element = document.querySelector(selector);
if (element) {
element.click();
}
};
/**
* 指定されたセレクターの要素をクリックし、遅延後に次の要素をクリックする関数
* @param {string} initialSelector
* @param {string} delayedSelector
* @param {number} delayMs
*/
const clickWithDelay = (initialSelector, delayedSelector, delayMs = 500) => {
const element = document.querySelector(initialSelector);
if (element) {
element.click();
setTimeout(() => {
console.log(`Wait ${delayMs / 1000} sec`);
clickElement(delayedSelector);
}, delayMs);
}
};
// "前へ"
Mousetrap.bind([',', '<', 'left'], () => {
clickElement('[aria-label="前のファイルへ移動"]');
});
// "次へ"
Mousetrap.bind(['.', '>', 'right'], () => {
clickElement('[aria-label="次のファイルへ移動"]');
});
// "既存の取引に添付"
Mousetrap.bind(['+'], () => {
clickWithDelay('[data-test="deals-tab"]', '.vb-button[data-test="attach-deal-link"]');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment