UserScript:Mandal-Art
マンダラート支援スクリプト
Mandal-Art.icon
code:script.js
scrapbox.PageMenu.addMenu({
title: 'Mandal-Art',
});
scrapbox.PageMenu('Mandal-Art').addItem({
title: "マンダラート",
});
scrapbox.PageMenu('Mandal-Art').addItem({
title: "マンダラ作成",
onClick: () => {
const project = scrapbox.Project.name;
const title = scrapbox.Page.title;
const body = `
table:mandal-art
1 2 3
4 ${title} 6
7 8 9`;
console.log(body);
window.open(https://scrapbox.io/${project}/${title}?body=${encodeURIComponent(body)}) }
});
scrapbox.PageMenu('Mandal-Art').addItem({
title: "画像作成",
onClick: async () => {
const project = scrapbox.Project.name;
const title = scrapbox.Page.title;
const svgfile = "mandal-art.svg";
const path = /api/table/${project}/${title}/mandal-art.csv
let res = await fetch(path)
.then(response => response.text())
.then(text => {
//console.log(text);
const tr = text.split("\n")
.map( line => {
//console.log(line)
const td = line.split(",")
.map( element => {
//console.log(element);
return <td>${element}</td>
})
.join('');
return \t\t<tr>${td}</tr>
})
.filter(line => line)
.join('\n');
//console.log(tr);
//console.log(<table>${tr}</table>);
const style=`<style type="text/css">
body{
font-weight:bold;
}
table{
width: 480px;
height:360px;
table-layout: fixed;
border-collapse:collapse;
margin:0 auto;
}
td,th{
width: 160px;
height:120px;
text-align: center;
vertical-align: middle;
background:#efffef;
border-bottom:1px solid #ccc; }
table tr th:nth-child(even),
table tr td:nth-child(even){
background:#ffffef;
}
</style>`;
const out1=code:${svgfile};
const out2=`
<foreignObject x="0" y="0" width="500" height="380">
<head>
${style}
</head>
<body>
<table>
${tr}
</table>
</body>
</html>
</foreignObject>
</svg>`;
//console.log(out);
const out3 = [https://svg-hosting.vercel.app/api/svg?url=https://scrapbox.io/api/code/${project}/${title}/${svgfile}];
const body = out1 + out2 + '\n' + out3;
console.log(body);
window.open(https://scrapbox.io/${project}/${title}?body=${encodeURIComponent(body)})
});
}
});
table:mandal-art
Mandal-Art.icon