Don't count private posts in the total post count.
rodzic
c44e6bbb7f
commit
7af6a72859
|
@ -4,6 +4,6 @@
|
|||
|
||||
```sh
|
||||
npm install
|
||||
npm start dev
|
||||
npm run dev
|
||||
npm run gulp
|
||||
```
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import loadEmbedScript from"/js/modules/loadEmbedScript.min.js";import{fileInput,loadingAnimation,loadingText,introElement,resultsElement,userDescription,userAvatar,userInfo,userDataBreakdown,chartElement}from"./handleUpload";const 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()),[]),a;s?.outbox?.orderedItems?r=s.outbox.orderedItems:s?.outbox&&(r=s.outbox),n=r.length;let l=[],i={posts:0,replies:0,reblogs:0,total:0};if(n){const d=Math.ceil(Math.pow(r.length,.1));let s=0;a=r[0],r.forEach(t=>{let a=!1;var e=[...t.to,...t.cc];if(e.forEach(e=>{e.endsWith("/followers")&&(a=!0)}),a){if(s++,10<=r.length&&s<=d){const t=r[Math.pow(10,s)];var o=t.id.replace("/activity","");let e=!1;t.object.id||(e=!0),o={label:[Math.pow(10,s).toLocaleString()+"th post"],url:o,isBoost:e},l.push(o)}i.total++,"Create"===t.type?t.object.inReplyTo?i.replies++:i.posts++:i.reblogs++}else 0===e.length&&console.log(t.id.replace("users/","@").replace("statuses/","").replace("/activity",""))}),console.log({counter:i})}var n={weekday:"long",year:"numeric",month:"long",day:"numeric"};s.actor&&(c=moment(s.actor.published),c=moment().diff(c,"days"),t+=`
|
||||
<p>
|
||||
You created your account on <strong>${new Date(s.actor.published).toLocaleDateString(void 0,n)}</strong>, which is <strong>${c.toLocaleString()} day(s) ago</strong>. Since then, you posted <strong>${i.total.toLocaleString()} times</strong>, or about ${Math.round(i.total/c).toLocaleString()} time(s) a day on average.
|
||||
</p>
|
||||
`),(0<i.reblogs||0<i.replies)&&(t+=`
|
||||
<p>
|
||||
You have reblogged <strong>${i.reblogs.toLocaleString()} post(s)</strong>, replied <strong>${i.replies.toLocaleString()} time(s)</strong>, and posted <strong>${i.posts.toLocaleString()} new post(s)</strong>.
|
||||
</p>
|
||||
`);let o;if(a){let e;if(!["firefish","calckey","misskey"].includes(s.format)){n=a?.uri||a?.object?.id||a?.id;try{e=new URL(n)}catch(e){console.log("error parsing data file",e)}e&&e.protocol&&e.hostname&&(o=e.protocol+"//"+e.hostname),t+=`
|
||||
<p>
|
||||
Here's your <a href="${n}" target="_blank">first post</a>!
|
||||
</p>
|
||||
`,"mastodon"===s.format&&(t+=`
|
||||
<iframe
|
||||
src="${n}/embed"
|
||||
class="mastodon-embed"
|
||||
style="max-width: 100%; border: 0" width="400"
|
||||
allowfullscreen="allowfullscreen"></iframe>
|
||||
`),l&&l.length&&(t+=`
|
||||
<p class="mt-3">
|
||||
Here are more of your milestones:
|
||||
</p>
|
||||
<ul>
|
||||
${l.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(o);var c={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:c,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{handleUpload};
|
||||
//# sourceMappingURL=handleUpload.1.min.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
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+=`
|
||||
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>
|
||||
|
@ -13,26 +13,30 @@ import sortArrayOfObjects from"/js/modules/sortArrayOfObjects.min.js";import get
|
|||
<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+=`
|
||||
`)):(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,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.
|
||||
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>
|
||||
`);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+=`
|
||||
`),(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="${c}" target="_blank">first post</a>!
|
||||
Here's your <a href="${i}" target="_blank">first post</a>!
|
||||
</p>
|
||||
`,"mastodon"===s.format&&(t+=`
|
||||
<iframe
|
||||
src="${c}/embed"
|
||||
src="${i}/embed"
|
||||
class="mastodon-embed"
|
||||
style="max-width: 100%; border: 0" width="400"
|
||||
allowfullscreen="allowfullscreen"></iframe>
|
||||
`),i&&i.length&&(t+=`
|
||||
`),n&&n.length&&(t+=`
|
||||
<p class="mt-3">
|
||||
Here are more of your milestones:
|
||||
</p>
|
||||
<ul>
|
||||
${i.map(e=>`
|
||||
${n.map(e=>`
|
||||
<li>
|
||||
<a target="_blanlk" href="${e.url}">${e.label}</a>${e.isBoost?" (boost)":""}
|
||||
</li>
|
||||
|
@ -42,5 +46,5 @@ import sortArrayOfObjects from"/js/modules/sortArrayOfObjects.min.js";import get
|
|||
<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;
|
||||
`}}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
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,2 @@
|
|||
const isBoost=o=>{return o.object&&o.object.id,isBoost};export default isBoost;
|
||||
//# sourceMappingURL=isBoost.min.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"isBoost.min.js","sources":["modules/isBoost.js"],"sourcesContent":["const isBoost = (post) => {\r\n let isPostBoost = false;\r\n\r\n if (post.object && !post.object.id) {\r\n isPostBoost = true;\r\n }\r\n\r\n return isBoost;\r\n};\r\n\r\nexport default isBoost;\r\n"],"names":["isBoost","post","object","id"],"mappings":"AAAA,MAAMA,QAAU,IAOd,OAJIC,EAAKC,QAAWD,EAAKC,OAAOC,GAIzBH,OACT,iBAEeA"}
|
|
@ -82,9 +82,9 @@ const handleUpload = () => {
|
|||
userDescription.remove();
|
||||
}
|
||||
|
||||
let posts = [],
|
||||
firstPost,
|
||||
postCount = 0;
|
||||
let posts = [];
|
||||
let firstPost;
|
||||
let postCount = 0;
|
||||
|
||||
if (userData?.outbox?.orderedItems) {
|
||||
posts = userData.outbox.orderedItems;
|
||||
|
@ -95,32 +95,76 @@ const handleUpload = () => {
|
|||
postCount = posts.length;
|
||||
let milestones = [];
|
||||
|
||||
let counter = {
|
||||
posts: 0,
|
||||
replies: 0,
|
||||
reblogs: 0,
|
||||
total: 0,
|
||||
};
|
||||
|
||||
if (postCount) {
|
||||
// posts = sortArrayOfObjects(posts, key, desc)
|
||||
const maxRoot = Math.ceil(Math.pow(posts.length, 1 / 10));
|
||||
let index = 0;
|
||||
firstPost = posts[0];
|
||||
|
||||
if (posts.length >= 10) {
|
||||
for (let i = 1; i <= maxRoot; i++) {
|
||||
const post = posts[Math.pow(10, i)];
|
||||
const url = post.id.replace("/activity", "");
|
||||
posts.forEach((post) => {
|
||||
let isSemiPublic = false;
|
||||
const recipients = [...post.to, ...post.cc];
|
||||
|
||||
let milestone = {};
|
||||
let isBoost = false;
|
||||
|
||||
if (!post.object.id) {
|
||||
isBoost = true;
|
||||
recipients.forEach(recipient => {
|
||||
if (recipient.endsWith("/followers")){
|
||||
isSemiPublic = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (isSemiPublic) {
|
||||
index++;
|
||||
if (posts.length >= 10 && index <= maxRoot) {
|
||||
const post = posts[Math.pow(10, index)];
|
||||
const url = post.id.replace("/activity", "");
|
||||
|
||||
let milestone = {};
|
||||
let isBoost = false;
|
||||
|
||||
if (!post.object.id) {
|
||||
isBoost = true;
|
||||
}
|
||||
|
||||
milestone = {
|
||||
label: [`${Math.pow(10, index).toLocaleString()}th post`],
|
||||
url,
|
||||
isBoost,
|
||||
};
|
||||
|
||||
milestones.push(milestone);
|
||||
}
|
||||
|
||||
|
||||
|
||||
milestone = {
|
||||
label: [`${Math.pow(10, i).toLocaleString()}th post`],
|
||||
url,
|
||||
isBoost,
|
||||
};
|
||||
|
||||
milestones.push(milestone);
|
||||
|
||||
|
||||
|
||||
counter.total++;
|
||||
if (post.type === "Create") {
|
||||
if (post.object.inReplyTo) {
|
||||
counter.replies++;
|
||||
} else {
|
||||
counter.posts++;
|
||||
}
|
||||
} else {
|
||||
counter.reblogs++;
|
||||
}
|
||||
} else {
|
||||
// console.log(post.id.replace("users/", "@").replace("statuses/", "").replace("/activity", ""), recipients);
|
||||
// console.log(recipients);
|
||||
// if (recipients.length === 0){
|
||||
// console.log(post.id.replace("users/", "@").replace("statuses/", "").replace("/activity", ""));
|
||||
// }
|
||||
}
|
||||
}
|
||||
});
|
||||
// console.log({ counter });
|
||||
}
|
||||
|
||||
const options = {
|
||||
|
@ -142,13 +186,28 @@ const handleUpload = () => {
|
|||
).toLocaleDateString(
|
||||
undefined,
|
||||
options
|
||||
)}</strong>, which is <strong>${timeAgo.toLocaleString()} day(s) ago</strong>. Since then, you posted <strong>${postCount.toLocaleString()} times</strong>, or about ${Math.round(
|
||||
postCount / timeAgo
|
||||
)}</strong>, which is <strong>${timeAgo.toLocaleString()} day(s) ago</strong>. Since then, you posted <strong>${counter.total.toLocaleString()} times</strong>, or about ${Math.round(
|
||||
counter.total / timeAgo
|
||||
).toLocaleString()} time(s) a day on average.
|
||||
</p>
|
||||
`;
|
||||
}
|
||||
|
||||
/*
|
||||
counter = {
|
||||
posts: 0,
|
||||
replies: 0,
|
||||
reblogs: 0,
|
||||
*/
|
||||
|
||||
if (counter.reblogs > 0 || counter.replies > 0) {
|
||||
userDataBreakdownHTML += `
|
||||
<p>
|
||||
You have reblogged <strong>${counter.reblogs.toLocaleString()} post(s)</strong>, replied <strong>${counter.replies.toLocaleString()} time(s)</strong>, and posted <strong>${counter.posts.toLocaleString()} new post(s)</strong>.
|
||||
</p>
|
||||
`;
|
||||
}
|
||||
|
||||
let instanceURL;
|
||||
|
||||
if (firstPost) {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
const isBoost = (post) => {
|
||||
let isPostBoost = false;
|
||||
|
||||
if (post.object && !post.object.id) {
|
||||
isPostBoost = true;
|
||||
}
|
||||
|
||||
return isBoost;
|
||||
};
|
||||
|
||||
export default isBoost;
|
Ładowanie…
Reference in New Issue