twitter-click-and-save
twitter-click-and-save copied to clipboard
Could you add a feature to forward images and videos to Telegram groups?
I don't use Telegram, but isn't that a phone messaging app and if you use this script with a script-compatible browser on your phone could you not forward via Twitter's built in share feature where it brings up your phone's modal?
It's not possible to share some data directly to a desktop program from a web page.
The Telegram Desktop is not a UWP application, as well as, it does not support Web Share API. The follow simple approach will not work on a PC:
let imageData = new File(new Uint8Array([0, 1, 2, 3]), "image-name.png", {type: "image/png"});
navigator.share({files: [imageData]});
...although, maybe it will work on a mobile. Are you talked about the desktop version?
However, technically, it's possible to exchange the data between two sites within one browser by using a blob:url as a URL's hash/parameter of an opened link, since browser extensions can bypass the CORS limitation and fetch this data from the passed blob:url.
It will look the follow way:
Instead of downloading of a blob on a Twitter page:
https://github.com/AlttiRi/twitter-click-and-save/blob/d74e7c2d3138fe4b8da46a97c5c24fa2b7be71a0/twitter-click-and-save.user.js#L740
you can open a new tab with Web version of Telegram, with an extra data attached to the opened link after #:
const a = document.createElement("a");
a.href = "https://web.telegram.org/#" + blob;
a.rel = "noreferrer noopener nofollow";
a.target = "_blank";
a.click();
(It will open a link like this: https://web.telegram.org/#blob:https://twitter.com/75bf2116-3171-41e9-bbb9-ef56835ca800)
Then, the other userscript can take the blob url from the browser's location: document.location.hash.slice(1)
download the data (image/video) and do something with it, like sending the data to a channel/group.
!async function demo() {
const blobUrl = document.location.hash.slice(1); // "blob:https://twitter.com/75bf2116-3171-41e9-bbb9-ef56835ca800"
const resp = await GM_fetch(blobUrl); // https://github.com/AlttiRi/gm_fetch#simple-wrapper
const bytes = await resp.arrayBuffer();
// Then do something with it:
console.log(new Uint8Array(bytes));
}();
But it's the work for an other userscript, not for this one. I don't think, that it's a work for few minutes.
Why not just to download the media while you browser Twitter, then manually upload all of them to Telegram by one time?
Mobile Firefox does not support file sharing, only mobile Chrome. But only Firefox allows to install extensions on Android. So it makes no sense to implement it.
You can check it here: https://alttiri.github.io/web-share-demo/
BTW, the uploaded to Telegram image by sharing from Chrome is reduced to 1280 x 853 from original 3000 x 2000.
Although, you can send it as a file by a long tap on the "Send" button, but Chrome does not keep the original name of the file. As well as, the description is missed when you share the image (but not the video).
I think this should be used to complete it https://api.telegram.org/YOUR_BOT_TOKEN/sendMessage?chat_id=YOUR_CHAT_ID&text=${encodeURIComponent(tweetText)}