From e12f7b6c055c8b49be44c1e49817087d1b073c58 Mon Sep 17 00:00:00 2001 From: idotj Date: Thu, 8 Feb 2024 16:10:44 +0100 Subject: [PATCH] Fix emoji error in profile title when hidden --- dist/mastodon-timeline.min.js | 2 +- examples/js/mastodon-timeline.js | 32 ++++++++++++++++++++------------ src/mastodon-timeline.js | 28 ++++++++++++++++++---------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/dist/mastodon-timeline.min.js b/dist/mastodon-timeline.min.js index f8eb015..1e93ac9 100644 --- a/dist/mastodon-timeline.min.js +++ b/dist/mastodon-timeline.min.js @@ -4,4 +4,4 @@ * @version 4.0.0 * @url https://gitlab.com/idotj/mastodon-embed-feed-timeline * @license GNU AGPLv3 -*/ "use strict";class MastodonTimeline{constructor(t={}){this.defaultSettings={mtContainerId:"mt-container",mtBody:"",instanceUrl:"https://mastodon.social",timelineType:"local",userId:"",profileName:"",hashtagName:"",spinnerClass:"mt-loading-spinner",defaultTheme:"auto",maxNbPostFetch:"20",maxNbPostShow:"20",hideUnlisted:!1,hideReblog:!1,hideReplies:!1,hideVideoPreview:!1,hidePreviewLink:!1,hideEmojos:!1,markdownBlockquote:!1,hideCounterBar:!1,txtMaxLines:"0",btnShowMore:"SHOW MORE",btnShowLess:"SHOW LESS",btnShowContent:"SHOW CONTENT",btnSeeMore:"See more posts at Mastodon",btnReload:"Refresh",fetchedData:{}},this.mtSettings={...this.defaultSettings,...t},this.mtSettings.mtBody=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("mt-body")[0],this.mtInit()}mtInit(){this.#a(),this.#b("newTimeline")}mtUpdate(){this.mtSettings.mtBody.replaceChildren(),this.mtSettings.mtBody.insertAdjacentHTML("afterbegin",'
'),this.#b("updateTimeline")}mtColorTheme(t){document.getElementById(this.mtSettings.mtContainerId).setAttribute("data-theme",t)}#a(){if("auto"===this.mtSettings.defaultTheme){let t=window.matchMedia("(prefers-color-scheme: dark)");t.matches?this.mtColorTheme("dark"):this.mtColorTheme("light"),t.addEventListener("change",t=>{t.matches?this.mtColorTheme("dark"):this.mtColorTheme("light")})}else this.mtColorTheme(this.mtSettings.defaultTheme)}#c(){return new Promise((t,e)=>{async function s(t){let e=await fetch(t);if(!e.ok)throw Error("Failed to fetch the following Url:
"+t+"
Error status: "+e.status+"
Error message: "+e.statusText);let s=await e.json();return s}let i={};this.mtSettings.instanceUrl?"profile"===this.mtSettings.timelineType?this.mtSettings.userId?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/accounts/${this.mtSettings.userId}/statuses?limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your userId value","⚠️"):"hashtag"===this.mtSettings.timelineType?this.mtSettings.hashtagName?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/timelines/tag/${this.mtSettings.hashtagName}?limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your hashtagName value","⚠️"):"local"===this.mtSettings.timelineType?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/timelines/public?local=true&limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your timelineType value","⚠️"):this.#d("Please check your instanceUrl value","⚠️"),this.mtSettings.hideEmojos||(i.emojos=this.mtSettings.instanceUrl+"/api/v1/custom_emojis");let a=Object.entries(i).map(([t,i])=>s(i).then(e=>({[t]:e})).catch(s=>(e(Error("Something went wrong fetching data from: "+i)),this.#d(s.message),{[t]:[]})));Promise.all(a).then(e=>{this.mtSettings.fetchedData=e.reduce((t,e)=>({...t,...e}),{}),t()})})}async #b(e){await this.#c(),this.mtSettings.mtBody.replaceChildren();let s=0;for(let i in this.mtSettings.fetchedData.timeline)("public"==this.mtSettings.fetchedData.timeline[i].visibility||!this.mtSettings.hideUnlisted&&"unlisted"==this.mtSettings.fetchedData.timeline[i].visibility)&&(this.mtSettings.hideReblog&&this.mtSettings.fetchedData.timeline[i].reblog||this.mtSettings.hideReplies&&this.mtSettings.fetchedData.timeline[i].in_reply_to_id||sThis may be due to an incorrect configuration in the parameters or to filters applied (to hide certains type of posts)";this.#d(a,"\uD83D\uDCED")}else"newTimeline"===e?(this.#f(),this.#g(),this.#h()):"updateTimeline"===e?this.#f():this.#d("The function buildTimeline() was expecting a param")}#e(o,n){this.mtSettings.mtBody.insertAdjacentHTML("beforeend",this.#i(o,n))}#i(r,l){let m,d,h,c,g,p,u,v,b;r.reblog?(c=r.reblog.url,m='
'+this.#j(r.reblog.account.username)+' avatar
'+this.#j(r.account.username)+' avatar
',h=this.#k(r.reblog.account.display_name?r.reblog.account.display_name:r.reblog.account.username,this.mtSettings.fetchedData.emojos),d='
'+h+' account
',g=r.reblog.created_at,b=r.reblog.replies_count,v=r.reblog.reblogs_count,u=r.reblog.favourites_count):(c=r.url,m='
'+this.#j(r.account.username)+' avatar
',h=this.#k(r.account.display_name?r.account.display_name:r.account.username,this.mtSettings.fetchedData.emojos),d='
'+h+' account
',g=r.created_at,b=r.replies_count,v=r.reblogs_count,u=r.favourites_count),p=this.#l(g);let S='
",$="";"0"!==this.mtSettings.txtMaxLines&&($=" truncate",this.mtSettings.mtBody.parentNode.style.setProperty("--mt-txt-max-lines",this.mtSettings.txtMaxLines));let f="";f=""!==r.spoiler_text?'
'+r.spoiler_text+'
'+this.#m(r.content)+"
":r.reblog&&""!==r.reblog.content&&""!==r.reblog.spoiler_text?'
'+r.reblog.spoiler_text+'
'+this.#m(r.reblog.content)+"
":r.reblog&&""!==r.reblog.content&&""===r.reblog.spoiler_text?'
'+this.#m(r.reblog.content)+"
":'
'+this.#m(r.content)+"
";let _=[];if(r.media_attachments.length>0)for(let w in r.media_attachments)_.push(this.#n(r.media_attachments[w],r.sensitive));if(r.reblog&&r.reblog.media_attachments.length>0)for(let y in r.reblog.media_attachments)_.push(this.#n(r.reblog.media_attachments[y],r.reblog.sensitive));let x="";!this.mtSettings.hidePreviewLink&&r.card&&(x=this.#o(r.card));let N="";if(r.poll){let T="";for(let L in r.poll.options)T+="
  • "+r.poll.options[L].title+"
  • ";N='
      '+T+"
    "}let k="";if(!this.mtSettings.hideCounterBar){let C='
    '+b+"
    ",M='
    '+v+"
    ",E='
    '+u+"
    ";k='
    '+C+M+E+"
    "}let B='
    '+m+d+S+"
    "+f+_.join("")+x+N+k+"
    ";return B}#m(P){let H=P;return H=this.#p(H),this.mtSettings.hideEmojos||(H=this.#k(H,this.mtSettings.fetchedData.emojos)),this.mtSettings.markdownBlockquote&&(H=this.#q(H,"

    >","

    ","

    ","

    ")),H}#p(j){let A=j.replaceAll('rel="tag"','rel="tag" target="_blank"');return A.replaceAll('class="u-url mention"','class="u-url mention" target="_blank"')}#q(I,D,U,F,R){if(!I.includes(D))return I;{let z=RegExp(D+"(.*?)"+U,"gi");return I.replace(z,F+"$1"+R)}}#j(q){return(q??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}#k(O,Z){if(!O.includes(":"))return O;for(let V of Z){let J=RegExp(`\\:${V.shortcode}\\:`,"g");O=O.replace(J,`Emoji ${V.shortcode}`)}return O}#l(W){let Y=new Date(W),G=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][Y.getMonth()]+" "+Y.getDate()+", "+Y.getFullYear();return G}#n(K,Q){let X=Q||!1,tt=K.type,te="";return"image"===tt&&(te='
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    '),"audio"===tt&&(te=K.preview_url?'
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    ':'
    '+(X?'":"")+'
    '),("video"===tt||"gifv"===tt)&&(te=this.mtSettings.hideVideoPreview?'
    '+(X?'":"")+'
    ':'
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    '),te}#r(ts){let ti=ts.target.closest("[data-video-url]"),ta=ti.dataset.videoUrl;ti.replaceChildren(),ti.innerHTML=''}#s(to){let tn=to.target.nextSibling;"img"===tn.localName||"audio"===tn.localName||"video"===tn.localName?(to.target.parentNode.classList.remove("mt-post-media-spoiler"),to.target.style.display="none"):(tn.classList.contains("spoiler-txt-hidden")||tn.classList.contains("spoiler-txt-visible"))&&(to.target.textContent==this.mtSettings.btnShowMore?(tn.classList.remove("spoiler-txt-hidden"),tn.classList.add("spoiler-txt-visible"),to.target.setAttribute("aria-expanded","true"),to.target.textContent=this.mtSettings.btnShowLess):(tn.classList.remove("spoiler-txt-visible"),tn.classList.add("spoiler-txt-hidden"),to.target.setAttribute("aria-expanded","false"),to.target.textContent=this.mtSettings.btnShowMore))}#o=function(t){let e=''+(t.image?'
    '+this.#j(t.image_description)+'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+this.#t(t.provider_name)+"":"")+''+t.title+""+(t.author_name?''+this.#t(t.author_name)+"":"")+"
    ";return e};#t(tr){let tl=new DOMParser,tm=tl.parseFromString(tr,"text/html");return tm.body.textContent}#h(){if(this.mtSettings.btnSeeMore||this.mtSettings.btnReload){this.mtSettings.mtBody.parentNode.insertAdjacentHTML("beforeend",'');let td=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("mt-footer")[0];if(this.mtSettings.btnSeeMore){let th="";"profile"===this.mtSettings.timelineType?this.mtSettings.profileName?th=this.mtSettings.profileName:this.#d("Please check your profileName value","⚠️"):"hashtag"===this.mtSettings.timelineType?th="tags/"+this.mtSettings.hashtagName:"local"===this.mtSettings.timelineType&&(th="public/local");let tc=''+this.mtSettings.btnSeeMore+"";td.insertAdjacentHTML("beforeend",tc)}if(this.mtSettings.btnReload){let tg='";td.insertAdjacentHTML("beforeend",tg);let tp=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("btn-refresh")[0];tp.addEventListener("click",()=>{this.mtUpdate()})}}}#g(){this.mtSettings.mtBody.addEventListener("click",t=>{"article"!=t.target.localName&&t.target.offsetParent?.localName!="article"&&("img"!=t.target.localName||t.target.parentNode.getAttribute("data-video-url"))||this.#u(t),"button"==t.target.localName&&t.target.classList.contains("mt-btn-spoiler")&&this.#s(t),("mt-post-media-play-icon"==t.target.className||"svg"==t.target.localName&&"mt-post-media-play-icon"==t.target.parentNode.className||"path"==t.target.localName&&"mt-post-media-play-icon"==t.target.parentNode.parentNode.className||"img"==t.target.localName&&t.target.parentNode.getAttribute("data-video-url"))&&this.#r(t)}),this.mtSettings.mtBody.addEventListener("keydown",t=>{"Enter"===t.key&&"article"==t.target.localName&&this.#u(t)})}#u(tu){let tv=tu.target.closest(".mt-post").dataset.location;"a"!==tu.target.localName&&"span"!==tu.target.localName&&"button"!==tu.target.localName&&"time"!==tu.target.localName&&"mt-post-preview-noImage"!==tu.target.className&&"mt-post-avatar-image-big"!==tu.target.parentNode.className&&"mt-post-avatar-image-small"!==tu.target.parentNode.className&&"mt-post-preview-image"!==tu.target.parentNode.className&&"mt-post-preview"!==tu.target.parentNode.className&&tv&&window.open(tv,"_blank","noopener")}#f(){let tb=t=>{t.target.parentNode.classList.remove(this.mtSettings.spinnerClass),t.target.removeEventListener("load",tb),t.target.removeEventListener("error",tb)};this.mtSettings.mtBody.querySelectorAll(`.${this.mtSettings.spinnerClass} > img`).forEach(t=>{t.addEventListener("load",tb),t.addEventListener("error",tb)})}#d(tS,t$){throw this.mtSettings.mtBody.innerHTML='
    '+(t$||"❌")+'
    Oops, something\'s happened:
    '+tS+"
    ",this.mtSettings.mtBody.setAttribute("role","none"),Error("Stopping the script due to an error building the timeline.")}} +*/ "use strict";class MastodonTimeline{constructor(t={}){this.defaultSettings={mtContainerId:"mt-container",mtBody:"",instanceUrl:"https://mastodon.social",timelineType:"local",userId:"",profileName:"",hashtagName:"",spinnerClass:"mt-loading-spinner",defaultTheme:"auto",maxNbPostFetch:"20",maxNbPostShow:"20",hideUnlisted:!1,hideReblog:!1,hideReplies:!1,hideVideoPreview:!1,hidePreviewLink:!1,hideEmojos:!1,markdownBlockquote:!1,hideCounterBar:!1,txtMaxLines:"0",btnShowMore:"SHOW MORE",btnShowLess:"SHOW LESS",btnShowContent:"SHOW CONTENT",btnSeeMore:"See more posts at Mastodon",btnReload:"Refresh",fetchedData:{}},this.mtSettings={...this.defaultSettings,...t},this.mtSettings.mtBody=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("mt-body")[0],this.mtInit()}mtInit(){this.#a(),this.#b("newTimeline")}mtUpdate(){this.mtSettings.mtBody.replaceChildren(),this.mtSettings.mtBody.insertAdjacentHTML("afterbegin",'
    '),this.#b("updateTimeline")}mtColorTheme(t){document.getElementById(this.mtSettings.mtContainerId).setAttribute("data-theme",t)}#a(){if("auto"===this.mtSettings.defaultTheme){let t=window.matchMedia("(prefers-color-scheme: dark)");t.matches?this.mtColorTheme("dark"):this.mtColorTheme("light"),t.addEventListener("change",t=>{t.matches?this.mtColorTheme("dark"):this.mtColorTheme("light")})}else this.mtColorTheme(this.mtSettings.defaultTheme)}#c(){return new Promise((t,e)=>{async function s(t){let e=await fetch(t);if(!e.ok)throw Error("Failed to fetch the following Url:
    "+t+"
    Error status: "+e.status+"
    Error message: "+e.statusText);let s=await e.json();return s}let i={};this.mtSettings.instanceUrl?"profile"===this.mtSettings.timelineType?this.mtSettings.userId?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/accounts/${this.mtSettings.userId}/statuses?limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your userId value","⚠️"):"hashtag"===this.mtSettings.timelineType?this.mtSettings.hashtagName?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/timelines/tag/${this.mtSettings.hashtagName}?limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your hashtagName value","⚠️"):"local"===this.mtSettings.timelineType?i.timeline=`${this.mtSettings.instanceUrl}/api/v1/timelines/public?local=true&limit=${this.mtSettings.maxNbPostFetch}`:this.#d("Please check your timelineType value","⚠️"):this.#d("Please check your instanceUrl value","⚠️"),this.mtSettings.hideEmojos||(i.emojos=this.mtSettings.instanceUrl+"/api/v1/custom_emojis");let a=Object.entries(i).map(([t,i])=>s(i).then(e=>({[t]:e})).catch(s=>(e(Error("Something went wrong fetching data from: "+i)),this.#d(s.message),{[t]:[]})));Promise.all(a).then(e=>{this.mtSettings.fetchedData=e.reduce((t,e)=>({...t,...e}),{}),t()})})}async #b(e){await this.#c(),this.mtSettings.mtBody.replaceChildren();let s=0;for(let i in this.mtSettings.fetchedData.timeline)("public"==this.mtSettings.fetchedData.timeline[i].visibility||!this.mtSettings.hideUnlisted&&"unlisted"==this.mtSettings.fetchedData.timeline[i].visibility)&&(this.mtSettings.hideReblog&&this.mtSettings.fetchedData.timeline[i].reblog||this.mtSettings.hideReplies&&this.mtSettings.fetchedData.timeline[i].in_reply_to_id||sThis may be due to an incorrect configuration in the parameters or to filters applied (to hide certains type of posts)";this.#d(a,"\uD83D\uDCED")}else"newTimeline"===e?(this.#f(),this.#g(),this.#h()):"updateTimeline"===e?this.#f():this.#d("The function buildTimeline() was expecting a param")}#e(o,n){this.mtSettings.mtBody.insertAdjacentHTML("beforeend",this.#i(o,n))}#i(r,l){let m,d,h,c,g,p,u,v,b;r.reblog?(c=r.reblog.url,m='
    '+this.#j(r.reblog.account.username)+' avatar
    '+this.#j(r.account.username)+' avatar
    ',h=r.reblog.account.display_name?r.reblog.account.display_name:r.reblog.account.username,this.mtSettings.hideEmojos||(h=this.#k(h,this.mtSettings.fetchedData.emojos)),d='
    '+h+' account
    ',g=r.reblog.created_at,b=r.reblog.replies_count,v=r.reblog.reblogs_count,u=r.reblog.favourites_count):(c=r.url,m='
    '+this.#j(r.account.username)+' avatar
    ',h=r.account.display_name?r.account.display_name:r.account.username,this.mtSettings.hideEmojos||(h=this.#k(h,this.mtSettings.fetchedData.emojos)),d='
    '+h+' account
    ',g=r.created_at,b=r.replies_count,v=r.reblogs_count,u=r.favourites_count),p=this.#l(g);let S='
    ",$="";"0"!==this.mtSettings.txtMaxLines&&($=" truncate",this.mtSettings.mtBody.parentNode.style.setProperty("--mt-txt-max-lines",this.mtSettings.txtMaxLines));let f="";f=""!==r.spoiler_text?'
    '+r.spoiler_text+'
    '+this.#m(r.content)+"
    ":r.reblog&&""!==r.reblog.content&&""!==r.reblog.spoiler_text?'
    '+r.reblog.spoiler_text+'
    '+this.#m(r.reblog.content)+"
    ":r.reblog&&""!==r.reblog.content&&""===r.reblog.spoiler_text?'
    '+this.#m(r.reblog.content)+"
    ":'
    '+this.#m(r.content)+"
    ";let _=[];if(r.media_attachments.length>0)for(let w in r.media_attachments)_.push(this.#n(r.media_attachments[w],r.sensitive));if(r.reblog&&r.reblog.media_attachments.length>0)for(let y in r.reblog.media_attachments)_.push(this.#n(r.reblog.media_attachments[y],r.reblog.sensitive));let x="";!this.mtSettings.hidePreviewLink&&r.card&&(x=this.#o(r.card));let N="";if(r.poll){let T="";for(let L in r.poll.options)T+="
  • "+r.poll.options[L].title+"
  • ";N='
      '+T+"
    "}let k="";if(!this.mtSettings.hideCounterBar){let C='
    '+b+"
    ",E='
    '+v+"
    ",M='
    '+u+"
    ";k='
    '+C+E+M+"
    "}let B='
    '+m+d+S+"
    "+f+_.join("")+x+N+k+"
    ";return B}#m(P){let H=P;return H=this.#p(H),this.mtSettings.hideEmojos||(H=this.#k(H,this.mtSettings.fetchedData.emojos)),this.mtSettings.markdownBlockquote&&(H=this.#q(H,"

    >","

    ","

    ","

    ")),H}#p(j){let A=j.replaceAll('rel="tag"','rel="tag" target="_blank"');return A.replaceAll('class="u-url mention"','class="u-url mention" target="_blank"')}#q(I,D,U,F,R){if(!I.includes(D))return I;{let z=RegExp(D+"(.*?)"+U,"gi");return I.replace(z,F+"$1"+R)}}#j(q){return(q??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}#k(O,Z){if(!O.includes(":"))return O;for(let V of Z){let J=RegExp(`\\:${V.shortcode}\\:`,"g");O=O.replace(J,`Emoji ${V.shortcode}`)}return O}#l(W){let Y=new Date(W),G=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][Y.getMonth()]+" "+Y.getDate()+", "+Y.getFullYear();return G}#n(K,Q){let X=Q||!1,tt=K.type,te="";return"image"===tt&&(te='
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    '),"audio"===tt&&(te=K.preview_url?'
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    ':'
    '+(X?'":"")+'
    '),("video"===tt||"gifv"===tt)&&(te=this.mtSettings.hideVideoPreview?'
    '+(X?'":"")+'
    ':'
    '+(X?'":"")+''+(K.description?this.#j(K.description):
    '),te}#r(ts){let ti=ts.target.closest("[data-video-url]"),ta=ti.dataset.videoUrl;ti.replaceChildren(),ti.innerHTML=''}#s(to){let tn=to.target.nextSibling;"img"===tn.localName||"audio"===tn.localName||"video"===tn.localName?(to.target.parentNode.classList.remove("mt-post-media-spoiler"),to.target.style.display="none"):(tn.classList.contains("spoiler-txt-hidden")||tn.classList.contains("spoiler-txt-visible"))&&(to.target.textContent==this.mtSettings.btnShowMore?(tn.classList.remove("spoiler-txt-hidden"),tn.classList.add("spoiler-txt-visible"),to.target.setAttribute("aria-expanded","true"),to.target.textContent=this.mtSettings.btnShowLess):(tn.classList.remove("spoiler-txt-visible"),tn.classList.add("spoiler-txt-hidden"),to.target.setAttribute("aria-expanded","false"),to.target.textContent=this.mtSettings.btnShowMore))}#o=function(t){let e=''+(t.image?'
    '+this.#j(t.image_description)+'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+this.#t(t.provider_name)+"":"")+''+t.title+""+(t.author_name?''+this.#t(t.author_name)+"":"")+"
    ";return e};#t(tr){let tl=new DOMParser,tm=tl.parseFromString(tr,"text/html");return tm.body.textContent}#h(){if(this.mtSettings.btnSeeMore||this.mtSettings.btnReload){this.mtSettings.mtBody.parentNode.insertAdjacentHTML("beforeend",'');let td=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("mt-footer")[0];if(this.mtSettings.btnSeeMore){let th="";"profile"===this.mtSettings.timelineType?this.mtSettings.profileName?th=this.mtSettings.profileName:this.#d("Please check your profileName value","⚠️"):"hashtag"===this.mtSettings.timelineType?th="tags/"+this.mtSettings.hashtagName:"local"===this.mtSettings.timelineType&&(th="public/local");let tc=''+this.mtSettings.btnSeeMore+"";td.insertAdjacentHTML("beforeend",tc)}if(this.mtSettings.btnReload){let tg='";td.insertAdjacentHTML("beforeend",tg);let tp=document.getElementById(this.mtSettings.mtContainerId).getElementsByClassName("btn-refresh")[0];tp.addEventListener("click",()=>{this.mtUpdate()})}}}#g(){this.mtSettings.mtBody.addEventListener("click",t=>{"article"!=t.target.localName&&t.target.offsetParent?.localName!="article"&&("img"!=t.target.localName||t.target.parentNode.getAttribute("data-video-url"))||this.#u(t),"button"==t.target.localName&&t.target.classList.contains("mt-btn-spoiler")&&this.#s(t),("mt-post-media-play-icon"==t.target.className||"svg"==t.target.localName&&"mt-post-media-play-icon"==t.target.parentNode.className||"path"==t.target.localName&&"mt-post-media-play-icon"==t.target.parentNode.parentNode.className||"img"==t.target.localName&&t.target.parentNode.getAttribute("data-video-url"))&&this.#r(t)}),this.mtSettings.mtBody.addEventListener("keydown",t=>{"Enter"===t.key&&"article"==t.target.localName&&this.#u(t)})}#u(tu){let tv=tu.target.closest(".mt-post").dataset.location;"a"!==tu.target.localName&&"span"!==tu.target.localName&&"button"!==tu.target.localName&&"time"!==tu.target.localName&&"mt-post-preview-noImage"!==tu.target.className&&"mt-post-avatar-image-big"!==tu.target.parentNode.className&&"mt-post-avatar-image-small"!==tu.target.parentNode.className&&"mt-post-preview-image"!==tu.target.parentNode.className&&"mt-post-preview"!==tu.target.parentNode.className&&tv&&window.open(tv,"_blank","noopener")}#f(){let tb=t=>{t.target.parentNode.classList.remove(this.mtSettings.spinnerClass),t.target.removeEventListener("load",tb),t.target.removeEventListener("error",tb)};this.mtSettings.mtBody.querySelectorAll(`.${this.mtSettings.spinnerClass} > img`).forEach(t=>{t.addEventListener("load",tb),t.addEventListener("error",tb)})}#d(tS,t$){throw this.mtSettings.mtBody.innerHTML='
    '+(t$||"❌")+'
    Oops, something\'s happened:
    '+tS+"
    ",this.mtSettings.mtBody.setAttribute("role","none"),Error("Stopping the script due to an error building the timeline.")}} diff --git a/examples/js/mastodon-timeline.js b/examples/js/mastodon-timeline.js index fb6f135..b645055 100644 --- a/examples/js/mastodon-timeline.js +++ b/examples/js/mastodon-timeline.js @@ -52,7 +52,7 @@ class MastodonTimeline { * Initialize and build the timeline */ mtInit() { - console.log("Init Mastodon timeline. Settings: ", this.mtSettings); + // console.log("Init Mastodon timeline. Settings: ", this.mtSettings); this.#loadColorTheme(); this.#buildTimeline("newTimeline"); } @@ -186,7 +186,7 @@ class MastodonTimeline { return { ...result, ...dataItem }; }, {}); - console.log("Timeline data fetched: ", this.mtSettings.fetchedData); + // console.log("Timeline data fetched: ", this.mtSettings.fetchedData); resolve(); }); }); @@ -311,12 +311,15 @@ class MastodonTimeline { ""; // User name and url - userName = this.#createEmoji( - c.reblog.account.display_name - ? c.reblog.account.display_name - : c.reblog.account.username, - this.mtSettings.fetchedData.emojos - ); + userName = c.reblog.account.display_name + ? c.reblog.account.display_name + : c.reblog.account.username; + if (!this.mtSettings.hideEmojos) { + userName = this.#createEmoji( + userName, + this.mtSettings.fetchedData.emojos + ); + } user = '
    ' + '"; // User name and url - userName = this.#createEmoji( - c.account.display_name ? c.account.display_name : c.account.username, - this.mtSettings.fetchedData.emojos - ); + userName = c.account.display_name + ? c.account.display_name + : c.account.username; + if (!this.mtSettings.hideEmojos) { + userName = this.#createEmoji( + userName, + this.mtSettings.fetchedData.emojos + ); + } user = '
    ' + '"; // User name and url - userName = this.#createEmoji( - c.reblog.account.display_name - ? c.reblog.account.display_name - : c.reblog.account.username, - this.mtSettings.fetchedData.emojos - ); + userName = c.reblog.account.display_name + ? c.reblog.account.display_name + : c.reblog.account.username; + if (!this.mtSettings.hideEmojos) { + userName = this.#createEmoji( + userName, + this.mtSettings.fetchedData.emojos + ); + } user = '
    ' + '"; // User name and url - userName = this.#createEmoji( - c.account.display_name ? c.account.display_name : c.account.username, - this.mtSettings.fetchedData.emojos - ); + userName = c.account.display_name + ? c.account.display_name + : c.account.username; + if (!this.mtSettings.hideEmojos) { + userName = this.#createEmoji( + userName, + this.mtSettings.fetchedData.emojos + ); + } user = '
    ' + '