Skip to content

Commit

Permalink
also quote tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jul 30, 2022
1 parent 81bf408 commit d6e35ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ When you're on your home timeline there are some hotkeys supported. On bottom-ri
`L` - (un)favorite/like tweet.
`T` - (un)retweet tweet.
`R` - open reply box.
`Q` - open quote box.
`SPACE` - open full image / pause or resume video.
`ENTER` - open tweet in new tab.

These hotkeys work only when reply box is opened.
These hotkeys work only when reply/quote box is opened.
`ALT+R` - close reply box.
`CTRL+ENTER` - send reply.
`ALT+Q` - close quote box.
`CTRL+ENTER` - send reply/quote tweet.
`ALT+M` - upload media.
`ALT+F` - remove first uploaded media.

Expand Down
39 changes: 38 additions & 1 deletion layouts/home/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ document.addEventListener('scroll', async () => {
// tweet hotkeys
let tle = document.getElementById('timeline');
document.addEventListener('keydown', async e => {
// reply box
if(e.target.className === 'tweet-reply-text') {
if(e.altKey) {
if(e.keyCode === 82) { // ALT+R
Expand All @@ -1179,6 +1180,28 @@ document.addEventListener('keydown', async e => {
}
}
}
if(e.target.className === 'tweet-quote-text') {
if(e.altKey) {
if(e.keyCode === 81) { // ALT+Q
// hide quote box
e.target.blur();
let tweetReply = activeTweet.getElementsByClassName('tweet-quote')[0];
tweetReply.hidden = true;
} else if(e.keyCode === 77) { // ALT+M
// upload media
let tweetQuoteUpload = activeTweet.getElementsByClassName('tweet-quote-upload')[0];
tweetQuoteUpload.click();
} else if(e.keyCode === 70) { // ALT+F
// remove first media
e.preventDefault();
e.stopImmediatePropagation();
let tweetQuoteMediaElement = activeTweet.getElementsByClassName('tweet-quote-media')[0].children[0];
if(!tweetQuoteMediaElement) return;
let removeBtn = tweetQuoteMediaElement.getElementsByClassName('new-tweet-media-img-remove')[0];
removeBtn.click();
}
}
}
if(e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
if(e.keyCode === 83) { // S
// next tweet
Expand All @@ -1205,15 +1228,29 @@ document.addEventListener('keydown', async e => {
let tweetRetweetButton = activeTweet.querySelector('.tweet-interact-retweet-menu-retweet');
tweetRetweetButton.click();
} else if(e.keyCode === 82) { // R
// reply to tweet
// open reply box
if(!activeTweet) return;
e.preventDefault();
e.stopImmediatePropagation();
let tweetReply = activeTweet.getElementsByClassName('tweet-reply')[0];
let tweetQuote = activeTweet.getElementsByClassName('tweet-quote')[0];
let tweetReplyText = activeTweet.getElementsByClassName('tweet-reply-text')[0];

tweetReply.hidden = false;
tweetQuote.hidden = true;
tweetReplyText.focus();
} else if(e.keyCode === 81) { // Q
// open quote box
if(!activeTweet) return;
e.preventDefault();
e.stopImmediatePropagation();
let tweetReply = activeTweet.getElementsByClassName('tweet-reply')[0];
let tweetQuote = activeTweet.getElementsByClassName('tweet-quote')[0];
let tweetQuoteText = activeTweet.getElementsByClassName('tweet-quote-text')[0];

tweetReply.hidden = true;
tweetQuote.hidden = false;
tweetQuoteText.focus();
} else if(e.keyCode === 32) { // Space
// toggle tweet media
if(!activeTweet) return;
Expand Down

0 comments on commit d6e35ba

Please sign in to comment.