A browser extension that automatically sets your Twitter timeline to show the latest tweets
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const switchToLatest = async () => {
  2. const waitForElements = async (els) => {
  3. return new Promise(async (resolve, reject) => {
  4. let counter = 0;
  5. while (true) {
  6. if (counter === 100) {
  7. return reject();
  8. }
  9. for (let el of els) {
  10. if (document.querySelector(el)) {
  11. return resolve(els.map((el) => document.querySelector(el)));
  12. }
  13. }
  14. await new Promise((resolve, _reject) => requestAnimationFrame(resolve));
  15. counter += 1;
  16. }
  17. });
  18. };
  19. const topTweetsOffSelector = '[aria-label="Top Tweets off"]';
  20. const topTweetsOnSelector = '[aria-label="Top Tweets on"]';
  21. const latestTweetsSelector = 'div[role="menuitem"]';
  22. waitForElements([topTweetsOnSelector, topTweetsOffSelector])
  23. .then((els) => {
  24. const [topTweetsOn, _topTweetsOff] = els;
  25. if (topTweetsOn) {
  26. topTweetsOn.click();
  27. waitForElements([latestTweetsSelector])
  28. .then((els) => {
  29. els.filter((el) => !!el).forEach((el) => el.click());
  30. })
  31. .catch(() => {});
  32. }
  33. })
  34. .catch(() => {});
  35. };
  36. switchToLatest();