Skip to content

Instantly share code, notes, and snippets.

@hidao80
Created July 26, 2023 11:15
Show Gist options
  • Save hidao80/664d5484ebc694fd27169b9c85d9b38d to your computer and use it in GitHub Desktop.
Save hidao80/664d5484ebc694fd27169b9c85d9b38d to your computer and use it in GitHub Desktop.
Pixiv のページ切替時に同じ処理を繰り返すブックマークレット
javascript:new MutationObserver((()=>{const i=document.querySelector("#root>div>div>div:nth-child(4)>div>div>div>main>section>div>div>figure>div>div>div>div>img");i&&(i.style.filter="blur(4px)")})).observe(document.getElementById("root"),{subtree:!0,childList:!0});
// オブザーバーを使って画面の内容が1項目編集されるたびに内部の関数を実行する
new MutationObserver(() => {
// 中央の画像を監視して、中央の画像が描画されたら中央の画像に対する処理を実行する
// 監視対象にする要素は用途に合わせてCSSセレクタで指定してください
const elem = document.querySelector("#root>div>div>div:nth-child(4)>div>div>div>main>section>div>div>figure>div>div>div>div>img");
if (elem) {
// ためしに4px分のぼかしを入れるスタイルを適用する
// ここを任意の処理に書き換える
elem.style.filter="blur(4px)";
}
// id="root"要素の内容に変化があった時、上記無名関数を実行する →childList: true
// 直下の要素以下の孫やその子要素すべての要素が対象 →subtree: true
}).observe(document.getElementById('root'), {subtree: true, childList: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment