-
-
Save nora-tetsu/aef2d3f5833eebcfe0358de3a8e191da to your computer and use it in GitHub Desktop.
Page Menuからstyle要素の追加・除去をトグルするUserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (){ | |
scrapbox.PageMenu.addMenu({ | |
title: '関連リンクを左に', | |
image: 'https://i.gyazo.com/7057219f5b20ca8afd122945b72453d3.png', // Scrapboxアイコン | |
onClick: () => { | |
const url = '/api/code/noratetsu/_CSS_related-page-list_left/style.css'; // CSSが書いてあるコードブロック | |
const styleId = 'related-left'; // 適当なidを設定する | |
const elm = document.getElementById(styleId); | |
if(elm){ // 既に設定されている時 | |
elm.remove(); // 除去する | |
}else{ // 設定されていない時 | |
fetch(url) // 指定したコードブロックの中身を取得 | |
.then(response => response.text()) | |
.then(text => { | |
// style要素にCSSの記述を入れてbody要素に追加する | |
const style = document.createElement('style'); | |
style.id = styleId; | |
style.append(document.createTextNode(text)); | |
document.body.append(style); | |
}); | |
}; | |
}, | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こちらを参考にしております。
ページの背景をリーガルパッド風にするUserScript - Scrapbox研究会