共通UserScript
使用しているUserScript一覧
AutoBracketter
正規表現を自由に入力して置換する右クリックメニュー
addLinkedListCopyButton
現在のページをリンクしているページ一覧をブラケットに囲って一列でクリップボードに保存する
favicon を旧Scrapboxアイコンに変更
右メニューにしおり記法へのリンク追加
数式ブラケット
キーボードのキー
ブラケティングの解除
選択範囲内のブラケティングを解除する
code:script.js
import '/api/code/my-knowledge/AutoBracketter/script.js';
import '/api/code/my-knowledge/正規表現を自由に入力して置換する右クリックメニュー/script.js';
// addLinkedListCopyButton
scrapbox.PageMenu.addMenu({
title: 'LinkList',
image: '/assets/img/logo.png',
onClick: () => getLinksAndCopy(),
});
function getLinksAndCopy(e) {
const decodeTitle = decodeURI(window.location).match(/^\/+$/)0;
const api = https://scrapbox.io/api/pages/my-knowledge/${decodeTitle};
fetch(api)
.then(d=>d.json())
.then(json=>{
const links = json[relatedPages][links1hop];
const linksTxt = links.map(e=>[${e["title"]}]).join("\n");
copyToClipbord(linksTxt);
})
.catch(error=>{
console.log(error!);
console.error(error);
});
function copyToClipbord(txt) {
if (!txt) return window.prompt(リンクされているページがありません);
setTimeout(() => navigator.clipboard.writeText(txt), 100);
return;
if (navigator.clipbord) {
return navigator.clipbord.writeText(txt);
}else {
console.log(copy failed!);
popupDisplay(txt);
return;
}
}
function popupDisplay(txt) {
window.prompt(コピーに失敗したため Ctrl + C を押して自力でコピーしてください, txt);
}
}
// favicon を旧Scrapboxに変更
document.querySelector(link[href="https://scrapbox.io/assets/img/favicon/favicon.ico"])?.remove();
const l = document.createElement(link);
l.id = favicon;
l.rel = icon;
l.href = https://i.gyazo.com/7057219f5b20ca8afd122945b72453d3.png;
document.head.appendChild(l);
// 右メニューにしおり記法へのリンク追加
const __bkmClass = '.deco-\\.' /* ここで記法のセレクタを設定してね。デフォルトはドットです */
const __bkmMenuTitle = 'Bookmarks'
scrapbox.PageMenu.addMenu({ title: __bkmMenuTitle, image: '/assets/img/logo.png',
onClick: function() {
const __fixedHeaderHeight = ($('.navbar').css('position') == 'fixed' ? $('.navbar').height() : 0)
+ ($('.navbar-pagemenu').height() || 0)
scrapbox.PageMenu(__bkmMenuTitle).removeAllItems()
$(__bkmClass).closest('.line').each(function(i, e){
scrapbox.PageMenu(__bkmMenuTitle).addItem({
title: $(e).find(__bkmClass).text(),
onClick: function() {
$('html,body').animate({
scrollTop: $(e).offset().top - $('body').offset().top - __fixedHeaderHeight - 100
}, 150)
}
})
})
}
})
// 数式ブラケット
scrapbox.PopupMenu.addButton({
title: '$',
onClick: text => [$ ${text} ]
})
// キーボードのキー
scrapbox.PopupMenu.addButton({
title: '>',
onClick: text => [> [${text}]]
})
// ブラケティングの解除
scrapbox.PopupMenu.addButton({
title: '][',
onClick: text => text.replace(/\[(^\]+)\]/g, "$1")
})
検証中!/progfay-pub/Replace_Text_UserScript
まだ検証中
code:sample.js
const replaceText = text => {
const splitPos = text.indexOf('\n\n')
const commands = text.substr(0, splitPos).split('\n').map(command => {
const before = '', after = '' = command.split(' => ', 2)
return { before, after }
})
let lines = text.substr(splitPos + 2).split('\n')
for (const { before, after } of commands) {
const match = before.match(new RegExp('^/(.*?)/(gimy*)$'))
const reg = match ? new RegExp(match1, match2) : before
lines = lines.map(line => line.replace(reg, after.replace(/\\n/g, '\n')))
}
return lines.join('\n')
}
scrapbox.PopupMenu.addButton({
title: 'replace',
onClick: replaceText
})
#Scrapbox #JavaScript