Created
March 6, 2018 11:01
-
-
Save arai-ta/9abdc5a3a5ede188b6f28bbe4613e054 to your computer and use it in GitHub Desktop.
chatworkのフィルタ切り替えやフォーカス外しにショートカットを割り当てるUserScript
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 ctrl key shortcut | |
// @namespace http://www.chatwork.com/ | |
// @version 0.2 | |
// @description try to take over the world! | |
// @author arai@chatwork.com | |
// @match https://www.chatwork.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function ctrl_bracket_to_escape(e) { | |
if (e.ctrlKey && e.key == "[") { | |
e.path[0].blur(); | |
} | |
} | |
function ctrl_n_p_navigate(e) { | |
var navi = (function(){ | |
function trim(text) { | |
return text.trim().split(/[ \n]+/)[0].trim(); | |
} | |
function is_current(node) { | |
return trim(node.innerText) == trim(document.getElementById('_selectRoomList').innerText); // FIXME | |
} | |
function list() { | |
return [].concat( | |
Array.prototype.slice.call(document.getElementById('_chatStatusTypeList').children), | |
Array.prototype.slice.call(document.getElementById('_chatCategoryUserList').children), | |
Array.prototype.slice.call(document.getElementById('_chatCategorySystemList').children) // move to last | |
); | |
} | |
function select(callback) { | |
list().some((curr, i, arr) => { | |
// if (curr.className.match(/selected/i)) { | |
if (is_current(curr)) { | |
callback(i, arr); | |
return true; // break | |
} | |
}); | |
} | |
function next() { | |
select((i, arr) => { | |
if (arr[i + 1]) arr[i + 1].click(); | |
}); | |
} | |
function prev() { | |
select((i, arr) => { | |
if (arr[i - 1]) arr[i - 1].click(); | |
}); | |
} | |
return { | |
next: next, | |
prev: prev | |
}; | |
}()); | |
if (e.ctrlKey) { | |
if (e.key == "n") { | |
navi.next(); | |
} else if (e.key == "p") { | |
navi.prev(); | |
} | |
} | |
} | |
function ctrl_m_to_mychat(e) { | |
if (e.ctrlKey && e.key == "m") { | |
document.getElementById('_sideChatMoveMyChat').click(); | |
} | |
} | |
function fix_style() { | |
$('.roomFilterListTooltip__listContainer').css('max-height', "none"); | |
} | |
window.addEventListener("keydown", ctrl_bracket_to_escape); | |
window.addEventListener("keydown", ctrl_n_p_navigate); | |
window.addEventListener("keydown", ctrl_m_to_mychat); | |
fix_style(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
は
return text.trim().split(/[ \n]+/, 1);
は
Array.from(document.querySelectorAll('#_chatStatusTypeList>*'))
とする