Skip to content

Commit

Permalink
copy hotkey & fixesw
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jul 31, 2022
1 parent 233692c commit 512ee2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Active tweet hotkeys. On bottom-right of tweet element there's blue dot showing
`T` - (un)retweet tweet.
`R` - open reply box.
`Q` - open quote box.
`C` - copy tweet image.
`SPACE` - open full image / pause or resume video.
`ENTER` - open tweet in new tab.

Expand Down
28 changes: 24 additions & 4 deletions layouts/home/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,7 @@ setTimeout(() => {
if(e.keyCode === 82) { // ALT+R
// hide reply box
e.target.blur();
let tweetReply = activeTweet.getElementsByClassName('tweet-reply')[0];
tweetReply.hidden = true;
activeTweet.getElementsByClassName('tweet-interact-reply')[0].click();
} else if(e.keyCode === 77) { // ALT+M
// upload media
let tweetReplyUpload = activeTweet.getElementsByClassName('tweet-reply-upload')[0];
Expand All @@ -1207,8 +1206,7 @@ setTimeout(() => {
if(e.keyCode === 81) { // ALT+Q
// hide quote box
e.target.blur();
let tweetReply = activeTweet.getElementsByClassName('tweet-quote')[0];
tweetReply.hidden = true;
activeTweet.getElementsByClassName('tweet-interact-retweet')[0].click();
} else if(e.keyCode === 77) { // ALT+M
// upload media
let tweetQuoteUpload = activeTweet.getElementsByClassName('tweet-quote-upload')[0];
Expand Down Expand Up @@ -1299,6 +1297,28 @@ setTimeout(() => {
e.target.click();
activeTweet.getElementsByClassName('tweet-interact-more-menu-copy')[0].focus();
}
} else if(e.keyCode === 67 && !e.ctrlKey && !e.altKey) { // C
// copy image
if(e.target.className.includes('tweet tweet-id-')) {
if(!activeTweet) return;
let media = activeTweet.getElementsByClassName('tweet-media')[0];
if(!media) return;
media = media.children[0];
if(!media) return;
if(media.tagName === "IMG") {
let img = media;
let canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
let ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
canvas.toBlob((blob) => {
navigator.clipboard.write([
new ClipboardItem({ "image/png": blob })
]);
}, "image/png");
}
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Old Twitter Layout (2022)",
"description": "A new extension that returns old Twitter's look.",
"version": "1.3.3",
"version": "1.3.4",
"manifest_version": 3,
"homepage_url": "https://github.com/dimdenGD/OldTwitter",
"background": {
Expand Down

0 comments on commit 512ee2a

Please sign in to comment.