Skip to content

Commit

Permalink
fix emojis disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Oct 6, 2023
1 parent 9c4c3f4 commit fd45a03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 9 additions & 2 deletions scripts/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2723,7 +2723,7 @@ const API = {
});
});
},
getV2: id => {
getV2: (id, useDiffKey) => {
return new Promise((resolve, reject) => {
chrome.storage.local.get(['tweetDetails'], d => {
if(!d.tweetDetails) d.tweetDetails = {};
Expand All @@ -2738,6 +2738,9 @@ const API = {
listeners: []
};
}
if(typeof useDiffKey === 'undefined' && isFinite(+localStorage.hitRateLimit) && +localStorage.hitRateLimit > Date.now()) {
useDiffKey = true;
}
fetch(`https://twitter.com/i/api/graphql/KwGBbJZc6DBx8EKmyQSP7g/TweetDetail?variables=${encodeURIComponent(JSON.stringify({
"focalTweetId":id,
"with_rux_injections":false,
Expand All @@ -2749,7 +2752,7 @@ const API = {
"withV2Timeline":true
}))}&features=${encodeURIComponent(JSON.stringify({"rweb_lists_timeline_redesign_enabled":false,"blue_business_profile_image_shape_enabled":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":false,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"tweetypie_unmention_optimization_enabled":true,"vibe_api_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"tweet_awards_web_tipping_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":false,"interactive_text_enabled":true,"responsive_web_text_conversations_enabled":false,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":false,"responsive_web_enhance_cards_enabled":false}))}`, {
headers: {
"authorization": isFinite(+localStorage.hitRateLimit) && +localStorage.hitRateLimit > Date.now() ? OLDTWITTER_CONFIG.oauth_key : OLDTWITTER_CONFIG.public_token,
"authorization": useDiffKey ? OLDTWITTER_CONFIG.oauth_key : OLDTWITTER_CONFIG.public_token,
"x-csrf-token": OLDTWITTER_CONFIG.csrf,
"x-twitter-auth-type": "OAuth2Session",
"x-twitter-client-language": LANGUAGE ? LANGUAGE : navigator.language ? navigator.language : "en"
Expand All @@ -2758,6 +2761,10 @@ const API = {
}).then(i => i.json()).then(data => {
debugLog('tweet.getV2', 'start', id, data);
if (data.errors && data.errors[0]) {
if(data.errors[0].code === 88 && !useDiffKey) {
localStorage.hitRateLimit = Date.now() + 600000;
return resolve(tweet.getV2(id, true));
}
if(loadingDetails[id]) loadingDetails[id].listeners.forEach(l => l[1](data.errors[0].message));
delete loadingDetails[id];
return reject(data.errors[0].message);
Expand Down
9 changes: 2 additions & 7 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ function escapeHTML(unsafe) {
.replace(/"/g, """)
.replace(/'/g, "’");
}
const splitEmoji = (string) => [...new Intl.Segmenter().segment(string)].map(x => x.segment);
async function renderTweetBodyHTML(t, is_quoted) {
let result = "",
last_pos = 0,
Expand All @@ -399,18 +398,14 @@ async function renderTweetBodyHTML(t, is_quoted) {

if(is_quoted) t = t.quoted_status

if(Intl.Segmenter) {
full_text_array = splitEmoji(t.full_text);
} else {
full_text_array = Array.from(t.full_text);
}
full_text_array = Array.from(t.full_text);

if (t.entities.richtext) {
t.entities.richtext.forEach(snippet => {
index_map[snippet.from_index] = [
snippet.to_index,
text => {
let snippetText = escapeHTML(full_text_array.slice(snippet.from_index, snippet.to_index).join(""));
let snippetText = escapeHTML(t.full_text.slice(snippet.from_index, snippet.to_index));
let startingTags = `${snippet.richtext_types.includes('Bold') ? '<b>' : ''}${snippet.richtext_types.includes('Italic') ? '<i>' : ''}`;
let endingTags = `${snippet.richtext_types.includes('Bold') ? '</b>' : ''}${snippet.richtext_types.includes('Italic') ? '</i>' : ''}`;

Expand Down

0 comments on commit fd45a03

Please sign in to comment.