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

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

Open
lolums1231 opened this issue May 17, 2024 · 11 comments
Open

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

lolums1231 opened this issue May 17, 2024 · 11 comments

Comments

@lolums1231
Copy link

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

@lolums1231
Copy link
Author

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
Copy link

ruemiyafuji commented May 17, 2024

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
Copy link
Author

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 added a commit that referenced this issue May 17, 2024
@AlttiRi
Copy link
Owner

AlttiRi commented May 17, 2024

Damn, this move was to be expected.

I did a quick fix: 3b53894
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)

For example, live-server --https=C:/dev/fs-server/.ssl/ssl.cjs --port=443.
For httpS you need to generate cert.crt and cert.key with 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:

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
Copy link
Owner

AlttiRi commented May 17, 2024

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

BTW, thanks, that you have reported it here.

@biggestsonicfan
Copy link

biggestsonicfan commented May 17, 2024

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
Copy link
Owner

AlttiRi commented May 17, 2024

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
Copy link
Owner

AlttiRi commented May 17, 2024

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
Copy link

biggestsonicfan commented May 17, 2024

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
Copy link

biggestsonicfan commented May 20, 2024

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.

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

5 participants
@biggestsonicfan @AlttiRi @lolums1231 @ruemiyafuji and others