ScrapboxSRS
code:script.js
const sortMode = 'log' // Interval Iteration Method
let visibleRankNum = 100; // ignored except for log
const day = 60 * 60 * 24 * 1000
const year = day * 365
let projectPages;
function get_data(){
let xhr = new XMLHttpRequest()
xhr.open('GET', /api/pages/${scrapbox.Project.name}?limit=10000)
xhr.onload = (e) => {
projectPages = JSON.parse(xhr.responseText).pages
sort_pages()
update_list()
}
xhr.send(null)
}
function sort_pages(){
const now = Date.now()
projectPages.forEach((page, index, pages) => {
if(diff > 10 * day){
page'score' = (Math.log(diff / (10 * day)) / Math.log(2)) % 1 page'ago' = Math.floor(diff / day) }
})
projectPages = projectPages.filter(page => (page'score' != null)) }
function create_page(title, lines){
const projectRoot = (() => {
const tmp = location.href.split('/')
tmp.pop()
return tmp.join('/')
})()
const body = encodeURIComponent(lines.join('\n'))
window.open(${projectRoot}/${title}?body=${body})
}
function update_list(){
scrapbox.PageMenu('Scrapbox Sort').removeAllItems()
let page_lists = [];
for (let i = 0; i < visibleRankNum; i++) {
if(page == null) break;
page_lists.push(${strftime(new Date(page.updated * 1000))}(${page['ago']}) [${page['title']}])
}
create_page("SRS" + new Date().toISOString().slice(0, 19), page_lists)
}
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
function strftime(d){
return (
d.getUTCFullYear() +
'-' + pad(d.getUTCMonth() + 1) +
'-' + pad(d.getUTCDate())
)
}
scrapbox.PageMenu.addMenu({
title: 'Scrapbox SRS',
onClick: () => {
scrapbox.PageMenu('Scrapbox SRS').addItem({ title: 'Please wait...', image: null, onClick: () => null })
get_data();
scrapbox.PageMenu('Scrapbox Sort').removeAllItems()
}
})
---
This page is auto-translated from /nishio/ScrapboxSRS. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.