generated at
UserScript:Mandal-Art

マンダラート支援スクリプト
Mandal-Art

script.js
scrapbox.PageMenu.addMenu({ title: 'Mandal-Art', image: 'https://scrapbox.io/api/pages/suto3/Mandal-Art/icon' }); scrapbox.PageMenu('Mandal-Art').addItem({ title: "マンダラート", onClick: () => location.href = "https://scrapbox.io/suto3/Scrapboxでマンダラート" }); 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=` <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 380" width="500" height="380"> <foreignObject x="0" y="0" width="500" height="380"> <html xmlns="http://www.w3.org/1999/xhtml"> <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)}`) }); } });


Mandal-Art