Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you add a feature to forward images and videos to Telegram groups? #29

Open
srsman opened this issue Jul 19, 2023 · 4 comments
Open

Comments

@srsman
Copy link

srsman commented Jul 19, 2023

No description provided.

@biggestsonicfan
Copy link

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?

@AlttiRi
Copy link
Owner

AlttiRi commented Jul 20, 2023

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:

downloadBlob(blob, filename, url);

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?

@AlttiRi
Copy link
Owner

AlttiRi commented Jul 21, 2023

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).

@srsman
Copy link
Author

srsman commented Aug 1, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants