diff --git a/CHANGELOG b/CHANGELOG index 5f5c677..d9110bb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -v4.0.0 - xx/02/2024 +v4.0.1 - 08/02/2024 +- Fix error in emojis present in user/profile title + +v4.0.0 - 07/02/2024 - Revamped JS (ES6) - Renamed CSS classes - Improved performance @@ -9,7 +12,7 @@ v4.0.0 - xx/02/2024 - Improved theme color management - Improve error messages - Possibility to have several timelines on the same page -- Fixed inconsistency in video aspect ratio +- Fix inconsistency in video aspect ratio v3.13.3 - 16/01/2024 - Add Docker compose diff --git a/dist/mastodon-timeline.min.js b/dist/mastodon-timeline.min.js index 1e93ac9..34f83b8 100644 --- a/dist/mastodon-timeline.min.js +++ b/dist/mastodon-timeline.min.js @@ -1,7 +1,7 @@ /** * Mastodon embed feed timeline * @author idotj - * @version 4.0.0 + * @version 4.0.1 * @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=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='
    "}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 b645055..68d4f1e 100644 --- a/examples/js/mastodon-timeline.js +++ b/examples/js/mastodon-timeline.js @@ -1,7 +1,7 @@ /** * Mastodon embed feed timeline * @author idotj - * @version 4.0.0 + * @version 4.0.1 * @url https://gitlab.com/idotj/mastodon-embed-feed-timeline * @license GNU AGPLv3 */ diff --git a/package.json b/package.json index 9e65b82..be5c18f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@idotj/mastodon-embed-feed-timeline", "description": "Displays Mastodon timeline with posts embed in your website. Very easy to setup, no dependencies, no trackers, cross-browser, WCAG compliant and fully responsive.", - "version": "4.0.0", + "version": "4.0.1", "author": { "name": "idotj" }, diff --git a/src/mastodon-timeline.js b/src/mastodon-timeline.js index b645055..68d4f1e 100644 --- a/src/mastodon-timeline.js +++ b/src/mastodon-timeline.js @@ -1,7 +1,7 @@ /** * Mastodon embed feed timeline * @author idotj - * @version 4.0.0 + * @version 4.0.1 * @url https://gitlab.com/idotj/mastodon-embed-feed-timeline * @license GNU AGPLv3 */