From 0acba22dc1692bf46f61efa1c2b7d5a0ed024917 Mon Sep 17 00:00:00 2001 From: Alper Ozdemir Date: Mon, 14 Aug 2023 16:36:10 +0300 Subject: [PATCH 1/2] fix: Retrieve likers (+add build commands for Win) --- CONTRIBUTION.md | 8 ++++++++ package.json | 3 +++ src/content/AccountCollector.ts | 11 ++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index e93ce368..e2532f5d 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -26,10 +26,18 @@ npm install ### Start the build process in watch mode +For Unix based systems: + ```bash npm start ``` +For Windows: + +```bash +npm run start:win +``` + ## Load the local extension in your browser ### Chromium diff --git a/package.json b/package.json index 6c9f99c1..f4b0b61e 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "start": "NODE_ENV=development rollup -w --config rollup.config.js", "build": "NODE_ENV=production rollup --config rollup.config.js", "buildDev": "NODE_ENV=development rollup --config rollup.config.js", + "start:win": "SET NODE_ENV=development&rollup -w --config rollup.config.js", + "build:win": "SET NODE_ENV=production&rollup --config rollup.config.js", + "buildDev:win": "SET NODE_ENV=development&rollup --config rollup.config.js", "lint": "eslint src/**/*.ts", "fix": "eslint src/**/*.ts src/*.ts --fix", "version": "node util/release.js && npm run build && git add .", diff --git a/src/content/AccountCollector.ts b/src/content/AccountCollector.ts index eebb1319..62fcb793 100644 --- a/src/content/AccountCollector.ts +++ b/src/content/AccountCollector.ts @@ -15,7 +15,7 @@ import TwitterPage, { AccountList } from "./TwitterPage"; const TOPBAR_SELECTOR = { mobile: "main > div > div > div > div > div > div", - desktop: "[aria-labelledby=modal-header] > div > div > div > div > div > div > div > div > div", + desktop: "[aria-labelledby=modal-header] > div > div > div > div > div > div > div > div > div" }; const BLOCKED_BUTTON_SELECTOR = "[data-testid=UserCell] [role=button]"; @@ -234,13 +234,14 @@ export default class AccountCollector { private async collectUsers() { const isBlockPage = await TwitterPage.isBlockExportPage(); - const userCells: NodeListOf = this.isLegacyTwitter - ? (await this.getScrollList()).querySelectorAll("a.js-user-profile-link") - : (await this.getScrollList()).querySelectorAll('[data-testid="UserCell"]'); + const userCells: NodeListOf = this.isLegacyTwitter + ? (await this.getScrollList()).querySelectorAll("a.js-user-profile-link") + : document.querySelectorAll('[aria-labelledby=modal-header] [data-testid="UserCell"]'); + // const userCells: NodeListOf = document.querySelectorAll('[aria-labelledby=modal-header] [data-testid="UserCell"]'); // Increase allowance for larger lists to avoid false-positive warnings: const idleCounterAllowance = settings.IDLE_COUNTER_ALLOWANCE + Math.floor(this.collectedUsers.size / 500); - const totalUserCount = await this.getTotalUsersCount(); + const totalUserCount = 9999999999;//= await this.getTotalUsersCount(); - THIS API IS NO LONGER AVAILABLE! const probablyAlmostReadyThreshold = totalUserCount < 100 ? 70 : totalUserCount < 200 ? 80 : 90; const animationLevel = await this.getAnimationLevel(); From 1f88fb2ef0cd9b72c397631217d0c231ad11eb24 Mon Sep 17 00:00:00 2001 From: Alper Ozdemir Date: Sat, 9 Sep 2023 23:22:00 +0300 Subject: [PATCH 2/2] fix: update the selector for blocked collector --- src/content/AccountCollector.ts | 79 ++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/content/AccountCollector.ts b/src/content/AccountCollector.ts index 62fcb793..e1ce060a 100644 --- a/src/content/AccountCollector.ts +++ b/src/content/AccountCollector.ts @@ -15,7 +15,7 @@ import TwitterPage, { AccountList } from "./TwitterPage"; const TOPBAR_SELECTOR = { mobile: "main > div > div > div > div > div > div", - desktop: "[aria-labelledby=modal-header] > div > div > div > div > div > div > div > div > div" + desktop: "[aria-labelledby=modal-header] > div > div > div > div > div > div > div > div > div", }; const BLOCKED_BUTTON_SELECTOR = "[data-testid=UserCell] [role=button]"; @@ -32,7 +32,6 @@ export default class AccountCollector { private popupWrapper: HTMLElement; private scrollInterval: number; private topbar: HTMLElement | null | undefined; - private totalUsersCount: number; private confirmButton: HTMLAnchorElement | HTMLDivElement; private constructor() { @@ -133,26 +132,50 @@ export default class AccountCollector { const isRetweetsPage = await TwitterPage.isRetweetsPage(); const isTweetPage = await TwitterPage.isTweetPage(); const isListPage = await TwitterPage.isListPage(); - - if (!this.totalUsersCount) { - if (isTweetPage) { - const tweetId = await TwitterPage.getTweetId(); - const tweet = await APIService.getTweet(tweetId); - this.totalUsersCount = isRetweetsPage ? tweet.retweet_count : tweet.favorite_count; - } else if (isListPage) { - const listId = await TwitterPage.getListId(); - const list = await APIService.getList(listId); - this.totalUsersCount = - isListPage === AccountList.followers ? list.subscriber_count : list.member_count; - } + let totalUsersCount = -1; + console.log( + "getTotalUsersCount() - isRetweetsPage:" + + isRetweetsPage + + " - isTweetPage:" + + isTweetPage + + " - isListPage:" + + isListPage + ); + if (isTweetPage) { + const interactionElements = document.querySelectorAll('article div[role="group"] a span'); + let tweetLikes = -1; + let tweetReposts = -1; + interactionElements.forEach((iElement) => { + if (iElement.textContent === "Likes") { + tweetLikes = parseInt( + iElement.parentElement.parentElement.querySelector( + '[data-testid="app-text-transition-container"]' + ).textContent + ); + console.log("Tweet Likes:" + tweetLikes); + } else if (iElement.textContent === "Reposts") { + tweetReposts = parseInt( + iElement.parentElement.parentElement.querySelector( + '[data-testid="app-text-transition-container"]' + ).textContent + ); + console.log("Tweet Reposts:" + tweetReposts); + } + }); + totalUsersCount = isRetweetsPage ? tweetReposts : tweetLikes; + } else if (isListPage) { + const listId = await TwitterPage.getListId(); + const list = await APIService.getList(listId); + totalUsersCount = + isListPage === AccountList.followers ? list.subscriber_count : list.member_count; } // prevent multiple api calls of not successful: - if (!this.totalUsersCount) { - this.totalUsersCount = -1; + if (!totalUsersCount) { + totalUsersCount = -1; } - return this.totalUsersCount; + return totalUsersCount; } private async getLimitMessage() { @@ -200,7 +223,7 @@ export default class AccountCollector { } private async changeStateToConfirm() { - console.debug("changeStateToConfirm()"); + console.debug("LikersBlocker: changeStateToConfirm()"); this.popup.classList.add("lb-confirm"); const avatarsWrapper = document.querySelector(".lb-truck-animation__avatars"); avatarsWrapper?.remove(); @@ -234,14 +257,18 @@ export default class AccountCollector { private async collectUsers() { const isBlockPage = await TwitterPage.isBlockExportPage(); - const userCells: NodeListOf = this.isLegacyTwitter - ? (await this.getScrollList()).querySelectorAll("a.js-user-profile-link") - : document.querySelectorAll('[aria-labelledby=modal-header] [data-testid="UserCell"]'); + let userCells: NodeListOf = this.isLegacyTwitter + ? (await this.getScrollList()).querySelectorAll("a.js-user-profile-link") + : document.querySelectorAll('[aria-labelledby=modal-header] [data-testid="UserCell"]'); + if (isBlockPage) { + userCells = document.querySelectorAll('div[aria-label="Timeline: Blocked accounts"] div[data-testid="cellInnerDiv"]'); + } // const userCells: NodeListOf = document.querySelectorAll('[aria-labelledby=modal-header] [data-testid="UserCell"]'); // Increase allowance for larger lists to avoid false-positive warnings: const idleCounterAllowance = settings.IDLE_COUNTER_ALLOWANCE + Math.floor(this.collectedUsers.size / 500); - const totalUserCount = 9999999999;//= await this.getTotalUsersCount(); - THIS API IS NO LONGER AVAILABLE! + + const totalUserCount = await this.getTotalUsersCount(); const probablyAlmostReadyThreshold = totalUserCount < 100 ? 70 : totalUserCount < 200 ? 80 : 90; const animationLevel = await this.getAnimationLevel(); @@ -652,7 +679,7 @@ export default class AccountCollector { } private async scrollDown(animationLevel: AnimationLevel) { - console.debug("scrollDown()"); + console.debug("LikersBlocker: scrollDown()"); const scrolly = await this.scrolly; const scrollListIsSmall = scrolly.scrollHeight < scrolly.clientHeight * 2; const scrollTop = Math.ceil(scrolly.scrollTop); @@ -669,7 +696,7 @@ export default class AccountCollector { await this.collectUsers(); if (scrolledToBottom || scrollListIsSmall || allUsersCollected) { - console.info("finished collecting!", { + console.info("LikersBlocker: finished collecting!", { scrolledToBottom, scrollListIsSmall, }); @@ -682,7 +709,7 @@ export default class AccountCollector { return; } - console.debug("finishCollecting()"); + console.debug("LikersBlocker: finishCollecting()"); this.stopScrolling(); @@ -914,7 +941,7 @@ export default class AccountCollector { } private stopScrolling = () => { - console.debug("stopScrolling()"); + console.debug("LikersBlocker: stopScrolling()"); clearInterval(this.scrollInterval); };