diff --git a/README.md b/README.md index 7e48a698..80b88a43 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/layouts/home/script.js b/layouts/home/script.js index 4e5e5b05..ee0f6fc9 100644 --- a/layouts/home/script.js +++ b/layouts/home/script.js @@ -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]; @@ -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]; @@ -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"); + } + } } }); } diff --git a/manifest.json b/manifest.json index 7e7feb88..ba369f42 100644 --- a/manifest.json +++ b/manifest.json @@ -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": {