xxxxx_
code:episopass.js
javascript:(function(){
var nquestions = 10;
async function episoq() {
var questions = [];
var answers = [];
var project = scrapbox.Project.name;
var res = await fetch('/api/users/me');
var data = await(res.json());
var username = data.name;
res = await fetch(/api/pages/${project}?limit=1000);
data = await res.json();
data.pages.forEach ( page => {
var title = page.title;
if(title.match(/^_/) || title.match(/_$/) || title == username || title == 'settings' || page.pin != 0){
}
else {
if(title.match(/\?$/)){
questions.push(title);
}
else {
answers.push(title);
}
}
})
answers = answers.sort().map ((e) => e.match(/^(\w+\s+)?(.*)$/)2; );
var qstr = questions.sort(() => 0.5 - Math.random()).slice(0,nquestions).join(';');
var astr = answers.join(';');
location.href = http://episopass.com/?questions=${qstr}&answers=${astr}&n=${nquestions};
}
document.addEventListener('keydown', e => {
if (e.key == 'c' && e.ctrlKey){ // Ctrl-Cで実行
nquestions = Number(window.prompt('問題の数を指定してください','10'))
if (nquestions != 0){
episoq()
}
}
})
}()