parmodule
https://gyazo.com/5a423052c14d631aa9254180b4487370
scrapbox utilities (2)
this is parmodule’s page
強調表示
code:style.css
/* 二重括弧による強調をマーカーっぽくする */
.line strong:not(class) { background: linear-gradient(transparent 10%, #fff33f 25%, #fff33f 70%, transparent 90%) }
code:script.js
// 選択した文字列にマーカー
scrapbox.PopupMenu.addButton({
title: 'マーカー',
onClick: text => [[${text}]]
})
関連ページを一気に取得する
code:script.js
const makepage = function () {
const url = location.href.replace("io/", "io/api/pages/");
let x = new XMLHttpRequest();
x.open("get", url, false);
x.send(null);
let json = x.responseText;
let pagedata = JSON.parse( json );
let relatedPagesDatalinks1hop = relatedPagesData"links1hop"; //ループで回して、関連ページの本文を取得していく
let pageContents = [];
let rooturl = location.href.replace("io/", "io/api/pages/").replace(new RegExp("/" + encodeURI(scrapbox.Page.title) + "$"),"/");
for (let i = 0, len = relatedPagesDatalinks1hop.length; i < len; ++i) {
let relatedurl = rooturl + relatedPagesDatalinks1hopi"title" + "/text"; //これでXMLHttpRequestを回していく
let y = new XMLHttpRequest();
y.open("get", relatedurl, false);
y.send(null);
let c = y.responseText;
c = removehashtag(c,scrapbox.Page.title); //もとハッシュタグを削除しない場合はこの行をコメントアウト
c = removebracket(c)//本文中からブラケット[]を取り除かない場合はこの行をコメントアウト
pageContents.push(addmargin(c));
}
//取得したページの中身を使って、新しいwindowをオープンする。
var win = window.open();
win.document.open();
win.document.write(<title>temporary</title>);
win.document.write('<pre>');
win.document.write(pageContents.join('\n'));
win.document.write('</pre>');
win.document.close();
}
function removehashtag(text,pageTitle){//本文中からもともとのハッシュタグを削除する
return text.replace(new RegExp('#' + scrapbox.Page.title),"")
}
function removebracket(text){//本文中から閉じと開きのブラケットを削除する
return text.replace(/\|\/g,"") }
function addmargin(text){ //二行目以降に半角スペースを追加する
return text.replace(/\n/g,"\n ")
}
scrapbox.PageMenu.addMenu({
title: '関連ページ取得',
onClick:makepage
})
ページ背景をリーガルパッド風にする
code:script.js
scrapbox.PageMenu.addItem({
title: 'legalpad',
onClick: (e) => {
var bg = '#F2F5A9' // ここにお好きな背景色を入れてね(テーマの背景が黒なら black で)#F2F5A9
var style = document.getElementById('__legal__')
if (style) { style.remove(); e.currentTarget.innerText = 'legalpad mode'; return }
else e.currentTarget.innerText = String.fromCharCode(0x02713) + ' legalpad mode'
var css = .page { background-color:${bg} !important; background-image:none !important; } + '.line{border-bottom:1px solid #000000;}' style = document.createElement('style')
style.setAttribute('id', '__legal__')
style.appendChild(document.createTextNode(css))
document.head.appendChild(style)
}
})
新書モード
code:style.css
.col-page.paperback {
max-width: 600px;
}
code:script.js
scrapbox.PageMenu.addItem({
title: '📙新書モード',
onClick: () => {
const className = 'paperback'
const colPage = document.querySelector('.col-page')
colPage.classList.contains(className) ?
colPage.classList.remove(className) : colPage.classList.add(className)
// 関連ページカードの横幅を再計算させる
requestAnimationFrame(() => {dispatchEvent(new Event('resize'))})
}
})
書くだけのモードにする
code:script.js
let isInputMode = true;
const enterInputMode = (e) => {
if (!isInputMode) {
if (e) {
e.preventDefault();
}
$("#text-input").prop('disabled', false);
$("#text-input").focus();
$('.page').css('background', '');
isInputMode = !isInputMode;
}
}
const exitInputMode = (e) => {
if (isInputMode) {
$("#text-input").prop('disabled', true);
$('.page').css('background', '#dadada');
isInputMode = !isInputMode;
}
}
const modeSelectors = {
true: exitInputMode,
false: enterInputMode,
}
scrapbox.PageMenu.addMenu({
title: 'Input mode',
onClick: () => {
},
});
$(window).keydown((e) => {
if (e.keyCode === 73) { // key code of "i"
enterInputMode(e);
}
if (e.keyCode === 27) { // key code of Esc
exitInputMode(e);
}
});
exitInputMode();
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon
/icons/hr.icon