51 wiersze
5.2 KiB
JavaScript
51 wiersze
5.2 KiB
JavaScript
import sortArrayOfObjects from"/js/modules/sortArrayOfObjects.min.js";import getDomain from"/js/modules/getDomain.min.js";import loadEmbedScript from"/js/modules/loadEmbedScript.min.js";import Cookie from"/js/cookies/main.min.js";const cookieManager=new Cookie,fileInput=document.getElementById("file-input"),introElement=document.getElementById("intro"),loadingAnimation=document.getElementById("loading-animation"),loadingText=document.getElementById("loading-text"),resultsElement=document.getElementById("results"),userInfo=document.getElementById("user-info"),userAvatar=document.getElementById("user-avatar"),userDescription=document.getElementById("user-description"),userDataBreakdown=document.getElementById("user-data-breakdown"),chartElement=document.getElementById("chart"),handleUpload=()=>{fileInput&&fileInput.addEventListener("change",async e=>{loadingAnimation.classList.remove("d-none"),loadingText.classList.remove("d-none"),fileInput.disabled=!0;var s=new FormData;s.set("archive",fileInput.files[0]);s=await(await fetch("/extract-data",{method:"POST",body:s})).json();if(s&&s.data){introElement.classList.add("d-none"),resultsElement.classList.remove("d-none");s=s.data;let e="",t="",r=(s.actor?(e+=`
|
|
<p class="mb-0">
|
|
<strong>${s.actor.name||s.actor.preferredUsername}</strong>
|
|
</p>
|
|
${s.actor.summary.replaceAll('class="invisible"',"")}
|
|
`,s.actor.attachment&&(e+=`
|
|
<ul class="list-group">
|
|
${s.actor.attachment.map(e=>`
|
|
<li class="list-group-item">${e.name}: ${e.value.replace('class="invisible"',"")}</li>
|
|
`).join("")}
|
|
</ul>
|
|
`),userDescription.innerHTML=`<div>${e}</div>`,s.avatar_url?userAvatar.innerHTML=`
|
|
<img class="img-thumbnail" width="64" height="64" src="${s.avatar_url}">
|
|
`:s.avatar&&(userAvatar.innerHTML=`
|
|
<img class="img-thumbnail" width="64" height="64" src="data:image/jpg;base64,${s.avatar}">
|
|
`)):(userInfo.remove(),userDescription.remove()),[]),o;s?.outbox?.orderedItems?r=s.outbox.orderedItems:s?.outbox&&(r=s.outbox),i=r.length;let n=[],l={posts:0,replies:0,reblogs:0,total:0};if(i){const m=Math.ceil(Math.pow(r.length,.1));let s=0;o=r[0],r.forEach(t=>{let o=!1;if([...t.to,...t.cc].forEach(e=>{e.endsWith("/followers")&&(o=!0)}),o){if(s++,10<=r.length&&s<=m){const t=r[Math.pow(10,s)];var a=t.id.replace("/activity","");let e=!1;t.object.id||(e=!0),a={label:[Math.pow(10,s).toLocaleString()+"th post"],url:a,isBoost:e},n.push(a)}l.total++,"Create"===t.type?t.object.inReplyTo?l.replies++:l.posts++:l.reblogs++}})}var i={weekday:"long",year:"numeric",month:"long",day:"numeric"};s.actor&&(d=moment(s.actor.published),d=moment().diff(d,"days"),t+=`
|
|
<p>
|
|
You created your account on <strong>${new Date(s.actor.published).toLocaleDateString(void 0,i)}</strong>, which is <strong>${d.toLocaleString()} day(s) ago</strong>. Since then, you posted <strong>${l.total.toLocaleString()} times</strong>, or about ${Math.round(l.total/d).toLocaleString()} time(s) a day on average.
|
|
</p>
|
|
`),(0<l.reblogs||0<l.replies)&&(t+=`
|
|
<p>
|
|
You have reblogged <strong>${l.reblogs.toLocaleString()} post(s)</strong>, replied <strong>${l.replies.toLocaleString()} time(s)</strong>, and posted <strong>${l.posts.toLocaleString()} new post(s)</strong>.
|
|
</p>
|
|
`);let a;if(o){let e;if(!["firefish","calckey","misskey"].includes(s.format)){i=o?.uri||o?.object?.id||o?.id;try{e=new URL(i)}catch(e){console.log("error parsing data file",e)}e&&e.protocol&&e.hostname&&(a=e.protocol+"//"+e.hostname),t+=`
|
|
<p>
|
|
Here's your <a href="${i}" target="_blank">first post</a>!
|
|
</p>
|
|
`,"mastodon"===s.format&&(t+=`
|
|
<iframe
|
|
src="${i}/embed"
|
|
class="mastodon-embed"
|
|
style="max-width: 100%; border: 0" width="400"
|
|
allowfullscreen="allowfullscreen"></iframe>
|
|
`),n&&n.length&&(t+=`
|
|
<p class="mt-3">
|
|
Here are more of your milestones:
|
|
</p>
|
|
<ul>
|
|
${n.map(e=>`
|
|
<li>
|
|
<a target="_blanlk" href="${e.url}">${e.label}</a>${e.isBoost?" (boost)":""}
|
|
</li>
|
|
`).join("")}
|
|
</ul>
|
|
`),t+=`
|
|
<p class="mt-4">
|
|
And this is what your posting history looks like.
|
|
</p>
|
|
`}}userDataBreakdown.innerHTML=t,"mastodon"===s.format&&loadEmbedScript(a);var d={labels:r.map(e=>moment(e.published||e.createdAt||e.created)),datasets:[{label:"Your posts in time",data:r.map((e,t)=>({x:moment(e.published||e.createdAt||e.created),y:new Date(e.published||e.createdAt||e.created).getHours()})),backgroundColor:["#ff6384"]}]};new Chart(chartElement,{type:"scatter",data:d,options:{scales:{x:{type:"time",position:"bottom",ticks:{beginAtZero:!1,stepSize:10}},y:{ticks:{beginAtZero:!1,display:!1},scaleLabel:{display:!1},minorTickInterval:null}},plugins:{tooltip:{callbacks:{label:e=>e.label}}}}})}else loadingAnimation.classList.add("d-none"),loadingText.classList.add("d-none"),fileInput.disabled=!1})};export default handleUpload;
|
|
//# sourceMappingURL=handleUpload.min.js.map
|