LoginSignup
1
2

More than 1 year has passed since last update.

年末年始にTV見ながらTwitter眺めてた時に、いちいちリロードするのめんどいのでChrome拡張作ってみた

Last updated at Posted at 2022-01-01

年末年始ひまだったのでずっとTV見ていてTwitterで世間のリアクションも併せて見ていたんですが、Twitterには自動で更新してくれる機能がなく画面リロードするのがめんどくさいのでChrome拡張で勝手に画面リロードするようにしてみました。

Chrome拡張作成

今回は以下のようなディレクトリ構成で作成します

  • chrome-extension-reload
    • manifest.json
    • content.js

マニフェストファイルはTwitterの最新タグを開いてる時だけ動くようにf=liveを指定しています。
matchesの部分を変えればいろんな場面で使えるようになります。

manifest.json
{
    "name": "Auto Reloader",
    "version": "1.0.0",
    "manifest_version": 2,
    "description": "auto reload per 15 sec.",
    "content_scripts": [
        {
            "matches": [
                "https://twitter.com/*f=live"
            ],
            "js": [
                "content.js"
            ]
        }
    ]
}

実際に実行されるJavascriptファイルです。
15秒後にリロードするだけです。

content.js
(function () {
    setTimeout(() => location.reload(), 15000);
})();

Chrome拡張アップロード

chrome://extensions/を開いて、パッケージ化されていない拡張機能を読み込むから作成したディレクトリを選択します

image.png

 ↓こんな感じで自作の拡張機能が追加されます

image.png

あとはTwitterで最新タブを開くと勝手にリロードされるようになります。

image.png

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2