47 wiersze
4.7 KiB
JavaScript
47 wiersze
4.7 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="",a=(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,r=0;s?.outbox?.orderedItems?a=s.outbox.orderedItems:s?.outbox&&(a=s.outbox);var i=[];if(r=a.length){var l=Math.ceil(Math.pow(a.length,.1));if(o=a[0],10<=a.length)for(let t=1;t<=l;t++){var d=a[Math.pow(10,t)],m=d.id.replace("/activity","");let e=!1;d.object.id||(e=!0),d={label:[Math.pow(10,t).toLocaleString()+"th post"],url:m,isBoost:e},i.push(d)}}var c={weekday:"long",year:"numeric",month:"long",day:"numeric"};s.actor&&(u=moment(s.actor.published),u=moment().diff(u,"days"),t+=`
|
|
<p>
|
|
You created your account on <strong>${new Date(s.actor.published).toLocaleDateString(void 0,c)}</strong>, which is <strong>${u.toLocaleString()} day(s) ago</strong>. Since then, you posted <strong>${r.toLocaleString()} times</strong>, or about ${Math.round(r/u).toLocaleString()} time(s) a day on average.
|
|
</p>
|
|
`);let n;if(o){let e;if(!["firefish","calckey","misskey"].includes(s.format)){c=o?.uri||o?.object?.id||o?.id;try{e=new URL(c)}catch(e){console.log("error parsing data file",e)}e&&e.protocol&&e.hostname&&(n=e.protocol+"//"+e.hostname),t+=`
|
|
<p>
|
|
Here's your <a href="${c}" target="_blank">first post</a>!
|
|
</p>
|
|
`,"mastodon"===s.format&&(t+=`
|
|
<iframe
|
|
src="${c}/embed"
|
|
class="mastodon-embed"
|
|
style="max-width: 100%; border: 0" width="400"
|
|
allowfullscreen="allowfullscreen"></iframe>
|
|
`),i&&i.length&&(t+=`
|
|
<p class="mt-3">
|
|
Here are more of your milestones:
|
|
</p>
|
|
<ul>
|
|
${i.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(n);var u={labels:a.map(e=>moment(e.published||e.createdAt||e.created)),datasets:[{label:"Your posts in time",data:a.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:u,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
|