script.jsasync function F(e){return(await B(e)).flatMap(r=>/\d{4}\/\d{2}\/\d{2}/.test(r.title)?[{pageId:r.id,title:r.title,commitId:r.commitId,pin:r.pin}]:[])}async function B(e){let t=await fetch(`https://scrapbox.io/api/pages/${e}?limit=1`),{count:r}=await t.json(),o=Math.min(r,1e3),s=Math.floor(r/1e3)+1;return(await Promise.all([...Array(s).keys()].map(async c=>{let u=await fetch(`/api/pages/${e}/?limit=${o}&skip=${c*1e3}`),{pages:g}=await u.json();return g}))).flat()}function L(e,t){return new Promise((r,o)=>{let s=new WebSocket(e,t),i=(c,u)=>{let g=y=>{u(y),s.removeEventListener(c,g)};s.addEventListener(c,g)};i("error",o),i("open",()=>r({close:()=>new Promise(c=>{s.close(),i("close",u=>c(u))}),send:c=>{s.send(c)},receive:async function*(){for(;;)yield await new Promise(u=>i("message",g=>u(g)))}}))})}var G=({pin:e,commitId:t,pageId:r,userId:o,projectId:s})=>`422${JSON.stringify(["socket.io-request",{method:"commit",data:{kind:"page",parentId:t,changes:[{pin:e>0?0:Number.MAX_SAFE_INTEGER-Math.floor(Date.now()/1e3)}],cursor:null,pageId:r,userId:o,projectId:s,freeze:!0}}])}`;async function A(e){let{send:t,receive:r,close:o}=await L("wss://scrapbox.io/socket.io/?EIO=4&transport=websocket"),s=r();await s.next(),await t("40"),await s.next(),await t(G(e)),await s.next(),await o()}function n(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function a(e){n(1,arguments);let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"),console.warn(new Error().stack)),new Date(NaN))}function _(e){n(1,arguments);let r=a(e).getFullYear();return r%400==0||r%4==0&&r%100!=0}function v(e){n(1,arguments);let t=a(e);return String(new Date(t))==="Invalid Date"?NaN:_(t)?366:365}function q(e){n(1,arguments);let t=a(e),r=new Date(0);return r.setFullYear(t.getFullYear(),0,1),r.setHours(0,0,0,0),r}function D(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e.getTime()-t.getTime()}function w(e){n(1,arguments);let t=a(e);return t.setHours(0,0,0,0),t}var J=864e5;function Y(e,t){n(2,arguments);let r=w(e),o=w(t),s=r.getTime()-D(r),i=o.getTime()-D(o);return Math.round((s-i)/J)}function T(e){n(1,arguments);let t=a(e);return Y(t,q(t))+1}function d(e){if(e===null||e===!0||e===!1)return NaN;let t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function l(e,t){n(2,arguments);let r=a(e),o=d(t);return isNaN(o)?new Date(NaN):(o&&r.setDate(r.getDate()+o),r)}function M(e,t){n(2,arguments);let r=d(t);return l(e,-r)}function $(e,t){n(2,arguments);let o=d(t)*7;return l(e,o)}function x(e,t){n(2,arguments);let r=d(t);return $(e,-r)}function b(e,t){n(2,arguments);let r=a(e),o=d(t);if(isNaN(o))return new Date(NaN);if(!o)return r;let s=r.getDate(),i=new Date(r.getTime());i.setMonth(r.getMonth()+o+1,0);let c=i.getDate();return s>=c?i:(r.setFullYear(i.getFullYear(),i.getMonth(),s),r)}function h(e,t){n(2,arguments);let r=d(t);return b(e,-r)}function P(e,t){n(2,arguments);let r=d(t);return b(e,r*12)}function O(e,t){n(2,arguments);let r=d(t);return P(e,-r)}function E(e){return n(1,arguments),a(e).getDay()}function k(e){return n(1,arguments),a(e).getFullYear()}function p(e,t){for(var r=e<0?"-":"",o=Math.abs(e).toString();o.length<t;)o="0"+o;return r+o}var Q={y(e,t){let r=e.getUTCFullYear(),o=r>0?r:1-r;return p(t==="yy"?o%100:o,t.length)},M(e,t){let r=e.getUTCMonth();return t==="M"?String(r+1):p(r+1,2)},d(e,t){return p(e.getUTCDate(),t.length)},a(e,t){let r=e.getUTCHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return r.toUpperCase();case"aaa":return r;case"aaaaa":return r[0];case"aaaa":default:return r==="am"?"a.m.":"p.m."}},h(e,t){return p(e.getUTCHours()%12||12,t.length)},H(e,t){return p(e.getUTCHours(),t.length)},m(e,t){return p(e.getUTCMinutes(),t.length)},s(e,t){return p(e.getUTCSeconds(),t.length)},S(e,t){let r=t.length,o=e.getUTCMilliseconds(),s=Math.floor(o*Math.pow(10,r-3));return p(s,t.length)}},R=Q;function S(e){n(1,arguments);var t=a(e);return!isNaN(t)}function j(e,t){n(2,arguments);let r=a(e).getTime(),o=d(t);return new Date(r+o)}function C(e,t){n(2,arguments);let r=d(t);return j(e,-r)}var X=/(\w)\1*|''|'(''|[^'])+('|$)|./g,K=/^'([^]*?)'?$/,ee=/''/g,te=/[a-zA-Z]/;function m(e,t){n(2,arguments);let r=a(e);if(!S(r))throw new RangeError("Invalid time value");let o=D(r),s=C(r,o),i=t.match(X);return i?i.map(u=>{if(u==="''")return"'";let g=u[0];if(g==="'")return re(u);let y=R[g];if(y)return y(s,u);if(g.match(te))throw new RangeError("Format string contains an unescaped latin alphabet character `"+g+"`");return u}).join(""):""}function re(e){let t=e.match(K);return t?t[1].replace(ee,"'"):e}var f="yyyy/MM/dd",U=e=>[m(e,f),`[${m(M(e,1),f)}.icon]←${m(e,f)}→[${m(l(e,1),f)}.icon]`,`[[${ne(e)}曜日]]`,`${k(e)}年 ${(T(e)*100/v(e)).toFixed(2)}%経過`,`[🌏 https://ja.wikipedia.org/wiki/${m(e,"M月d日")}]`,[`[${m(x(e,1),f)}.icon]`,`[${m(x(e,2),f)}.icon]`,`[${m(x(e,3),f)}.icon]`,`[${m(h(e,1),f)}.icon]`,`[${m(h(e,2),f)}.icon]`,`[${m(h(e,3),f)}.icon]`].join(" "),"今日のn年前",` [${m(O(e,1),f)}]`,"","","",`[${m(M(e,1),f)}]←${m(e,f)}→[${m(l(e,1),f)}]`].join(`
`);function ne(e){switch(E(e)){case 0:return"日";case 1:return"月";case 2:return"火";case 3:return"水";case 4:return"木";case 5:return"金";case 6:return"土"}}var I="villagepump",W=()=>scrapbox.Project.name===I?oe():H();W();scrapbox.addListener("project:changed",W);var z;async function oe(){H();let e=await fetch("https://scrapbox.io/api/users/me"),{id:t}=await e.json(),r=await fetch(`https://scrapbox.io/api/projects/${I}`),{id:o}=await r.json();N(t,o),z=setInterval(()=>N(t,o),24*3600*1e3)}function H(){clearInterval(z)}async function N(e,t){let r=await F(I),o=r.filter(({pin:i})=>i>0);for(let i of o)i.title!==V(new Date)&&await A({userId:e,projectId:t,...i});let s=r.find(({title:i})=>i===V(new Date));if(!s){let[i,...c]=U(new Date).split(`
`),u=document.createElement("a");return u.href=`../${I}/${encodeURIComponent(i)}?body=${encodeURIComponent(c.join(`
`))}`,document.body.append(u),u.click(),u.remove(),await new Promise(g=>scrapbox.once("page:changed",g)),await N(e,t)}s.pin>0||await A({userId:e,projectId:t,...s})}function V(e){return`${e.getFullYear()}/${Z(e.getMonth()+1)}/${Z(e.getDate())}`}function Z(e){return String(e).padStart(2,"0")}