~simulacrumparty/latest-tweets

f25fb4d8ad705937816691782a57ac1d4c9ffc29 — Dylan Baker 1 year, 9 months ago master
Initial commit
8 files changed, 93 insertions(+), 0 deletions(-)

A .gitignore
A LICENSE
A README.md
A icons/128.png
A icons/16.png
A icons/48.png
A index.js
A manifest.json
A  => .gitignore +1 -0
@@ 1,1 @@
web-ext-artifacts/

A  => LICENSE +21 -0
@@ 1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Dylan Baker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

A  => README.md +8 -0
@@ 1,8 @@
# Latest Tweets

A browser extension that automatically sets your Twitter timeline to show the
latest tweets instead of leaving it up to the algorithm. I developed and tested
it with Firefox but I believe it works with Chrome too. Note that I can't
guarantee it works in Chrome and you'll have to install it yourself as I
haven't published it to the Chrome Web Store. You can install the Firefox
extension [here](https://addons.mozilla.org/en-US/firefox/addon/latest-tweets).

A  => icons/128.png +0 -0
A  => icons/16.png +0 -0
A  => icons/48.png +0 -0
A  => index.js +42 -0
@@ 1,42 @@
const switchToLatest = async () => {
  const waitForElements = async (els) => {
    return new Promise(async (resolve, reject) => {
      let counter = 0;
      while (true) {
        if (counter === 100) {
          return reject();
        }

        for (let el of els) {
          if (document.querySelector(el)) {
            return resolve(els.map((el) => document.querySelector(el)));
          }
        }

        await new Promise((resolve, _reject) => requestAnimationFrame(resolve));

        counter += 1;
      }
    });
  };

  const topTweetsOffSelector = '[aria-label="Top Tweets off"]';
  const topTweetsOnSelector = '[aria-label="Top Tweets on"]';
  const latestTweetsSelector = 'div[role="menuitem"]';

  waitForElements([topTweetsOnSelector, topTweetsOffSelector])
    .then((els) => {
      const [topTweetsOn, _topTweetsOff] = els;
      if (topTweetsOn) {
        topTweetsOn.click();
        waitForElements([latestTweetsSelector])
          .then((els) => {
            els.filter((el) => !!el).forEach((el) => el.click());
          })
          .catch(() => {});
      }
    })
    .catch(() => {});
};

switchToLatest();

A  => manifest.json +21 -0
@@ 1,21 @@
{
  "name": "Latest Tweets",
  "version": "0.0.3",
  "manifest_version": 2,
  "description": "Automatically switch back to latest tweets",
  "content_scripts": [
    {
      "matches": [
        "https://twitter.com/home"
      ],
      "js": [
        "index.js"
      ]
    }
  ],
  "icons": {
    "16": "icons/16.png",
    "48": "icons/48.png",
    "128": "icons/128.png"
  }
}