import-dev
code:script.js
await import("../../takker-dist/import-devにbackgroundでテストコードを貼り付けるUserScript/script.js");
await import("./mod.js");
code:mod.js
var ve=Object.defineProperty;var Ve=(e,r)=>{for(var t in r)ve(e,t,{get:rt,enumerable:!0})};var se={};Ve(se,{check:()=>ne,emitChange:()=>re,load:()=>yr,subscribe:()=>mr});var g=!1,ie=e=>{g=typeof e=="boolean"?e:new Set(e)},C=e=>Object.fromEntries(...Object.entries(console).map((r,t)=>{if(typeof t!="function")returnr,t;switch(r){case"warn":case"error":return[r,(...o)=>t(%c${e},G,...o)];case"log":case"info":case"debug":return[r,(...o)=>{g!==!0&&(!g||!g.has(e))||t(%c${e},G,...o)}];case"assert":return[r,(o,...n)=>{g!==!0&&(!g||!g.has(e))||t(o,%c${e},G,...n)}];case"time":case"timeEnd":return[r,o=>{g!==!0&&(!g||!g.has(e))||t(${e} ${o})}];default:returnr,(...o)=>{if(!(g!==!0&&(!g||!g.has(e))))return t(...o)}}})),G="color: gray";var ae=" must not return ",We="transformer",Ke="recoverer",ze="defaultValue",wr=We+ae,H="called with ",Tr=ze+" must not be ",Pr=Ke+ae;var Ye="Ok",ce="Err",pe=H+ce,ue=H+Ye,kr="Carrying E in "+ce+" instead of throwing it directly. See .cause",v="an instance of Error of the current realm.",Nr="The thrown value is not "+v,Fr="The contained E should be "+v,Lr="This .cause is not "+v;function I(e){return e.ok}function R(e){return{ok:!0,val:e,err:null}}function f(e){return!e.ok}function w(e){return{ok:!1,val:null,err:e}}function y(e){return me(e,pe)}function k(e){return de(e,ue)}function me(e,r){if(f(e))throw new TypeError(r);return e.val}function de(e,r){if(I(e))throw new TypeError(r);return e.err}function fe(e){return e.val}function le(e){return e.err}async function N(e,r){if(f(e))return e;let t=fe(e),o=await r(t);return R(o)}async function F(e,r){if(I(e))return e;let t=le(e),o=await r(t);return w(o)}var m=e=>e.ok?R(e):w({name:"HTTPError",message:${e.status} ${e.statusText},response:e});var Ee=async(e,r)=>{let t=new Request(e,r);try{return R(await globalThis.fetch(t))}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return w({name:"AbortError",message:o.message,request:t});if(o instanceof TypeError)return w({name:"NetworkError",message:o.message,request:t});throw o}};var p=e=>{let{fetch:r=Ee,hostName:t="scrapbox.io",...o}=e;return{fetch:r,hostName:t,...o}};var d=e=>connect.sid=${e};function B(e,r={}){if(e===null)return"null";if(Array.isArray(e))return Je(e,r);switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return${e}n;case"object":return e.constructor?.name!=="Object"?e.constructor?.name:Qe(e,r);case"function":return e.name||"(anonymous)"}return e?.toString()??"undefined"}function Je(e,r){let{threshold:t=20}=r,o=e.map(i=>B(i,r)),n=o.join(", ");if(n.length<=t)return[${n}];let s=o.join(`, );return[
${ge(2,s)}
]}function Qe(e,r){let{threshold:t=20}=r,o=[...Object.keys(e),...Object.getOwnPropertySymbols(e)].map(i=>${i.toString()}: ${B(ei,r)}),n=o.join(", ");if(n.length<=t)return{${n}};let s=o.join(, );return{
${ge(2,s)}
}}function ge(e,r){let t=" ".repeat(e);return r.split(
).map(o=>${t}${o}).join(
)}function A(e,r,...t){let o;return Object.defineProperties(e,{name:{get:()=>o||(o=${r}(${t.map(n=>B(n)).join(", ")}),o)}})}function ye(e){return Array.isArray(e)}function he(e){return A(r=>ye(r)&&r.every(t=>e(t)),"isArrayOf",e)}function V(e){let r=new Set(e);return A(t=>r.has(t),"isLiteralOneOf",e)}function W(e){return e!=null&&!Array.isArray(e)&&typeof e=="object"}function _(e){return typeof e=="string"}var l=async(e,r)=>{let t=e.response.clone(),o=V(r);try{let n=await t.json();if(!W(n))return;if(t.status===422){if(!_(n.message))return;for(let s of["NoQueryError","InvalidURLError"])if(r.includes(s))return{name:s,message:n.message}}return!o(n.name)||!_(n.message)?void 0:n.name==="NotLoggedInError"?!W(n.detals)||!_(n.detals.project)||!he(Xe)(n.detals.loginStrategies)?void 0:{name:n.name,message:n.message,details:{project:n.detals.project,loginStrategies:n.detals.loginStrategies}}:{name:n.name,message:n.message}}catch(n){if(n instanceof SyntaxError)return;throw n}},Xe=V(["google","github","microsoft","gyazo","email","saml","easy-trial"]);var xe=(e,r)=>{let{sid:t,hostName:o}=p(r??{});return new Request(https://${o}/api/projects/${e},t?{headers:{Cookie:d(t)}}:void 0)},we=async e=>N(await F(m(e),async r=>await l(r,["NotFoundError","NotLoggedInError","NotMemberError"])??r),r=>r.json()),be=(()=>{let e=async(r,t)=>{let{fetch:o}=p(t??{}),n=xe(r,t),s=await o(n);return f(s)?s:we(y(s))};return e.toRequest=xe,e.fromResponse=we,e})(),Te=(e,r)=>{let{sid:t,hostName:o}=p(r??{}),n=new URLSearchParams(e.map(s=>["ids",s]));return new Request(https://${o}/api/projects?${n},t?{headers:{Cookie:d(t)}}:void 0)},Pe=async e=>N(await F(m(e),async r=>await l(r,["NotLoggedInError"])??r),r=>r.json()),Ie=(()=>{let e=async(r,t)=>{let{fetch:o}=p(t??{}),n=await o(Te(r,t));return f(n)?n:Pe(y(n))};return e.toRequest=Te,e.fromResponse=Pe,e})();var ke=(e,r)=>{let{sid:t,hostName:o,followingId:n}=p(r??{});return new Request(https://${o}/api/pages/${e}/search/titles${n??followingId=${n}:""},t?{headers:{Cookie:d(t)}}:void 0)},Ne=async e=>N(await F(m(e),async r=>r.response.status===422?{name:"InvalidFollowingIdError",message:await r.response.text()}:await l(r,["NotFoundError","NotLoggedInError"])??r),r=>r.json().then(t=>({pages:t,followingId:r.headers.get("X-following-id")??""}))),Ze=(()=>{let e=async(r,t)=>{let o=await p(t??{}).fetch(ke(r,t));return f(o)?o:Ne(y(o))};return e.toRequest=ke,e.fromResponse=Ne,e})();async function*Fe(e,r){let t;do{let o=await Ze(e,{followingId:t,...r});if(f(o)){yield o;return}let n=y(o);yield R(n.pages),t=n.followingId}while(t)}var Mo=new TextEncoder;var Do=new TextEncoder().encode("0123456789abcdef"),Go=new TextEncoder,Ho=new TextDecoder;async function*Le(e){let r=[],t=[],o=new Map,n=[];for(let s of e)s.isValid&&(s.id?s.isMember||r.push(s.id):t.push(s.name),n.push(s.name),o.set(s.name,s.checked));for(let s=0;s<r.length;s+=50){let i=r.slice(s,s+50);if(i.length===0)break;i.length===1&&i.push(i[0]);let c=await Ie(i);if(f(c)){t=n;break}for(let a of y(c).projects)o.has(a.name)&&(yield R({...a,checked:o.get(a.name)??0}))}for(let s of t){let i=await be(s);yield I(i)?R({...y(i),checked:o.get(s)??0}):w({...k(i),project:s})}}var Y=(e,r)=>r.some(t=>e instanceof t),Oe,je;function er(){return Oe||(Oe=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function rr(){return je||(je=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var J=new WeakMap,K=new WeakMap,U=new WeakMap;function tr(e){let r=new Promise((t,o)=>{let n=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(P(e.result)),n()},i=()=>{o(e.error),n()};e.addEventListener("success",s),e.addEventListener("error",i)});return U.set(r,e),r}function or(e){if(J.has(e))return;let r=new Promise((t,o)=>{let n=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{t(),n()},i=()=>{o(e.error||new DOMException("AbortError","AbortError")),n()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});J.set(e,r)}var Q={get(e,r,t){if(e instanceof IDBTransaction){if(r==="done")return J.get(e);if(r==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return P(e[r])},set(e,r,t){return e[r]=t,!0},has(e,r){return e instanceof IDBTransaction&&(r==="done"||r==="store")?!0:r in e}};function Ae(e){Q=e(Q)}function nr(e){return rr().includes(e)?function(...r){return e.apply(X(this),r),P(this.request)}:function(...r){return P(e.apply(X(this),r))}}function sr(e){return typeof e=="function"?nr(e):(e instanceof IDBTransaction&&or(e),Y(e,er())?new Proxy(e,Q):e)}function P(e){if(e instanceof IDBRequest)return tr(e);if(K.has(e))return K.get(e);let r=sr(e);return r!==e&&(K.set(e,r),U.set(r,e)),r}var X=e=>U.get(e);function _e(e,r,{blocked:t,upgrade:o,blocking:n,terminated:s}={}){let i=indexedDB.open(e,r),c=P(i);return o&&i.addEventListener("upgradeneeded",a=>{o(P(i.result),a.oldVersion,a.newVersion,P(i.transaction),a)}),t&&i.addEventListener("blocked",a=>t(a.oldVersion,a.newVersion,a)),c.then(a=>{s&&a.addEventListener("close",()=>s()),n&&a.addEventListener("versionchange",u=>n(u.oldVersion,u.newVersion,u))}).catch(()=>{}),c}var ir=["get","getKey","getAll","getAllKeys","count"],ar=["put","add","delete","clear"],z=new Map;function Se(e,r){if(!(e instanceof IDBDatabase&&!(r in e)&&typeof r=="string"))return;if(z.get(r))return z.get(r);let t=r.replace(/FromIndex$/,""),o=r!==t,n=ar.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(n||ir.includes(t)))return;let s=async function(i,...c){let a=this.transaction(i,n?"readwrite":"readonly"),u=a.store;return o&&(u=u.index(c.shift())),(await Promise.all([u[t](...c),n&&a.done]))[0]};return z.set(r,s),s}Ae(e=>({...e,get:(r,t,o)=>Se(r,t)||e.get(r,t,o),has:(r,t)=>!!Se(r,t)||e.has(r,t)}));var cr=["continue","continuePrimaryKey","advance"],Ce={},Z=new WeakMap,Me=new WeakMap,pr={get(e,r){if(!cr.includes(r))return e[r];let t=Ce[r];return t||(t=Ce[r]=function(...o){Z.set(this,Me.get(this)[r](...o))}),t}};async function*ur(...e){let r=this;if(r instanceof IDBCursor||(r=await r.openCursor(...e)),!r)return;r=r;let t=new Proxy(r,pr);for(Me.set(t,r),U.set(t,X(r));r;)yield t,r=await(Z.get(t)||r.continue()),Z.delete(t)}function Be(e,r){return r===Symbol.asyncIterator&&Y(e,[IDBIndex,IDBObjectStore,IDBCursor])||r==="iterate"&&Y(e,[IDBIndex,IDBObjectStore])}Ae(e=>({...e,get(r,t,o){return Be(r,t)?ur:e.get(r,t,o)},has(r,t){return Be(r,t)||e.has(r,t)}}));var $=C("scrapbox-storage:db.ts"),Ue,ee=async()=>(Ue??=await _e("scrapbox-storage-test",2,{upgrade(e){$.time("update DB");for(let o of e.objectStoreNames)e.deleteObjectStore(o);let r=e.createObjectStore("titles",{keyPath:"id"});r.createIndex("project","project"),r.createIndex("updated","updated"),e.createObjectStore("projects",{keyPath:"name"}).createIndex("checked","checked"),$.timeEnd("update DB")},blocked(e,r){let t=The database "@takker/cosense-storage"(v${r}) is blocked because the older one (v${e}) is opened in other tabs. Please close the other tabs and reload this page.;$.error(t),alert(t)},blocking(e,r){let t=The database "@takker/cosense-storage"(v${e}) is blocking the newer one (v${r}) opened.
Please close this page.;$.error(t),alert(t)}}),Ue);var mr=(e,r)=>(q.set(r,new Set(e).union(q.get(r)??new Set)),()=>q.delete(r)),re=(e,r)=>{let t={type:"links:changed",project:e,diff:r};$e(t);let o=new BroadcastChannel(qe);o.postMessage(t),o.close()},$e=e=>{for(let[r,t]of q)t.has(e.project)&&r(e)},qe="scrapbox-storage-notify",dr=new BroadcastChannel(qe);dr.addEventListener("message",e=>$e(e.data));var q=new Map;var fr=Math.pow(10,8)*24*60*60*1e3,Nn=-fr;var lr=3600;var De=lr*24,Fn=De*7,Er=De*365.2425,gr=Er/12,Ln=gr*3,te=Symbol.for("constructDateFrom");function Ge(e,r){return typeof e=="function"?e(r):e&&typeof e=="object"&&te in e?e[te](r):e instanceof Date?new e.constructor(r):new Date(r)}function He(e,r){return Ge(r||e,e)}function oe(e){return Math.trunc(+He(e)/1e3)}var h=C("scrapbox-storage:mod.ts"),ne=async(e,r)=>{let t=await ee(),o=new Map;try{{h.debug("check updates of links...");let s=t.transaction("projects","readwrite"),i=oe(new Date),c=i-600;for await(let a of s.store.index("checked").iterate(IDBKeyRange.lowerBound(c,!0))){let u=a.value;if(u?.isValid===!1)continue;let L=u?.checked??0;if(L+r>i||u?.updating&&L>c)continue;let O=u?.name??"",b=structuredClone(u);b.updating=!0,o.set(O,b),a.update(b)}await s.done;for(let a of e)o.has(a)||o.set(a,hr(a));if(o.size===0){h.debug("checked. No project needs upgrade.");return}h.debug(checked. ${o.size} projects maybe need upgrade.)}let n=oe(new Date);for await(let s of Le(o.values())){if(f(s)){let{project:E,name:S}=k(s);switch(S){default:continue;case"NotFoundError":h.warn("${E}" is not found.);break;case"NotMemberError":h.warn(You are not a member of "${E}".);break;case"NotLoggedInError":h.warn(You are not a member of "${E}" or You are not logged in yet.);break}o.set(E,{name:E,checked:n,updating:!1,isValid:!1,reason:S});continue}let{checked:i,...c}=y(s);if(c.updated<i){h.debug(no updates in "${c.name}"),o.set(c.name,{...c,isValid:!0,checked:n,updating:!1});continue}let a={added:new Map,updated:new Map,deleted:new Set},u=new Set,L=download and store links of "${c.name}";h.time(L);let O=new Set(await t.getAllKeysFromIndex("titles","project",c.name));for await(let E of Fe(c.name)){if(f(E)){let{name:x,message:T}=k(E);h.error(Failed to get links of "${c.name}" with ${x}: ${T});break}let S=y(E),j=t.transaction("titles","readwrite");await Promise.all(S.map(async x=>{let T={...x,project:c.name};if(!O.has(x.id))return a.added.set(x.id,T),j.store.add(T);O.delete(x.id);let D=await j.store.get(x.id);if(!D)return a.added.set(x.id,T),j.store.add(T);if(D.updated>=T.updated){u.add(x.id);return}return a.updated.set(x.id,[D,T]),j.store.put(T)})),await j.done,h.debug(Updating "/${c.name}": +${a.added.size} pages, .${u.size} pages, ~${a.updated.size} pages, -${a.deleted.size} pages)}for(let E of O)a.deleted.add(E);let b=t.transaction("titles","readwrite");await Promise.all([...a.deleted].map(E=>b.store.delete(E))),await b.done,h.timeEnd(L),h.debug(Update "/${c.name}": +${a.added.size} pages, .${u.size} pages, ~${a.updated.size} pages, -${a.deleted.size} pages),o.set(c.name,{...c,isValid:!0,checked:n,updating:!1}),re(c.name,a)}}finally{let n=t.transaction("projects","readwrite");await Promise.all([...o.values()].map(s=>(s.updating=!1,n.store.put({...s})))),await n.done}},yr=async e=>{let r=[...new Set(e)];if(r.length===0)return[];let t=Date.now(),n=(await ee()).transaction("titles","readonly"),s=n.store.index("project"),i=(await Promise.all(r.map(c=>s.getAll(c)))).flat();return await n.done,h.debug(Read ${i.length} links from ${r.length} projects in ${Date.now()-t}ms`),i},hr=e=>({name:e,displayName:e,id:"",isValid:!0,publicVisible:!0,isMember:!0,loginStrategies:[],theme:"default",gyazoTeamsName:null,translation:!0,infobox:!0,checked:0,updated:0,created:0,updating:!0});ie(!0);globalThis.cosenseStorage=se;await ne("takker","nishio","mrsekut-p",60);