Browse Source

Initial commit

master
Dylan Baker 4 years ago
commit
f25fb4d8ad
8 changed files with 93 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 21
    0
      LICENSE
  3. 8
    0
      README.md
  4. BIN
      icons/128.png
  5. BIN
      icons/16.png
  6. BIN
      icons/48.png
  7. 42
    0
      index.js
  8. 21
    0
      manifest.json

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+web-ext-artifacts/

+ 21
- 0
LICENSE View File

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2019 Dylan Baker
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in
13
+all copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+THE SOFTWARE.

+ 8
- 0
README.md View File

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

BIN
icons/128.png View File


BIN
icons/16.png View File


BIN
icons/48.png View File


+ 42
- 0
index.js View File

@@ -0,0 +1,42 @@
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
+
10
+        for (let el of els) {
11
+          if (document.querySelector(el)) {
12
+            return resolve(els.map((el) => document.querySelector(el)));
13
+          }
14
+        }
15
+
16
+        await new Promise((resolve, _reject) => requestAnimationFrame(resolve));
17
+
18
+        counter += 1;
19
+      }
20
+    });
21
+  };
22
+
23
+  const topTweetsOffSelector = '[aria-label="Top Tweets off"]';
24
+  const topTweetsOnSelector = '[aria-label="Top Tweets on"]';
25
+  const latestTweetsSelector = 'div[role="menuitem"]';
26
+
27
+  waitForElements([topTweetsOnSelector, topTweetsOffSelector])
28
+    .then((els) => {
29
+      const [topTweetsOn, _topTweetsOff] = els;
30
+      if (topTweetsOn) {
31
+        topTweetsOn.click();
32
+        waitForElements([latestTweetsSelector])
33
+          .then((els) => {
34
+            els.filter((el) => !!el).forEach((el) => el.click());
35
+          })
36
+          .catch(() => {});
37
+      }
38
+    })
39
+    .catch(() => {});
40
+};
41
+
42
+switchToLatest();

+ 21
- 0
manifest.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "name": "Latest Tweets",
3
+  "version": "0.0.3",
4
+  "manifest_version": 2,
5
+  "description": "Automatically switch back to latest tweets",
6
+  "content_scripts": [
7
+    {
8
+      "matches": [
9
+        "https://twitter.com/home"
10
+      ],
11
+      "js": [
12
+        "index.js"
13
+      ]
14
+    }
15
+  ],
16
+  "icons": {
17
+    "16": "icons/16.png",
18
+    "48": "icons/48.png",
19
+    "128": "icons/128.png"
20
+  }
21
+}

Loading…
Cancel
Save