Adding shortcut keys to Safari on iPadOS with Userscripts, to open new tabs with your favorite website.

LEICA M-P (Typ 240) + Summicron 50mm f/2.0 Leitz

There's still no way to set any webpages as a homepage of Safari when opening new tabs or new windows on iPadOS. Maybe that'll never change in the future as well. So, I tried to consider if there's some ways to fix is.

🇯🇵 日本語 / ja

iPadOS の Safari は未だに新しいタブとかウインドウを開いた時に自分で好きなページをホームページとして設定できない。で、今後もそれは変わることがないんだろう。で、何か解決方法がないかなーって考えてみた。

My idea.

LEICA Q + Summilux 28mm f/1.7 (28mm)

This solution doesn't work when tapping a new tab button or using original shortcut key to open new tab "Command+T". But when using hardware keyboard like MagicKeyboard from Apple, this just works with no problem.

First of all, we need to install an app extension of Safari called "Userscripts". This extension allows us JavaScript written by ourselves when opening webpages. It has some more features, but I don't touch them here. If you want to know some more about it, please google it by yourself.

🇯🇵 日本語 / ja

この解決策は新しいタブボタンをタップしたり『Command+T』のショートカットキーで新しいタブを開いたりする場合は動かない。けど MagicKeyboard とかハードウェアキーボードを使っていれば問題なく動く。

まずしなきゃいけないのは『Userscripts』って Safari 拡張機能を入れること。この拡張機能はウェブページを開いた時に自分で書いた JavaScript を実行できるようにしてくれる。他にもいろんな機能があるんだけどここでは触れない。知りたい人は各自で調べてもらえれば。

Userscript needs to be installed both of Safari on iPad and Safari on Mac. And when you're ready, try creating new JavaScript file on Userscripts on Mac and paste the code below to the JavaScript file. One more thing, give a permission to that JavaScript file to run on all of the websites.

🇯🇵 日本語 / ja

Userscripts は iPad と Mac の両方の Safari に をインストールしておく必要がある。で、準備ができたら新しい JavaScript ファイルを Mac の Userscripts で作って、以下のコードを貼り付ける。あともうひとつ、全てのウェブサイトでその JavaScript が実行されるようにパーミッションを与えること。

addEventListener("keydown", (event) => {
if ( event.key == 'z' && event.ctrlKey == true ) {
window.open("URL OF YOUR FAVORITE WEBPAGE")
}
})

Then we get to be able to open a webpage set on the JavaScript file with a new tab, using a shortcut key "Ctrl+Z" defined on the same JavaScript file. It seems to be unable to be overridden and not work with shortcut keys defined originally like "Command+T", but we can define as shortcut keys except them. By the way, the JavaScript file runs after webpages get loaded, so it doesn't work during loading.

If you get interested in this, try it. So see you then.

🇯🇵 日本語 / ja

これで JavaScript ファイルで設定したウェブページを『Ctrl+Z』のショートカットキーを使って新しいタブで開くことができるようになる。『Command+T』みたいな元々定義されているショートカットキーを上書きすることはできないみたいだけど、それ以外なら定義できる。ちなみにこの JavaScript はウェブページが読み込まれた後に実行されるから読み込み中は動かない。

興味があったら試してみてください。ほなまた。