Advertisement
AliceDay_UK

TweetDelete.txt

Nov 16th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.08 KB | None | 0 0
  1. Export your Twitter data archive from https://twitter.com/settings/download_your_data (takes 1-2 days; unzip it after downloading)
  2.  
  3. Copy script from below the line
  4.  
  5. Paste script and hit enter
  6.  
  7. A light blue bar appears at the top of the window
  8.  
  9. Use the file picker to select your tweet-headers.js file
  10.  
  11. Wait for all your Tweets to vanish (about 5-10 Tweets per second)
  12.  
  13.  
  14. ***************************************************************************
  15.  
  16.  
  17. // ==UserScript==
  18. // @name TweetXer
  19. // @namespace https://github.com/lucahammer/tweetXer/
  20. // @version 0.6.6
  21. // @description Delete all your Tweets for free.
  22. // @author Luca
  23. // @match https://x.com/*
  24. // @icon https://www.google.com/s2/favicons?domain=twitter.com
  25. // @grant unsafeWindow
  26. // ==/UserScript==
  27.  
  28. var TweetsXer = {
  29. allowed_requests: [],
  30. TweetCount: 0,
  31. dId: "exportUpload",
  32. tIds: [],
  33. tId: "",
  34. ratelimitreset: 0,
  35. more: '[data-testid="tweet"] [aria-label="More"][data-testid="caret"]',
  36. skip: 0,
  37. total: 0,
  38. dCount: 0,
  39. lastHeaders: {},
  40. deleteURL: 'https://x.com/i/api/graphql/VaenaVgh5q5ih7kvyVjgtg/DeleteTweet',
  41. unfavURL: 'https://x.com/i/api/graphql/ZYKSe-w7KEslx3JhSIk5LA/UnfavoriteTweet',
  42. username: '',
  43. action: '',
  44. bookmarksURL: 'https://x.com/i/api/graphql/sLg287PtRrRWcUciNGFufQ/Bookmarks?',
  45. bookmarks: [],
  46. bookmarksNext: '',
  47.  
  48. init() {
  49. // document.querySelector('header>div>div').setAttribute('class', '')
  50. TweetsXer.username = document.location.href.split('/')[3]
  51. this.createUploadForm()
  52. TweetsXer.initXHR()
  53. TweetsXer.getTweetCount()
  54. this.sleep(200)
  55. },
  56.  
  57. sleep(ms) {
  58. return new Promise((resolve) => setTimeout(resolve, ms))
  59. },
  60.  
  61. initXHR() {
  62. if (typeof AjaxMonitoring_notfired == "undefined") { var AjaxMonitoring_notfired = false }
  63. if (!AjaxMonitoring_notfired) {
  64. AjaxMonitoring_notfired = true
  65.  
  66. /* NOTE: XMLHttpRequest actions happen in this sequence: at first "open"[readyState=1] happens, then "setRequestHeader", then "send", then "open"[readyState=2] */
  67.  
  68. var XHR_SendOriginal = XMLHttpRequest.prototype.send
  69. XMLHttpRequest.prototype.send = function () {
  70. XHR_SendOriginal.apply(this, arguments)
  71. }
  72.  
  73. var XHR_OpenOriginal = XMLHttpRequest.prototype.open
  74. XMLHttpRequest.prototype.open = function () {
  75. if (arguments[1] && arguments[1].includes("DeleteTweet")) {
  76. // POST /DeleteTweet
  77. TweetsXer.deleteURL = arguments[1]
  78. }
  79. XHR_OpenOriginal.apply(this, arguments)
  80. }
  81.  
  82. var XHR_SetRequestHeaderOriginal = XMLHttpRequest.prototype.setRequestHeader
  83. XMLHttpRequest.prototype.setRequestHeader = function (a, b) {
  84. TweetsXer.lastHeaders[a] = b
  85. XHR_SetRequestHeaderOriginal.apply(this, arguments)
  86. }
  87. }
  88. },
  89.  
  90. updateProgressBar() {
  91. document.getElementById('progressbar').setAttribute('value', this.dCount)
  92. document.getElementById("info").textContent = `${this.dCount} deleted`
  93. },
  94.  
  95. processFile() {
  96. let tn = document.getElementById(`${TweetsXer.dId}_file`)
  97. if (tn.files && tn.files[0]) {
  98. let fr = new FileReader()
  99. fr.onloadend = function (evt) {
  100. // window.YTD.tweet_headers.part0
  101. // window.YTD.tweets.part0
  102. // window.YTD.like.part0
  103. let cutpoint = evt.target.result.indexOf('= ')
  104. let filestart = evt.target.result.slice(0, cutpoint)
  105. let json = JSON.parse(evt.target.result.slice(cutpoint + 1))
  106.  
  107. if (filestart.includes('.tweet_headers.')) {
  108. console.log('File contains Tweets.')
  109. TweetsXer.action = 'untweet'
  110. TweetsXer.tIds = json.map((x) => x.tweet.tweet_id)
  111. } else if (filestart.includes('.tweets.') || filestart.includes('.tweet.')) {
  112. console.log('File contains Tweets.')
  113. TweetsXer.action = 'untweet'
  114. TweetsXer.tIds = json.map((x) => x.tweet.id_str)
  115. } else if (filestart.includes('.like.')) {
  116. console.log('File contains Favs.')
  117. TweetsXer.action = 'unfav'
  118. TweetsXer.tIds = json.map((x) => x.like.tweetId)
  119. } else {
  120. console.log('File contain not recognized. Please use a file from the Twitter data export.')
  121. }
  122.  
  123.  
  124. TweetsXer.total = TweetsXer.tIds.length
  125. document.getElementById('start').remove()
  126. TweetsXer.createProgressBar()
  127.  
  128. TweetsXer.skip = document.getElementById('skipCount').value
  129.  
  130.  
  131. if (TweetsXer.action == 'untweet') {
  132. if (TweetsXer.skip == 0) {
  133. // If there is no amount set to skip, automatically try to skip the amount
  134. // that has been deleted already. Difference of Tweeets in file to count on profile
  135. // 5% tolerance to prevent skipping too much
  136. TweetsXer.skip = TweetsXer.total - TweetsXer.TweetCount - parseInt(TweetsXer.total / 20)
  137. TweetsXer.skip = Math.max(0, TweetsXer.skip)
  138. }
  139. console.log(`Skipping oldest ${TweetsXer.skip} Tweets`)
  140. TweetsXer.tIds.reverse()
  141. TweetsXer.tIds = TweetsXer.tIds.slice(TweetsXer.skip)
  142. TweetsXer.dCount = TweetsXer.skip
  143. TweetsXer.tIds.reverse()
  144. document.getElementById(
  145. `${TweetsXer.dId}_title`
  146. ).textContent = `Deleting ${TweetsXer.total} Tweets`
  147.  
  148. TweetsXer.deleteTweets()
  149. } else if (TweetsXer.action == 'unfav') {
  150. console.log(`Skipping oldest ${TweetsXer.skip} Tweets`)
  151. TweetsXer.tIds = TweetsXer.tIds.slice(TweetsXer.skip)
  152. TweetsXer.dCount = TweetsXer.skip
  153. TweetsXer.tIds.reverse()
  154. document.getElementById(
  155. `${TweetsXer.dId}_title`
  156. ).textContent = `Deleting ${TweetsXer.total} Favs`
  157. TweetsXer.deleteFavs()
  158. } else {
  159. document.getElementById(
  160. `${TweetsXer.dId}_title`
  161. ).textContent = `Please try a different file`
  162. }
  163.  
  164. }
  165. fr.readAsText(tn.files[0])
  166. }
  167. },
  168.  
  169. createUploadForm() {
  170. var h2_class = document.querySelectorAll("h2")[1]?.getAttribute("class") || ""
  171. var div = document.createElement("div")
  172. div.id = this.dId
  173. if (document.getElementById(this.dId)) { document.getElementById(this.dId).remove() }
  174. div.innerHTML = `<style>#${this.dId}{ z-index:99999; position: sticky; top:0px; left:0px; width:auto; margin:0 auto; padding: 20px 10%; background:#87CEFA; opacity:0.9; } #${this.dId} > *{padding:5px;}</style>
  175. <div>
  176. <h2 class="${h2_class}" id="${this.dId}_title">TweetXer</h2>
  177. <p id="info">Select your tweet-headers.js from your Twitter Data Export to start the deletion of all your Tweets. </p>
  178. <p id="start">
  179. <input type="file" value="" id="${this.dId}_file" />
  180. <a href="#" id="toggleAdvanced">Advanced Options</a>
  181. <div id="advanced" style="display:none">
  182. <label for="skipCount">Enter how many Tweets to skip (useful for reruns) before selecting a file.</label>
  183. <input id="skipCount" type="number" value="0" />
  184. <p>To delete your Favs (aka Likes), select your like.js file.</p>
  185. <p>Instead of your tweet-headers.js file, you can use the tweets.js file. Unfaving is limited to 500 unfavs per 15 minutes.</p>
  186. <input id="exportBookmarks" type="button" value="Export Bookmarks" />
  187. <p><strong>No tweet-headers.js?</strong><br>
  188. If you are unable to get your data export, you can use the following option.<br>
  189. This option is much slower and less reliable. It can remove at most 4000 Tweets per hour.<br>
  190. <input id="slowDelete" type="button" value="Slow delete without file" />
  191. </p>
  192. <p><strong>Unfollow everyone</strong><br>
  193. It's time to let go. This will unfollow everyone you follow.<br>
  194. <input id="unfollowEveryone" type="button" value="Unfollow everyone" />
  195. </p>
  196. <p><input id="removeTweetXer" type="button" value="Remove TweetXer" /></p>
  197. </div>
  198. </p>
  199. </div>`
  200. document.body.insertBefore(div, document.body.firstChild)
  201. document.getElementById("toggleAdvanced").addEventListener("click", (() => {
  202. let adv = document.getElementById('advanced')
  203. if (adv.style.display == 'none') {
  204. adv.style.display = 'block'
  205. } else {
  206. adv.style.display = 'none'
  207. }
  208. }))
  209. document.getElementById(`${this.dId}_file`).addEventListener("change", this.processFile, false)
  210. document.getElementById("exportBookmarks").addEventListener("click", this.exportBookmarks, false)
  211. document.getElementById("slowDelete").addEventListener("click", this.slowDelete, false)
  212. document.getElementById("unfollowEveryone").addEventListener("click", this.unfollow, false)
  213. document.getElementById("removeTweetXer").addEventListener("click", this.removeTweetXer, false)
  214.  
  215. },
  216.  
  217. async exportBookmarks() {
  218. //document.getElementById('exportBookmarks').remove()
  219. //TweetsXer.createProgressBar()
  220. while (!('authorization' in TweetsXer.lastHeaders)) {
  221. await TweetsXer.sleep(1000)
  222. }
  223. let variables = ''
  224. while (TweetsXer.bookmarksNext.length > 0 || TweetsXer.bookmarks.length == 0) {
  225. if (TweetsXer.bookmarksNext.length > 0) {
  226. variables = `{"count":20,"cursor":"${TweetsXer.bookmarksNext}","includePromotedContent":true}`
  227. } else variables = '{"count":20,"includePromotedContent":false}'
  228. let response = await fetch(TweetsXer.bookmarksURL + new URLSearchParams({
  229. variables: variables,
  230. features: '{"graphql_timeline_v2_bookmark_timeline":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"responsive_web_home_pinned_timelines_enabled":true,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"tweetypie_unmention_optimization_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,"responsive_web_twitter_article_tweet_consumption_enabled":false,"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":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_media_download_video_enabled":false,"responsive_web_enhance_cards_enabled":false}'
  231. }), {
  232. "headers": {
  233. "accept": "*/*",
  234. "accept-language": 'en-US,en;q=0.5',
  235. "authorization": TweetsXer.lastHeaders.authorization,
  236. "content-type": "application/json",
  237. "sec-fetch-dest": "empty",
  238. "sec-fetch-mode": "cors",
  239. "sec-fetch-site": "same-origin",
  240. "x-client-transaction-id": TweetsXer.lastHeaders['X-Client-Transaction-Id'],
  241. "x-client-uuid": TweetsXer.lastHeaders['x-client-uuid'],
  242. "x-csrf-token": TweetsXer.lastHeaders['x-csrf-token'],
  243. "x-twitter-active-user": "yes",
  244. "x-twitter-auth-type": "OAuth2Session",
  245. "x-twitter-client-language": 'en'
  246. },
  247. "referrer": 'https://x.com/i/bookmarks',
  248. "referrerPolicy": "strict-origin-when-cross-origin",
  249. "method": "GET",
  250. "mode": "cors",
  251. "credentials": "include"
  252. })
  253.  
  254. if (response.status == 200) {
  255. let data = await response.json()
  256. data.data.bookmark_timeline_v2.timeline.instructions[0].entries.forEach((item) => {
  257.  
  258. if (item.entryId.includes('tweet')) {
  259. TweetsXer.dCount++
  260. TweetsXer.bookmarks.push(item.content.itemContent.tweet_results.result)
  261. } else if (item.entryId.includes('cursor-bottom')) {
  262. if (TweetsXer.bookmarksNext != item.content.value) {
  263. TweetsXer.bookmarksNext = item.content.value
  264. } else {
  265. TweetsXer.bookmarksNext = ''
  266. }
  267. }
  268. })
  269. console.log(TweetsXer.bookmarks)
  270. //document.getElementById('progressbar').setAttribute('value', TweetsXer.dCount)
  271. document.getElementById("info").textContent = `${TweetsXer.dCount} Bookmarks collected`
  272. } else {
  273. console.log(response)
  274. }
  275.  
  276. if (response.headers.get('x-rate-limit-remaining') < 1) {
  277. console.log('rate limit hit')
  278. let ratelimitreset = response.headers.get('x-rate-limit-reset')
  279. let sleeptime = ratelimitreset - Math.floor(Date.now() / 1000)
  280. while (sleeptime > 0) {
  281. sleeptime = ratelimitreset - Math.floor(Date.now() / 1000)
  282. document.getElementById("info").textContent = `Ratelimited. Waiting ${sleeptime} seconds. ${TweetsXer.dCount} deleted.`
  283. await TweetsXer.sleep(1000)
  284. }
  285. }
  286. }
  287. let download = new Blob([JSON.stringify(TweetsXer.bookmarks)], {
  288. type: 'text/plain'
  289. })
  290. let bookmarksDownload = document.createElement("a")
  291. bookmarksDownload.id = 'bookmarksDownload'
  292. bookmarksDownload.innerText = 'Download'
  293. bookmarksDownload.href = window.URL.createObjectURL(download)
  294. bookmarksDownload.download = 'twitter-bookmarks.json'
  295. document.getElementById('advanced').appendChild(bookmarksDownload)
  296. },
  297.  
  298. createProgressBar() {
  299. let progressbar = document.createElement("progress")
  300. progressbar.setAttribute('id', "progressbar")
  301. progressbar.setAttribute('value', this.dCount)
  302. progressbar.setAttribute('max', this.total)
  303. progressbar.setAttribute('style', 'width:100%')
  304. document.getElementById(this.dId).appendChild(progressbar)
  305. },
  306.  
  307. async deleteFavs() {
  308. // 500 unfavs per 15 Minutes
  309. // x-rate-limit-remaining
  310. // x-rate-limit-reset
  311. while (!('authorization' in this.lastHeaders)) {
  312. await TweetsXer.sleep(1000)
  313. }
  314. TweetsXer.username = document.location.href.split('/')[3]
  315.  
  316. while (this.tIds.length > 0) {
  317. this.tId = this.tIds.pop()
  318. let response = await fetch(this.unfavURL, {
  319. "headers": {
  320. "accept": "*/*",
  321. "accept-language": 'en-US,en;q=0.5',
  322. "authorization": this.lastHeaders.authorization,
  323. "content-type": "application/json",
  324. "sec-fetch-dest": "empty",
  325. "sec-fetch-mode": "cors",
  326. "sec-fetch-site": "same-origin",
  327. "x-client-transaction-id": this.lastHeaders['X-Client-Transaction-Id'],
  328. "x-client-uuid": this.lastHeaders['x-client-uuid'],
  329. "x-csrf-token": this.lastHeaders['x-csrf-token'],
  330. "x-twitter-active-user": "yes",
  331. "x-twitter-auth-type": "OAuth2Session",
  332. "x-twitter-client-language": 'en'
  333. },
  334. "referrer": `https://x.com/${this.username}/likes`,
  335. "referrerPolicy": "strict-origin-when-cross-origin",
  336. "body": `{\"variables\":{\"tweet_id\":\"${this.tId}\"},\"queryId\":\"${this.unfavURL.split('/')[6]}\"}`,
  337. "method": "POST",
  338. "mode": "cors",
  339. "credentials": "include"
  340. })
  341.  
  342. if (response.status == 200) {
  343. TweetsXer.dCount++
  344. TweetsXer.updateProgressBar()
  345. } else {
  346. console.log(response)
  347. }
  348.  
  349. if (response.headers.get('x-rate-limit-remaining') < 1) {
  350. console.log('rate limit hit')
  351. let ratelimitreset = response.headers.get('x-rate-limit-reset')
  352. let sleeptime = ratelimitreset - Math.floor(Date.now() / 1000)
  353. while (sleeptime > 0) {
  354. sleeptime = ratelimitreset - Math.floor(Date.now() / 1000)
  355. document.getElementById("info").textContent = `Ratelimited. Waiting ${sleeptime} seconds. ${TweetsXer.dCount} deleted.`
  356. await TweetsXer.sleep(1000)
  357. }
  358. }
  359. }
  360. },
  361.  
  362. async deleteTweets() {
  363. while (!('authorization' in this.lastHeaders)) {
  364. await TweetsXer.sleep(1000)
  365. }
  366. TweetsXer.username = document.location.href.split('/')[3]
  367.  
  368. while (this.tIds.length > 0) {
  369. this.tId = this.tIds.pop()
  370. let response = await fetch(this.deleteURL, {
  371. "headers": {
  372. "accept": "*/*",
  373. "accept-language": 'en-US,en;q=0.5',
  374. "authorization": this.lastHeaders.authorization,
  375. "content-type": "application/json",
  376. "sec-fetch-dest": "empty",
  377. "sec-fetch-mode": "cors",
  378. "sec-fetch-site": "same-origin",
  379. "x-client-transaction-id": this.lastHeaders['X-Client-Transaction-Id'],
  380. "x-client-uuid": this.lastHeaders['x-client-uuid'],
  381. "x-csrf-token": this.lastHeaders['x-csrf-token'],
  382. "x-twitter-active-user": "yes",
  383. "x-twitter-auth-type": "OAuth2Session",
  384. "x-twitter-client-language": 'en'
  385. },
  386. "referrer": `https://x.com/${this.username}/with_replies`,
  387. "referrerPolicy": "strict-origin-when-cross-origin",
  388. "body": `{\"variables\":{\"tweet_id\":\"${this.tId}\",\"dark_request\":false},\"queryId\":\"${this.deleteURL.split('/')[6]}\"}`,
  389. "method": "POST",
  390. "mode": "cors",
  391. "credentials": "include"
  392. })
  393. if (response.status == 200) {
  394. TweetsXer.dCount++
  395. TweetsXer.updateProgressBar()
  396. }
  397. else if (response.status == 429) {
  398. this.tIds.push(this.tId)
  399. console.log('Received status code 429. Waiting for 1 second before trying again.')
  400. await TweetsXer.sleep(1000)
  401. }
  402. else {
  403. console.log(response)
  404. }
  405. }
  406. },
  407.  
  408. async getTweetCount() {
  409. await waitForElemToExist('header')
  410. await TweetsXer.sleep(1000)
  411. try {
  412. document.querySelector('[data-testid="AppTabBar_Profile_Link"]').click()
  413. } catch (error) {
  414. if (document.querySelector('[aria-label="Back"]')) {
  415. document.querySelector('[aria-label="Back"]').click()
  416. await TweetsXer.sleep(1000)
  417. }
  418.  
  419. if (document.querySelector('[data-testid="app-bar-back"]')) {
  420. document.querySelector('[data-testid="app-bar-back"]').click()
  421. await TweetsXer.sleep(1000)
  422. }
  423. document.querySelector('[data-testid="DashButton_ProfileIcon_Link"]').click()
  424. await TweetsXer.sleep(1000)
  425. document.querySelector('[aria-label="Account"] a').click()
  426. }
  427. await waitForElemToExist('[data-testid="UserName"]')
  428. await TweetsXer.sleep(500)
  429.  
  430. try {
  431. TweetsXer.TweetCount = document.querySelector('[aria-label="Home timeline"]>div>div')
  432. .textContent.match(/((\d|,|\.|K)+) posts$/)[1]
  433. .replace(/\.(\d+)K/, '$1'.padEnd(4, '0'))
  434. .replace('K', '000')
  435. .replace(',', '')
  436. } catch (error) {
  437. TweetsXer.TweetCount = document.querySelector('[data-testid="TopNavBar"]>div>div')
  438. .textContent.match(/((\d|,|\.|K)+) posts$/)[1]
  439. .replace(/\.(\d+)K/, '$1'.padEnd(4, '0'))
  440. .replace('K', '000')
  441. .replace(',', '')
  442. }
  443. console.log(TweetsXer.TweetCount + " Tweets on profile.")
  444. console.log("You can close the console now to reduce the memory usage.")
  445. console.log("Reopen the console if there are issues to see if an error shows up.")
  446. },
  447.  
  448. async slowDelete() {
  449. document.getElementById("toggleAdvanced").click()
  450. document.getElementById('start').remove()
  451. TweetsXer.total = TweetsXer.TweetCount
  452. TweetsXer.createProgressBar()
  453.  
  454. document.querySelectorAll('[data-testid="ScrollSnap-List"] a')[1].click()
  455. await TweetsXer.sleep(2000)
  456.  
  457. let unretweet, confirmURT, caret, menu, confirmation
  458.  
  459. const more = '[data-testid="tweet"] [aria-label="More"][data-testid="caret"]'
  460. while (document.querySelectorAll(more).length > 0) {
  461.  
  462. // give the Tweets a chance to load; increase/decrease if necessary
  463. // afaik the limit is 50 requests per minute
  464. await TweetsXer.sleep(1200)
  465.  
  466. // hide recommended profiles and stuff
  467. document.querySelectorAll('[aria-label="Profile timelines"]+section [data-testid="cellInnerDiv"]>div>div>div').forEach(x => x.remove())
  468. document.querySelectorAll('[aria-label="Profile timelines"]+section [data-testid="cellInnerDiv"]>div>div>[role="link"]').forEach(x => x.remove())
  469. document.querySelector('[aria-label="Profile timelines"]').scrollIntoView({
  470. 'behavior': 'smooth'
  471. })
  472.  
  473. // if it is a Retweet, unretweet it
  474. unretweet = document.querySelector('[data-testid="unretweet"]')
  475. if (unretweet) {
  476. unretweet.click()
  477. confirmURT = await waitForElemToExist('[data-testid="unretweetConfirm"]')
  478. confirmURT.click()
  479. }
  480.  
  481. // delete Tweet
  482. else {
  483. caret = await waitForElemToExist(more)
  484. caret.click()
  485.  
  486. menu = await waitForElemToExist('[role="menuitem"]')
  487. if (menu.textContent.includes('@')) {
  488. // don't unfollow people (because their Tweet is the reply tab)
  489. caret.click()
  490. document.querySelector('[data-testid="tweet"]').remove()
  491. } else {
  492. menu.click()
  493. confirmation = await waitForElemToExist('[data-testid="confirmationSheetConfirm"]')
  494. if (confirmation) confirmation.click()
  495. }
  496. }
  497.  
  498. TweetsXer.dCount++
  499. TweetsXer.updateProgressBar()
  500.  
  501. // print to the console how many Tweets already got deleted
  502. // Change the 100 to how often you want an update.
  503. // 10 for every 10th Tweet, 1 for every Tweet, 100 for every 100th Tweet
  504. if (TweetsXer.dCount % 100 == 0) console.log(`${new Date().toUTCString()} Deleted ${TweetsXer.dCount} Tweets`)
  505.  
  506. }
  507.  
  508. console.log('No Tweets left. Please reload to confirm.')
  509. },
  510.  
  511. async unfollow() {
  512. //document.getElementById("toggleAdvanced").click()
  513. let unfollowCount = 0
  514. let next_unfollow, menu
  515.  
  516. document.querySelector('[href$="/following"]').click()
  517. await TweetsXer.sleep(1200)
  518.  
  519. const accounts = '[data-testid="UserCell"]'
  520. while (document.querySelectorAll('[data-testid="UserCell"] [data-testid$="-unfollow"]').length > 0) {
  521. next_unfollow = document.querySelectorAll(accounts)[0]
  522. next_unfollow.scrollIntoView({
  523. 'behavior': 'smooth'
  524. })
  525.  
  526. next_unfollow.querySelector('[data-testid$="-unfollow"]').click()
  527. menu = await waitForElemToExist('[data-testid="confirmationSheetConfirm"]')
  528. menu.click()
  529. next_unfollow.remove()
  530. unfollowCount++
  531. if (unfollowCount % 10 == 0) console.log(`${new Date().toUTCString()} Unfollowed ${unfollowCount} accounts`)
  532. await TweetsXer.sleep(Math.floor(Math.random() * 200))
  533. }
  534.  
  535. console.log('No accounts left. Please reload to confirm.')
  536. },
  537. removeTweetXer() {
  538. document.getElementById('exportUpload').remove()
  539. }
  540. }
  541.  
  542. const waitForElemToExist = async (selector) => {
  543. return new Promise(resolve => {
  544. if (document.querySelector(selector)) {
  545. return resolve(document.querySelector(selector))
  546. }
  547.  
  548. const observer = new MutationObserver(() => {
  549. if (document.querySelector(selector)) {
  550. resolve(document.querySelector(selector))
  551. observer.disconnect()
  552. }
  553. })
  554.  
  555. observer.observe(document.body, {
  556. subtree: true,
  557. childList: true,
  558. })
  559. })
  560. }
  561.  
  562. TweetsXer.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement