Skip to content

Commit

Permalink
revert like api
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jun 14, 2024
1 parent 3550446 commit e5bdcbe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
40 changes: 36 additions & 4 deletions scripts/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand Down
36 changes: 33 additions & 3 deletions scripts/twchallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
};
Expand Down

0 comments on commit e5bdcbe

Please sign in to comment.