From be946ee4732ed0fed229601e22b74bb6628bce5f Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Fri, 22 Apr 2022 21:26:36 +0900 Subject: [PATCH] create scripts --- README.md | 21 +++++++++++++++++++++ amazon-shorten.user.js | 9 +++++++++ github-tab-size.user.js | 14 ++++++++++++++ twimg-shorten.user.js | 11 +++++++++++ 4 files changed, 55 insertions(+) create mode 100644 README.md create mode 100644 amazon-shorten.user.js create mode 100644 github-tab-size.user.js create mode 100644 twimg-shorten.user.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..53d027a --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# UserScript + +## github-tab-size.user.js + +GitHub のタブの表示幅を変える + +デフォルトの幅は 8 だが広すぎるように感じた\ +雑だが適当な UserScript を書いて拡張機能として追加した\ +Chrome はデフォルトでいまも UserScript をサポートしており、\*.user.js ファイルをドラッグアンドドロップすると使える + +## amazon-shorten.user.js + +Amazon (amazon.co.jp) の商品 URL を短縮する + +## twimg-shorten.user.js + +Twitter の画像 URL を短縮する + +## ライセンス + +MIT License diff --git a/amazon-shorten.user.js b/amazon-shorten.user.js new file mode 100644 index 0000000..f9240aa --- /dev/null +++ b/amazon-shorten.user.js @@ -0,0 +1,9 @@ +// ==UserScript== +// @match https://www.amazon.co.jp/* +// ==/UserScript== +"use strict"; + +const { pathname } = window.location; +const dp = pathname.match(/(?<=\/(?:dp|gp\/product)\/)\w*/)?.[0]; +const to = dp && `/dp/${dp}`; +if (to && pathname !== to) window.history.replaceState(null, "", to); diff --git a/github-tab-size.user.js b/github-tab-size.user.js new file mode 100644 index 0000000..ed9a679 --- /dev/null +++ b/github-tab-size.user.js @@ -0,0 +1,14 @@ +// ==UserScript== +// @match https://github.com/* +// ==/UserScript== +"use strict"; + +const { body } = window.document; + +function main() { + const el = body.querySelector(".tab-size"); + if (el) el.dataset.tabSize = "2"; +} + +new MutationObserver(main).observe(body, { childList: true }); +main(); diff --git a/twimg-shorten.user.js b/twimg-shorten.user.js new file mode 100644 index 0000000..d45068a --- /dev/null +++ b/twimg-shorten.user.js @@ -0,0 +1,11 @@ +// ==UserScript== +// @match https://pbs.twimg.com/media/* +// ==/UserScript== +"use strict"; + +const { pathname, search } = window.location; +const params = new URLSearchParams(search); +const name = params.get("name"); +const format = params.get("format"); +const to = format && `${pathname}.${format}${name === "large" ? ":orig" : ""}`; +if (to && pathname !== to) window.history.replaceState(null, "", to);