Skip to content

Commit

Permalink
Fix twitter x rename (#282)
Browse files Browse the repository at this point in the history
Closes #280
Co-authored-by: dani <29378233+DanielleMiu@users.noreply.github.com>
  • Loading branch information
kheina committed May 16, 2024
1 parent 6fb6616 commit 2b20f35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/injected/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(function (xhr) {
// TODO: find a way to make this cleaner
const RequestRegex = /^https?:\/\/(?:\w+\.)?twitter.com\/[\w\/\.\-\_\=]+\/(HomeLatestTimeline|HomeTimeline|Followers|Following|SearchTimeline|UserTweets|UserCreatorSubscriptions|FollowersYouKnow|BlueVerifiedFollowers|SearchTimeline|timeline\/home\.json|TweetDetail|search\/typeahead\.json|search\/adaptive\.json|blocks\/destroy\.json|mutes\/users\/destroy\.json)(?:$|\?)/;
const RequestRegex = /^https?:\/\/(?:\w+\.)?(?:twitter|x)\.com\/[\w\/\.\-\_\=]+\/(HomeLatestTimeline|HomeTimeline|Followers|Following|SearchTimeline|UserTweets|UserCreatorSubscriptions|FollowersYouKnow|BlueVerifiedFollowers|SearchTimeline|timeline\/home\.json|TweetDetail|search\/typeahead\.json|search\/adaptive\.json|blocks\/destroy\.json|mutes\/users\/destroy\.json)(?:$|\?)/;

let XHR = <BlueBlockerXLMRequest>XMLHttpRequest.prototype;
let open = XHR.open;
Expand Down
14 changes: 12 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export default defineManifest({
},
content_scripts: [
{
matches: ["*://*.twitter.com/*", "*://twitter.com/*"],
matches: [
"*://*.twitter.com/*",
"*://twitter.com/*",
"*://*.x.com/*",
"*://x.com/*",
],
js: ["src/content/index.ts"],
},
],
Expand All @@ -30,7 +35,12 @@ export default defineManifest({
"src/injected/*",
"icon/*",
],
matches: ["*://*.twitter.com/*", "*://twitter.com/*"],
matches: [
"*://*.twitter.com/*",
"*://twitter.com/*",
"*://*.x.com/*",
"*://x.com/*",
],
},
],
});
6 changes: 4 additions & 2 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ setInterval(blockCache.clear, 10 * 60e3); // clear the cache every 10 minutes
// this is just here so we don't double add users unnecessarily (and also overwrite name)
setInterval(UnblockCache.clear, 10 * 60e3);

const twitterWindowRegex = /^https?:\/\/(?:\w+\.)?(?:twitter|x)\.com(?=$|\/)/;

function unblockUser(
user: { name: string; screen_name: string },
user_id: string,
Expand All @@ -69,7 +71,7 @@ function unblockUser(
api.storage.sync.set(items);
});

const match = window.location.href.match(/^https?:\/\/(?:\w+\.)?twitter.com(?=$|\/)/);
const match = window.location.href.match(twitterWindowRegex);

if (!match) {
throw new Error('unexpected or incorrectly formatted url');
Expand Down Expand Up @@ -375,7 +377,7 @@ consumer.start();
const CsrfTokenRegex = /ct0=\s*(\w+);/;

function blockUser(user: BlockUser, attempt = 1) {
const match = window.location.href.match(/^https?:\/\/(?:\w+\.)?twitter.com(?=$|\/)/);
const match = window.location.href.match(twitterWindowRegex);

if (!match) {
throw new Error('unexpected or incorrectly formatted url');
Expand Down

0 comments on commit 2b20f35

Please sign in to comment.