AlttiRi / twitter-click-and-save

[userscript] Adds buttons to save images and videos in Twitter, also does some other enhancements. (Twitter image and video downloader)
https://greasyfork.org/en/scripts/430132
GNU General Public License v3.0
104 stars 9 forks source link

Auto-redict from twitter.com to x.com breaking functionality #40

Open lolums1231 opened 5 months ago

lolums1231 commented 5 months ago

Twitter.com is now auto-redirecting to x.com, script doesn't load on x.com breaking functionality.

lolums1231 commented 5 months ago

Edit the script and just add this

// @match       https://x.com/*

This works to get the download button back but doesn't fix the "Error" or "X" from appearing when using on both video and images.

Enabling "Strict Tracking Protection Fix" allows images to be saved, but "Error" on videos, with it disabled obviously neither video or image downloading works.

When downloading an image, the account name in the saved file name appears as "undefined" for all images, something isn't working specifically for x.com. Where as on twitter.com hours earlier without any other changes was fully functional.

Running up-to-date Tampermonkey and Firefox with script version 1.9.1-2023.12.19 + // @match https://x.com/*

ruemiyafuji commented 5 months ago

On this line

        get author() {
            //return this.url.match(/(?<=twitter\.com\/).+?(?=\/)/)?.[0];
         }

Change it to

        get author() {
            //return this.url.match(/(?<=x\.com\/).+?(?=\/)/)?.[0];
         }

to fix the name

lolums1231 commented 5 months ago

On this line

        get author() {
            //return this.url.match(/(?<=twitter\.com\/).+?(?=\/)/)?.[0];
         }

Change it to

        get author() {
            //return this.url.match(/(?<=x\.com\/).+?(?=\/)/)?.[0];
         }

to fix the name

This helped fix the name

All the changes I've made

            // if not an opened tweet
            if (!location.href.match(/x\.com\/[^\/]+\/status\/\d+/)) {

to

            // if not an opened tweet
            if (!location.href.match(/twitter\.com\/[^\/]+\/status\/\d+/)) {
        static goFromMobileToMainSite() { // uncompleted
            if (location.href.startsWith("https://mobile.twitter.com/")) {
                location.href = location.href.replace("https://mobile.twitter.com/", "https://twitter.com/");

to

        static goFromMobileToMainSite() { // uncompleted
            if (location.href.startsWith("https://mobile.x.com/")) {
                location.href = location.href.replace("https://mobile.x.com/", "https://x.com/");
        get author() {
            return this.url.match(/(?<=twitter\.com\/).+?(?=\/)/)?.[0];

to

        get author() {
            return this.url.match(/(?<=x\.com\/).+?(?=\/)/)?.[0];
            const urlBase = `https://twitter.com/i/api/graphql/${API.TweetDetailQueryId}/TweetDetail`;

to

            const urlBase = `https://x.com/i/api/graphql/${API.TweetDetailQueryId}/TweetDetail`;
            const url = `https://twitter.com/i/api/graphql/${API.UserByScreenNameQueryId}/UserByScreenName?variables=${encodeURIComponent(variables)}`;

to

            const url = `https://x.com/i/api/graphql/${API.UserByScreenNameQueryId}/UserByScreenName?variables=${encodeURIComponent(variables)}`;

basically changing "twitter" to "x", I don't really know what I'm doing but these seem to fix the the video downloads so long as I have "Strict Tracking Protection Fix" enabled.

AlttiRi commented 5 months ago

Damn, this move was to be expected.

I did a quick fix: https://github.com/AlttiRi/twitter-click-and-save/commit/3b53894ba2448d3286ba2da1d9a8d0e5907214f4 Did not test on FF yet.


The bad thing is that the history is hostname (origin) depended. So, the new hostname — the new history. It's why I did not added mobile.twitter.com earlier in // @match.

It makes sense to add an option to store the history in a userscript manager extension's storage (instead of Localstorage), in this case it will work OK on multiple origins.


BTW, technically it's possible to extract the LocalStorage data from the old (https://twitter.com) origin, but it's too complicated for a common user, it requires to run a local https server.

how to (click) --- - run any [local web server](https://www.npmjs.com/package/@compodoc/live-server) on `localhost:443` with enabled http**s** For example, `live-server --https=C:/dev/fs-server/.ssl/ssl.cjs --port=443`. For http**S** you need to generate `cert.crt` and `cert.key` with [`mkcert`](https://www.npmjs.com/package/mkcert): ``` npx mkcert create-ca --organization "Test CA for fs-server" --key "ca-root.key" --cert "ca-root.crt" ``` ``` npx mkcert create-cert --ca-key "ca-root.key" --ca-cert "ca-root.crt" --domains 192.168.1.33,127.0.0.1,localhost ``` ssl.cjs: ```js const fs = require("fs"); module.exports = { cert: fs.readFileSync(__dirname + "/cert.crt"), key: fs.readFileSync(__dirname + "/cert.key"), }; ``` - add in `hosts` (`C:\Windows\System32\drivers\etc`) a row with `127.0.0.1 twitter.com` text, - also, remove in `chrome://net-internals/#hsts` the cached HSTS data for `twitter.com`.

Probably, it would simpler to recreate the history from the downloaded files' names. However, it also requires to run an external program (a script) to scan the download/archive folder.

AlttiRi commented 5 months ago

Seems, it should be worked, will check it in some hours for others bugs.

BTW, thanks, that you have reported it here.

biggestsonicfan commented 5 months ago

Oh boy, I was just thinking I should export my history the other day, oops! Let me see if I can whip up a better revision of the script.

EDIT: For the time being https://twitter.com/i/api/ still exists as a non-redirected url. You can navigate to this page and open twitter-click-and-save's settings and export history there.

AlttiRi commented 5 months ago

EDIT: For the time being https://twitter.com/i/api/ still exists as a non-redirected url. You can navigate to this page and open twitter-click-and-save's settings and export history there.

Yeah, it's a good solution, but only for Firefox. In Chrome the response with 403 code does not count as https://twitter.com/'s page. Chrome navigates to chrome-error://chromewebdata/ where location.origin is null.

AlttiRi commented 5 months ago

Fine. Just go to https://twitter.com/x/migrate. This link does not redirect to x.com. But only it. Then export the history in this user script's popup setting. Then open any x.com page and import/merge the exported .json file.

Screenshot

biggestsonicfan commented 5 months ago

EDIT: For the time being https://twitter.com/i/api/ still exists as a non-redirected url. You can navigate to this page and open twitter-click-and-save's settings and export history there.

Yeah, it's a good solution, but only for Firefox. In Chrome the response with 403 code does not count as https://twitter.com/'s page. Chrome navigates to chrome-error://chromewebdata/ where location.origin is null.

Ah dang, yeah. I'm having issues getting the history off Kiwi Browser (Chromium based). I have some old tabs up with twitter.com in them, but click and save isn't allowing the popup to be shown, even though the script is active.

EDIT: Eyyy, https://twitter.com/x/migrate worked a treat!

biggestsonicfan commented 5 months ago

Suddenly getting intermittent [error] Fallback URLs are failed. errors when they should be fine? I can't pinpoint the issue but it might be related to the change?

Edit: Example False alarm. Just needed Strict Tracking Protection Fix.