2021-08-06 One click generates the following page
Intended use.
Comparison with previous version [ScrapboxSRS
I used it. - Reflections on "2021-08-05 Reflection"
[/takker/Scrapbox lookback feature#610c18a51280f00000ed3fc3](https://scrapbox.io/takker/Scrapbox lookback feature#610c18a51280f00000ed3fc3).
I changed the external project link notation so that the link does not appear in the related pages list even if the link remains.
2021-08-06 script.js
const LINE_PER_SECTION = 3;
const day = 60 * 60 * 24 * 1000;
const year = day * 365;
const project_name = scrapbox.Project.name;
const project_root = `https://scrapbox.io/${project_name}`;
const menu_title = "Looking Back";.
const make_title = () => `${strftime(new Date())}${menu_title}`;
// score: 0 is best
const sections = [
{
title: "100 days ago",.
score: (diff) => Math.abs(diff - 100 * day),
},
{
title: "1 year ago",.
score: (diff) => Math.abs(diff - year),
},
{
title: "n years ago",.
score: (diff) => {
// excludes 1 year ago
if (diff < year * 1.5) {
return year;
}
const mod = diff % year;
return Math.min(mod, year - mod);
},
},
];
const main = () => {
// calc scores
const now = Date.now();
const scored_pages = [];
scrapbox.Project.pages.forEach((page) => {
const updated = page.updated;
if (updated === 0) return;
const diff = now - updated * 1000;
const p = { ...page };
sections.forEach((sction) => {
p[sction.title] = sction.score(diff);
});
scored_pages.push(p);
});
// generate page contents
const lines = [];
sections.forEach((section) => {
scored_pages.sort((a, b) => a[section.title] - b[section.title]);
lines.push(section.title);
scored_pages.slice(0, LINE_PER_SECTION).forEach((page) => {
const title = page["title"];
const date = strftime(new Date(page.updated * 1000));
lines.push(` ${date} [${title}]`);
});
lines.push("");
});
create_page(make_title(), lines);
};
function create_page(title, lines) {
const body = encodeURIComponent(lines.join("\n"));
window.open(`${project_root}/${title}?body=${body}`);
}
function pad(number) {
if (number < 10) {
return "0" + number;
}
return number;
}
function strftime(d) {
return (
d.getUTCFullYear() +
"-" +
pad(d.getUTCMonth() + 1) +
"-" +
pad(d.getUTCDate())
);
}
const WAIT = { title: "Please wait...", image: null, onClick: () => null };
const onClick = () => {
scrapbox.PageMenu(menu_title).addItem(WAIT);
main();
scrapbox.PageMenu(menu_title).removeAllItems();
};
scrapbox.PageMenu.addMenu({
title: menu_title,
image: "https://gyazo.com/11140c8b35b407c5d490a94ec6f2528f/raw",
onClick,
});
old version
orthographical variants - Reflection (Scrapbox)
This page is auto-translated from /nishio/Scrapbox振り返り機能 using DeepL. 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.