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..e1ce060a 100644 --- a/src/content/AccountCollector.ts +++ b/src/content/AccountCollector.ts @@ -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,12 +257,17 @@ export default class AccountCollector { private async collectUsers() { const isBlockPage = await TwitterPage.isBlockExportPage(); - const userCells: NodeListOf = this.isLegacyTwitter + let userCells: NodeListOf = this.isLegacyTwitter ? (await this.getScrollList()).querySelectorAll("a.js-user-profile-link") - : (await this.getScrollList()).querySelectorAll('[data-testid="UserCell"]'); + : 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 = await this.getTotalUsersCount(); const probablyAlmostReadyThreshold = totalUserCount < 100 ? 70 : totalUserCount < 200 ? 80 : 90; const animationLevel = await this.getAnimationLevel(); @@ -651,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); @@ -668,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, }); @@ -681,7 +709,7 @@ export default class AccountCollector { return; } - console.debug("finishCollecting()"); + console.debug("LikersBlocker: finishCollecting()"); this.stopScrolling(); @@ -913,7 +941,7 @@ export default class AccountCollector { } private stopScrolling = () => { - console.debug("stopScrolling()"); + console.debug("LikersBlocker: stopScrolling()"); clearInterval(this.scrollInterval); };