From e5bdcbe234f5b6e437fd647dd5d9bc17d13ece55 Mon Sep 17 00:00:00 2001 From: dimden <26517362+dimdenGD@users.noreply.github.com> Date: Fri, 14 Jun 2024 14:24:51 +0300 Subject: [PATCH] revert like api --- .github/ISSUE_TEMPLATE/feature-request.md | 3 +- manifest.json | 2 +- scripts/apis.js | 40 ++++++++++++++++++++--- scripts/twchallenge.js | 36 ++++++++++++++++++-- 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md index a6ec5e2c..254967fd 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -7,4 +7,5 @@ assignees: '' --- -Please do not request multiple big features at once, break them down into multiple issues. +Please do not request multiple big features at once, break them down into multiple issues. +Also keep in mind that OldTwitter is basically on life support now, so don't expect too much. \ No newline at end of file diff --git a/manifest.json b/manifest.json index 48899724..15624e84 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Old Twitter Layout (2024)", "description": "__MSG_ext_description__", - "version": "1.8.5", + "version": "1.8.5.1", "manifest_version": 3, "homepage_url": "https://github.com/dimdenGD/OldTwitter", "background": { diff --git a/scripts/apis.js b/scripts/apis.js index 606f9f2d..6ce3ce56 100644 --- a/scripts/apis.js +++ b/scripts/apis.js @@ -2108,9 +2108,32 @@ const API = { }, getFavorites: (id, cursor) => { return new Promise((resolve, reject) => { - fetch(`https://api.x.com/1.1/favorites/list.json?count=40&include_my_retweet=1&user_id=${id}${cursor ? `&max_id=${cursor}` : ''}&cards_platform=Web-13&include_entities=1&include_user_entities=1&include_cards=1&send_error_codes=1&tweet_mode=extended&include_ext_alt_text=true&include_reply_count=true`, { + let obj = { + "userId": id, + "count": 50, + "includePromotedContent": false, + "withSuperFollowsUserFields": true, + "withDownvotePerspective": false, + "withReactionsMetadata": false, + "withReactionsPerspective": false, + "withSuperFollowsTweetFields": true, + "withClientEventToken": false, + "withBirdwatchNotes": false, + "withVoice": true, + "withV2Timeline": true + }; + if(cursor) obj.cursor = cursor; + fetch(`/i/api/graphql/vni8vUvtZvJoIsl49VPudg/Likes?variables=${encodeURIComponent(JSON.stringify(obj))}&features=${encodeURIComponent(JSON.stringify({ + "dont_mention_me_view_api_enabled": true, + "interactive_text_enabled": true, + "responsive_web_uc_gql_enabled": false, + "vibe_tweet_context_enabled": false, + "responsive_web_edit_tweet_api_enabled": false, + "standardized_nudges_misinfo": false, + "responsive_web_enhance_cards_enabled": false + }))}`, { headers: { - "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF", + "authorization": isFinite(+localStorage.hitRateLimit) && +localStorage.hitRateLimit > Date.now() ? OLDTWITTER_CONFIG.oauth_key : OLDTWITTER_CONFIG.public_token, "x-csrf-token": OLDTWITTER_CONFIG.csrf, "x-twitter-auth-type": "OAuth2Session", "content-type": "application/json", @@ -2125,9 +2148,18 @@ const API = { if (data.errors && data.errors[0]) { return reject(data.errors[0].message); } + if(!data.data.user.result.timeline_v2.timeline.instructions[0]) { + return resolve({ + tl: [], + cursor: null + }) + } let out = { - tl: data, - cursor: data.length > 0 ? data[data.length - 1].id_str : null + tl: data.data.user.result.timeline_v2.timeline.instructions[0].entries + .filter(e => e.entryId.startsWith('tweet-') && e.content.itemContent.tweet_results.result) + .map(e => parseTweet(e.content.itemContent.tweet_results.result)) + .filter(e => e), + cursor: data.data.user.result.timeline_v2.timeline.instructions[0].entries.find(e => e.entryId.startsWith('cursor-bottom')).content.value }; debugLog('user.getFavorites', 'end', out); resolve(out); diff --git a/scripts/twchallenge.js b/scripts/twchallenge.js index 8acfa998..ac9482a9 100644 --- a/scripts/twchallenge.js +++ b/scripts/twchallenge.js @@ -108,13 +108,39 @@ fetch = async function(url, options) { async function initChallenge() { try { - let homepageData = await _fetch(`https://${location.hostname}/`).then(res => res.text()); + let homepageData; + let sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); + try { + homepageData = await _fetch(`https://${location.hostname}/`).then(res => res.text()); + } catch(e) { + await sleep(500); + try { + homepageData = await _fetch(`https://${location.hostname}/`).then(res => res.text()); + } catch(e) { + throw new Error('Failed to fetch homepage: ' + e); + } + } let dom = new DOMParser().parseFromString(homepageData, 'text/html'); let verificationKey = dom.querySelector('meta[name="twitter-site-verification"]').content; let anims = Array.from(dom.querySelectorAll('svg[id^="loading-x"]')).map(svg => svg.outerHTML); let challengeCode = homepageData.match(/"ondemand.s":"(\w+)"/)[1]; - let challengeData = await _fetch(`https://abs.twimg.com/responsive-web/client-web/ondemand.s.${challengeCode}a.js`).then(res => res.text()); + let challengeData; + try { + challengeData = await _fetch(`https://abs.twimg.com/responsive-web/client-web/ondemand.s.${challengeCode}a.js`).then(res => res.text()); + } catch(e) { + await sleep(500); + try { + challengeData = await _fetch(`https://abs.twimg.com/responsive-web/client-web/ondemand.s.${challengeCode}a.js`).then(res => res.text()); + } catch(e) { + await sleep(1000); + try { + challengeData = await _fetch(`https://abs.twimg.com/responsive-web/client-web/ondemand.s.${challengeCode}a.js`).then(res => res.text()); + } catch(e) { + throw new Error('Failed to fetch challenge data: ' + e); + } + } + } OLDTWITTER_CONFIG.verificationKey = verificationKey; @@ -136,7 +162,11 @@ async function initChallenge() { } catch (e) { console.error(`Error during challenge init:`); console.error(e); - alert(`There was an error in initializing security header generator: ${e}. OldTwitter doesn't allow unsigned requests anymore for your account security. Currently the main reason for this happening is social network tracker protection blocking the script. Try disabling such settings in your browser and extensions that do that and refresh the page.`); + if(location.hostname === 'twitter.com') { + alert(`There was an error in initializing security header generator: ${e}. OldTwitter doesn't allow unsigned requests anymore for your account security. Currently the main reason for this happening is social network tracker protection blocking the script. Try disabling such settings in your browser and extensions that do that and refresh the page. Also using OldTwitter from twitter.com domain is not supported.`); + } else { + alert(`There was an error in initializing security header generator: ${e}. OldTwitter doesn't allow unsigned requests anymore for your account security. Currently the main reason for this happening is social network tracker protection blocking the script. Try disabling such settings in your browser and extensions that do that and refresh the page.`); + } return false; } };