From fb5c35c45b15478351153479a12463af42bdc4c3 Mon Sep 17 00:00:00 2001 From: idotj Date: Tue, 16 Jan 2024 16:45:52 +0100 Subject: [PATCH] Fix truncate css class name + rename js variable --- CHANGELOG | 3 +++ src/mastodon-timeline.css | 2 +- src/mastodon-timeline.js | 45 +++++++++++++++++++----------------- src/mastodon-timeline.min.js | 2 +- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 262d164..1828b41 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +v3.13.2 - 16/01/2024 +- Fix truncate CSS class name + v3.13.1 - 12/01/2024 - Add support for audio player - Add support for video player diff --git a/src/mastodon-timeline.css b/src/mastodon-timeline.css index 09b9160..e870efc 100644 --- a/src/mastodon-timeline.css +++ b/src/mastodon-timeline.css @@ -1,4 +1,4 @@ -/* Mastodon embed feed timeline v3.13.1 */ +/* Mastodon embed feed timeline v3.13.2 */ /* More info at: */ /* https://gitlab.com/idotj/mastodon-embed-feed-timeline */ diff --git a/src/mastodon-timeline.js b/src/mastodon-timeline.js index d0d7b89..c7e096d 100644 --- a/src/mastodon-timeline.js +++ b/src/mastodon-timeline.js @@ -1,5 +1,5 @@ /** - * Mastodon embed feed timeline v3.13.1 + * Mastodon embed feed timeline v3.13.2 * More info at: * https://gitlab.com/idotj/mastodon-embed-feed-timeline */ @@ -75,7 +75,9 @@ window.addEventListener("load", () => { * Trigger main function to build the timeline */ const MastodonApi = function (params_) { - this.CONTAINER_BODY_ID = params_.container_body_id || "mt-body"; + this.CONTAINER_BODY_ID = document.getElementById( + params_.container_body_id || "mt-body" + ); this.SPINNER_CLASS = params_.spinner_class || "loading-spinner"; this.DEFAULT_THEME = params_.default_theme || "auto"; this.INSTANCE_URL = params_.instance_url; @@ -112,8 +114,6 @@ const MastodonApi = function (params_) { this.LINK_SEE_MORE = params_.link_see_more; this.FETCHED_DATA = {}; - this.mtBodyContainer = document.getElementById(this.CONTAINER_BODY_ID); - this.buildTimeline(); }; @@ -128,7 +128,7 @@ MastodonApi.prototype.buildTimeline = async function () { await this.getTimelineData(); // Empty the
container - this.mtBodyContainer.innerHTML = ""; + this.CONTAINER_BODY_ID.innerHTML = ""; for (let i in this.FETCHED_DATA.timeline) { // First filter (Public / Unlisted) @@ -151,9 +151,9 @@ MastodonApi.prototype.buildTimeline = async function () { } // Check if there are toots in the container (due to filters applied) - if (this.mtBodyContainer.innerHTML === "") { - this.mtBodyContainer.setAttribute("role", "none"); - this.mtBodyContainer.innerHTML = + if (this.CONTAINER_BODY_ID.innerHTML === "") { + this.CONTAINER_BODY_ID.setAttribute("role", "none"); + this.CONTAINER_BODY_ID.innerHTML = '
📭
Sorry, no toots to show
Got ' + this.FETCHED_DATA.timeline.length + " toots from the server.
This may be due to an incorrect configuration in the parameters or to filters applied to hide certains type of toots.
"; @@ -176,7 +176,7 @@ MastodonApi.prototype.buildTimeline = async function () { '" target="_blank" rel="nofollow noopener noreferrer">' + this.LINK_SEE_MORE + "
"; - this.mtBodyContainer.parentNode.insertAdjacentHTML( + this.CONTAINER_BODY_ID.parentNode.insertAdjacentHTML( "beforeend", linkSeeMore ); @@ -187,7 +187,7 @@ MastodonApi.prototype.buildTimeline = async function () { } // Toot interactions - this.mtBodyContainer.addEventListener("click", function (e) { + this.CONTAINER_BODY_ID.addEventListener("click", function (e) { // Check if toot cointainer was clicked if ( e.target.localName == "article" || @@ -215,7 +215,7 @@ MastodonApi.prototype.buildTimeline = async function () { loadTootVideo(e); } }); - this.mtBodyContainer.addEventListener("keydown", function (e) { + this.CONTAINER_BODY_ID.addEventListener("keydown", function (e) { // Check if Enter key was pressed with focus in an article if (e.key === "Enter" && e.target.localName == "article") { openTootURL(e); @@ -360,11 +360,11 @@ MastodonApi.prototype.getTimelineData = async function () { .then((data) => ({ [key]: data })) .catch((error) => { reject(new Error("Something went wrong fetching data")); - this.mtBodyContainer.innerHTML = + this.CONTAINER_BODY_ID.innerHTML = '

Sorry, request failed:
' + error.message + "
"; - this.mtBodyContainer.setAttribute("role", "none"); + this.CONTAINER_BODY_ID.setAttribute("role", "none"); return { [key]: [] }; }); }); @@ -387,7 +387,10 @@ MastodonApi.prototype.getTimelineData = async function () { * @param {number} i Index of toot */ MastodonApi.prototype.appendToot = function (c, i) { - this.mtBodyContainer.insertAdjacentHTML("beforeend", this.assambleToot(c, i)); + this.CONTAINER_BODY_ID.insertAdjacentHTML( + "beforeend", + this.assambleToot(c, i) + ); }; /** @@ -521,7 +524,7 @@ MastodonApi.prototype.assambleToot = function (c, i) { // Main text let text_css = ""; if (this.TEXT_MAX_LINES !== "0") { - text_css = "truncate"; + text_css = " truncate"; document.documentElement.style.setProperty( "--text-max-lines", this.TEXT_MAX_LINES @@ -959,10 +962,10 @@ MastodonApi.prototype.manageSpinner = function () { }; // Add listener to images - this.mtBodyContainer - .querySelectorAll(`.${this.SPINNER_CLASS} > img`) - .forEach((e) => { - e.addEventListener("load", removeSpinner); - e.addEventListener("error", removeSpinner); - }); + this.CONTAINER_BODY_ID.querySelectorAll( + `.${this.SPINNER_CLASS} > img` + ).forEach((e) => { + e.addEventListener("load", removeSpinner); + e.addEventListener("error", removeSpinner); + }); }; diff --git a/src/mastodon-timeline.min.js b/src/mastodon-timeline.min.js index 9e4a0eb..59645f6 100644 --- a/src/mastodon-timeline.min.js +++ b/src/mastodon-timeline.min.js @@ -1 +1 @@ -window.addEventListener("load",()=>{new MastodonApi({container_body_id:"mt-body",spinner_class:"loading-spinner",default_theme:"auto",instance_url:"https://mastdn.social",timeline_type:"local",user_id:"",profile_name:"",hashtag_name:"",toots_limit:"20",hide_unlisted:!1,hide_reblog:!1,hide_replies:!1,hide_video_preview:!1,hide_preview_link:!1,hide_emojos:!1,markdown_blockquote:!1,hide_counter_bar:!1,text_max_lines:"0",link_see_more:"See more posts at Mastodon"})});const MastodonApi=function(t){this.CONTAINER_BODY_ID=t.container_body_id||"mt-body",this.SPINNER_CLASS=t.spinner_class||"loading-spinner",this.DEFAULT_THEME=t.default_theme||"auto",this.INSTANCE_URL=t.instance_url,this.USER_ID=t.user_id||"",this.PROFILE_NAME=this.USER_ID?t.profile_name:"",this.TIMELINE_TYPE=t.timeline_type||"local",this.HASHTAG_NAME=t.hashtag_name||"",this.TOOTS_LIMIT=t.toots_limit||"20",this.HIDE_UNLISTED=void 0!==t.hide_unlisted&&t.hide_unlisted,this.HIDE_REBLOG=void 0!==t.hide_reblog&&t.hide_reblog,this.HIDE_REPLIES=void 0!==t.hide_replies&&t.hide_replies,this.HIDE_VIDEO_PREVIEW=void 0!==t.hide_video_preview&&t.hide_video_preview,this.HIDE_PREVIEW_LINK=void 0!==t.hide_preview_link&&t.hide_preview_link,this.HIDE_EMOJOS=void 0!==t.hide_emojos&&t.hide_emojos,this.MARKDOWN_BLOCKQUOTE=void 0!==t.markdown_blockquote&&t.markdown_blockquote,this.HIDE_COUNTER_BAR="undefined"!==t.hide_counter_bar&&t.hide_counter_bar,this.TEXT_MAX_LINES=t.text_max_lines||"0",this.LINK_SEE_MORE=t.link_see_more,this.FETCHED_DATA={},this.mtBodyContainer=document.getElementById(this.CONTAINER_BODY_ID),this.buildTimeline()};MastodonApi.prototype.buildTimeline=async function(){for(let t in this.setTheme(),await this.getTimelineData(),this.mtBodyContainer.innerHTML="",this.FETCHED_DATA.timeline)("public"==this.FETCHED_DATA.timeline[t].visibility||!this.HIDE_UNLISTED&&"unlisted"==this.FETCHED_DATA.timeline[t].visibility)&&(this.HIDE_REBLOG&&this.FETCHED_DATA.timeline[t].reblog||this.HIDE_REPLIES&&this.FETCHED_DATA.timeline[t].in_reply_to_id||this.appendToot(this.FETCHED_DATA.timeline[t],Number(t)));if(""===this.mtBodyContainer.innerHTML)this.mtBodyContainer.setAttribute("role","none"),this.mtBodyContainer.innerHTML='
\uD83D\uDCED
Sorry, no toots to show
Got '+this.FETCHED_DATA.timeline.length+" toots from the server.
This may be due to an incorrect configuration in the parameters or to filters applied to hide certains type of toots.
";else{if(this.LINK_SEE_MORE){let e="";"profile"===this.TIMELINE_TYPE?e=this.PROFILE_NAME:"hashtag"===this.TIMELINE_TYPE?e="tags/"+this.HASHTAG_NAME:"local"===this.TIMELINE_TYPE&&(e="public/local");let o='";this.mtBodyContainer.parentNode.insertAdjacentHTML("beforeend",o)}this.manageSpinner()}this.mtBodyContainer.addEventListener("click",function(t){"article"!=t.target.localName&&t.target.offsetParent?.localName!="article"&&("img"!=t.target.localName||t.target.parentNode.classList.contains("video-ratio14_7"))||i(t),"button"==t.target.localName&&"spoiler-btn"==t.target.className&&a(t),("mt-toot-media-play-icon"==t.target.className||"svg"==t.target.localName&&"mt-toot-media-play-icon"==t.target.parentNode.className||"path"==t.target.localName&&"mt-toot-media-play-icon"==t.target.parentNode.parentNode.className||"img"==t.target.localName&&t.target.parentNode.classList.contains("video-ratio14_7"))&&s(t)}),this.mtBodyContainer.addEventListener("keydown",function(t){"Enter"===t.key&&"article"==t.target.localName&&i(t)});let i=function(t){let e=t.target.closest(".mt-toot").dataset.location;"a"!==t.target.localName&&"span"!==t.target.localName&&"button"!==t.target.localName&&"time"!==t.target.localName&&"mt-toot-preview-noImage"!==t.target.className&&"mt-toot-avatar-image-big"!==t.target.parentNode.className&&"mt-toot-avatar-image-small"!==t.target.parentNode.className&&"mt-toot-preview-image"!==t.target.parentNode.className&&"mt-toot-preview"!==t.target.parentNode.className&&e&&window.open(e,"_blank","noopener")},a=function(t){let e=t.target.nextSibling;"img"===e.localName||"audio"===e.localName||"video"===e.localName?(t.target.parentNode.classList.remove("mt-toot-media-spoiler"),t.target.style.display="none"):(e.classList.contains("spoiler-text-hidden")||e.classList.contains("spoiler-text-visible"))&&("Show more"==t.target.textContent?(e.classList.remove("spoiler-text-hidden"),e.classList.add("spoiler-text-visible"),t.target.setAttribute("aria-expanded","true"),t.target.textContent="Show less"):(e.classList.remove("spoiler-text-visible"),e.classList.add("spoiler-text-hidden"),t.target.setAttribute("aria-expanded","false"),t.target.textContent="Show more"))},s=function(t){let e=t.target.closest("[data-video-url]"),o=e.dataset.videoUrl;e.replaceChildren(),e.innerHTML=''}},MastodonApi.prototype.setTheme=function(){let t=function(t){document.documentElement.setAttribute("data-theme",t)};if("auto"===this.DEFAULT_THEME){let e=window.matchMedia("(prefers-color-scheme: dark)");e.matches?t("dark"):t("light"),e.addEventListener("change",e=>{e.matches?t("dark"):t("light")})}else t(this.DEFAULT_THEME)},MastodonApi.prototype.getTimelineData=async function(){return new Promise((t,e)=>{async function o(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 o=await e.json();return o}let i={};"profile"===this.TIMELINE_TYPE?i.timeline=`${this.INSTANCE_URL}/api/v1/accounts/${this.USER_ID}/statuses?limit=${this.TOOTS_LIMIT}`:"hashtag"===this.TIMELINE_TYPE?i.timeline=`${this.INSTANCE_URL}/api/v1/timelines/tag/${this.HASHTAG_NAME}?limit=${this.TOOTS_LIMIT}`:"local"===this.TIMELINE_TYPE&&(i.timeline=`${this.INSTANCE_URL}/api/v1/timelines/public?local=true&limit=${this.TOOTS_LIMIT}`),this.HIDE_EMOJOS||(i.emojos=this.INSTANCE_URL+"/api/v1/custom_emojis");let a=Object.entries(i).map(([t,i])=>o(i).then(e=>({[t]:e})).catch(o=>(e(Error("Something went wrong fetching data")),this.mtBodyContainer.innerHTML='

Sorry, request failed:
'+o.message+"
",this.mtBodyContainer.setAttribute("role","none"),{[t]:[]})));Promise.all(a).then(e=>{this.FETCHED_DATA=e.reduce((t,e)=>({...t,...e}),{}),t()})})},MastodonApi.prototype.appendToot=function(t,e){this.mtBodyContainer.insertAdjacentHTML("beforeend",this.assambleToot(t,e))},MastodonApi.prototype.assambleToot=function(t,e){let o,i,a,s,r,n,l,d,c;t.reblog?(s=t.reblog.url,o='
'+this.escapeHtml(t.reblog.account.username)+' avatar
'+this.escapeHtml(t.account.username)+' avatar
',a=this.showEmojos(t.reblog.account.display_name?t.reblog.account.display_name:t.reblog.account.username,this.FETCHED_DATA.emojos),i='
'+a+' account
',r=t.reblog.created_at,c=t.reblog.replies_count,d=t.reblog.reblogs_count,l=t.reblog.favourites_count):(s=t.url,o='
'+this.escapeHtml(t.account.username)+' avatar
',a=this.showEmojos(t.account.display_name?t.account.display_name:t.account.username,this.FETCHED_DATA.emojos),i='
'+a+' account
',r=t.created_at,c=t.replies_count,d=t.reblogs_count,l=t.favourites_count),n=this.formatDate(r);let m='
",p="";"0"!==this.TEXT_MAX_LINES&&(p="truncate",document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES));let h="";h=""!==t.spoiler_text?'
'+t.spoiler_text+'
'+this.formatTootText(t.content)+"
":t.reblog&&""!==t.reblog.content&&""!==t.reblog.spoiler_text?'
'+t.reblog.spoiler_text+'
'+this.formatTootText(t.reblog.content)+"
":t.reblog&&""!==t.reblog.content&&""===t.reblog.spoiler_text?'
'+this.formatTootText(t.reblog.content)+"
":'
'+this.formatTootText(t.content)+"
";let u=[];if(t.media_attachments.length>0)for(let v in t.media_attachments)u.push(this.placeMedias(t.media_attachments[v],t.sensitive));if(t.reblog&&t.reblog.media_attachments.length>0)for(let g in t.reblog.media_attachments)u.push(this.placeMedias(t.reblog.media_attachments[g],t.reblog.sensitive));let E="";!this.HIDE_PREVIEW_LINK&&t.card&&(E=this.placePreviewLink(t.card));let b="";if(t.poll){let T="";for(let f in t.poll.options)T+="
  • "+t.poll.options[f].title+"
  • ";b='
    "}let _="";if(!this.HIDE_COUNTER_BAR){let A='
    '+c+"
    ",$='
    '+d+"
    ",N='
    '+l+"
    ";_='
    '+A+$+N+"
    "}let L='
    '+o+i+m+"
    "+h+u.join("")+E+b+_+"
    ";return L},MastodonApi.prototype.formatTootText=function(t){let e=t;return e=this.addTarget2hashtagMention(e),this.HIDE_EMOJOS||(e=this.showEmojos(e,this.FETCHED_DATA.emojos)),this.MARKDOWN_BLOCKQUOTE&&(e=this.replaceHTMLtag(e,"

    >","

    ","

    ","

    ")),e},MastodonApi.prototype.addTarget2hashtagMention=function(t){let e=t.replaceAll('rel="tag"','rel="tag" target="_blank"');return e.replaceAll('class="u-url mention"','class="u-url mention" target="_blank"')},MastodonApi.prototype.showEmojos=function(t,e){if(!t.includes(":"))return t;for(let o of e){let i=RegExp(`\\:${o.shortcode}\\:`,"g");t=t.replace(i,`Emoji ${o.shortcode}`)}return t},MastodonApi.prototype.replaceHTMLtag=function(t,e,o,i,a){if(!t.includes(e))return t;{let s=RegExp(e+"(.*?)"+o,"gi");return t.replace(s,i+"$1"+a)}},MastodonApi.prototype.placeMedias=function(t,e){let o=e||!1,i=t.type,a="";return"image"===i&&(a='
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    '),"audio"===i&&(a=t.preview_url?'
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    ':'
    '+(o?'':"")+'
    '),"video"===i&&(a=this.HIDE_VIDEO_PREVIEW?'
    '+(o?'':"")+'
    ':'
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    '),a},MastodonApi.prototype.placePreviewLink=function(t){let e=''+(t.image?'
    '+this.escapeHtml(t.image_description)+'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+this.parseHTMLstring(t.provider_name)+"":"")+''+t.title+""+(t.author_name?''+this.parseHTMLstring(t.author_name)+"":"")+"
    ";return e},MastodonApi.prototype.formatDate=function(t){let e=new Date(t),o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][e.getMonth()]+" "+e.getDate()+", "+e.getFullYear();return o},MastodonApi.prototype.parseHTMLstring=function(t){let e=new DOMParser,o=e.parseFromString(t,"text/html");return o.body.textContent},MastodonApi.prototype.escapeHtml=function(t){return(t??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")},MastodonApi.prototype.manageSpinner=function(){let t=this.SPINNER_CLASS,e=function(){this.parentNode.classList.remove(t),this.removeEventListener("load",e),this.removeEventListener("error",e)};this.mtBodyContainer.querySelectorAll(`.${this.SPINNER_CLASS} > img`).forEach(t=>{t.addEventListener("load",e),t.addEventListener("error",e)})}; +window.addEventListener("load",()=>{new MastodonApi({container_body_id:"mt-body",spinner_class:"loading-spinner",default_theme:"auto",instance_url:"https://mastdn.social",timeline_type:"local",user_id:"",profile_name:"",hashtag_name:"",toots_limit:"20",hide_unlisted:!1,hide_reblog:!1,hide_replies:!1,hide_video_preview:!1,hide_preview_link:!1,hide_emojos:!1,markdown_blockquote:!1,hide_counter_bar:!1,text_max_lines:"0",link_see_more:"See more posts at Mastodon"})});const MastodonApi=function(t){this.CONTAINER_BODY_ID=document.getElementById(t.container_body_id||"mt-body"),this.SPINNER_CLASS=t.spinner_class||"loading-spinner",this.DEFAULT_THEME=t.default_theme||"auto",this.INSTANCE_URL=t.instance_url,this.USER_ID=t.user_id||"",this.PROFILE_NAME=this.USER_ID?t.profile_name:"",this.TIMELINE_TYPE=t.timeline_type||"local",this.HASHTAG_NAME=t.hashtag_name||"",this.TOOTS_LIMIT=t.toots_limit||"20",this.HIDE_UNLISTED=void 0!==t.hide_unlisted&&t.hide_unlisted,this.HIDE_REBLOG=void 0!==t.hide_reblog&&t.hide_reblog,this.HIDE_REPLIES=void 0!==t.hide_replies&&t.hide_replies,this.HIDE_VIDEO_PREVIEW=void 0!==t.hide_video_preview&&t.hide_video_preview,this.HIDE_PREVIEW_LINK=void 0!==t.hide_preview_link&&t.hide_preview_link,this.HIDE_EMOJOS=void 0!==t.hide_emojos&&t.hide_emojos,this.MARKDOWN_BLOCKQUOTE=void 0!==t.markdown_blockquote&&t.markdown_blockquote,this.HIDE_COUNTER_BAR="undefined"!==t.hide_counter_bar&&t.hide_counter_bar,this.TEXT_MAX_LINES=t.text_max_lines||"0",this.LINK_SEE_MORE=t.link_see_more,this.FETCHED_DATA={},this.buildTimeline()};MastodonApi.prototype.buildTimeline=async function(){for(let t in this.setTheme(),await this.getTimelineData(),this.CONTAINER_BODY_ID.innerHTML="",this.FETCHED_DATA.timeline)("public"==this.FETCHED_DATA.timeline[t].visibility||!this.HIDE_UNLISTED&&"unlisted"==this.FETCHED_DATA.timeline[t].visibility)&&(this.HIDE_REBLOG&&this.FETCHED_DATA.timeline[t].reblog||this.HIDE_REPLIES&&this.FETCHED_DATA.timeline[t].in_reply_to_id||this.appendToot(this.FETCHED_DATA.timeline[t],Number(t)));if(""===this.CONTAINER_BODY_ID.innerHTML)this.CONTAINER_BODY_ID.setAttribute("role","none"),this.CONTAINER_BODY_ID.innerHTML='
    \uD83D\uDCED
    Sorry, no toots to show
    Got '+this.FETCHED_DATA.timeline.length+" toots from the server.
    This may be due to an incorrect configuration in the parameters or to filters applied to hide certains type of toots.
    ";else{if(this.LINK_SEE_MORE){let e="";"profile"===this.TIMELINE_TYPE?e=this.PROFILE_NAME:"hashtag"===this.TIMELINE_TYPE?e="tags/"+this.HASHTAG_NAME:"local"===this.TIMELINE_TYPE&&(e="public/local");let o='";this.CONTAINER_BODY_ID.parentNode.insertAdjacentHTML("beforeend",o)}this.manageSpinner()}this.CONTAINER_BODY_ID.addEventListener("click",function(t){"article"!=t.target.localName&&t.target.offsetParent?.localName!="article"&&("img"!=t.target.localName||t.target.parentNode.classList.contains("video-ratio14_7"))||i(t),"button"==t.target.localName&&"spoiler-btn"==t.target.className&&a(t),("mt-toot-media-play-icon"==t.target.className||"svg"==t.target.localName&&"mt-toot-media-play-icon"==t.target.parentNode.className||"path"==t.target.localName&&"mt-toot-media-play-icon"==t.target.parentNode.parentNode.className||"img"==t.target.localName&&t.target.parentNode.classList.contains("video-ratio14_7"))&&s(t)}),this.CONTAINER_BODY_ID.addEventListener("keydown",function(t){"Enter"===t.key&&"article"==t.target.localName&&i(t)});let i=function(t){let e=t.target.closest(".mt-toot").dataset.location;"a"!==t.target.localName&&"span"!==t.target.localName&&"button"!==t.target.localName&&"time"!==t.target.localName&&"mt-toot-preview-noImage"!==t.target.className&&"mt-toot-avatar-image-big"!==t.target.parentNode.className&&"mt-toot-avatar-image-small"!==t.target.parentNode.className&&"mt-toot-preview-image"!==t.target.parentNode.className&&"mt-toot-preview"!==t.target.parentNode.className&&e&&window.open(e,"_blank","noopener")},a=function(t){let e=t.target.nextSibling;"img"===e.localName||"audio"===e.localName||"video"===e.localName?(t.target.parentNode.classList.remove("mt-toot-media-spoiler"),t.target.style.display="none"):(e.classList.contains("spoiler-text-hidden")||e.classList.contains("spoiler-text-visible"))&&("Show more"==t.target.textContent?(e.classList.remove("spoiler-text-hidden"),e.classList.add("spoiler-text-visible"),t.target.setAttribute("aria-expanded","true"),t.target.textContent="Show less"):(e.classList.remove("spoiler-text-visible"),e.classList.add("spoiler-text-hidden"),t.target.setAttribute("aria-expanded","false"),t.target.textContent="Show more"))},s=function(t){let e=t.target.closest("[data-video-url]"),o=e.dataset.videoUrl;e.replaceChildren(),e.innerHTML=''}},MastodonApi.prototype.setTheme=function(){let t=function(t){document.documentElement.setAttribute("data-theme",t)};if("auto"===this.DEFAULT_THEME){let e=window.matchMedia("(prefers-color-scheme: dark)");e.matches?t("dark"):t("light"),e.addEventListener("change",e=>{e.matches?t("dark"):t("light")})}else t(this.DEFAULT_THEME)},MastodonApi.prototype.getTimelineData=async function(){return new Promise((t,e)=>{async function o(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 o=await e.json();return o}let i={};"profile"===this.TIMELINE_TYPE?i.timeline=`${this.INSTANCE_URL}/api/v1/accounts/${this.USER_ID}/statuses?limit=${this.TOOTS_LIMIT}`:"hashtag"===this.TIMELINE_TYPE?i.timeline=`${this.INSTANCE_URL}/api/v1/timelines/tag/${this.HASHTAG_NAME}?limit=${this.TOOTS_LIMIT}`:"local"===this.TIMELINE_TYPE&&(i.timeline=`${this.INSTANCE_URL}/api/v1/timelines/public?local=true&limit=${this.TOOTS_LIMIT}`),this.HIDE_EMOJOS||(i.emojos=this.INSTANCE_URL+"/api/v1/custom_emojis");let a=Object.entries(i).map(([t,i])=>o(i).then(e=>({[t]:e})).catch(o=>(e(Error("Something went wrong fetching data")),this.CONTAINER_BODY_ID.innerHTML='

    Sorry, request failed:
    '+o.message+"
    ",this.CONTAINER_BODY_ID.setAttribute("role","none"),{[t]:[]})));Promise.all(a).then(e=>{this.FETCHED_DATA=e.reduce((t,e)=>({...t,...e}),{}),t()})})},MastodonApi.prototype.appendToot=function(t,e){this.CONTAINER_BODY_ID.insertAdjacentHTML("beforeend",this.assambleToot(t,e))},MastodonApi.prototype.assambleToot=function(t,e){let o,i,a,s,r,l,n,d,c;t.reblog?(s=t.reblog.url,o='
    '+this.escapeHtml(t.reblog.account.username)+' avatar
    '+this.escapeHtml(t.account.username)+' avatar
    ',a=this.showEmojos(t.reblog.account.display_name?t.reblog.account.display_name:t.reblog.account.username,this.FETCHED_DATA.emojos),i='
    '+a+' account
    ',r=t.reblog.created_at,c=t.reblog.replies_count,d=t.reblog.reblogs_count,n=t.reblog.favourites_count):(s=t.url,o='
    '+this.escapeHtml(t.account.username)+' avatar
    ',a=this.showEmojos(t.account.display_name?t.account.display_name:t.account.username,this.FETCHED_DATA.emojos),i='
    '+a+' account
    ',r=t.created_at,c=t.replies_count,d=t.reblogs_count,n=t.favourites_count),l=this.formatDate(r);let m='
    ",p="";"0"!==this.TEXT_MAX_LINES&&(p=" truncate",document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES));let h="";h=""!==t.spoiler_text?'
    '+t.spoiler_text+'
    '+this.formatTootText(t.content)+"
    ":t.reblog&&""!==t.reblog.content&&""!==t.reblog.spoiler_text?'
    '+t.reblog.spoiler_text+'
    '+this.formatTootText(t.reblog.content)+"
    ":t.reblog&&""!==t.reblog.content&&""===t.reblog.spoiler_text?'
    '+this.formatTootText(t.reblog.content)+"
    ":'
    '+this.formatTootText(t.content)+"
    ";let u=[];if(t.media_attachments.length>0)for(let v in t.media_attachments)u.push(this.placeMedias(t.media_attachments[v],t.sensitive));if(t.reblog&&t.reblog.media_attachments.length>0)for(let g in t.reblog.media_attachments)u.push(this.placeMedias(t.reblog.media_attachments[g],t.reblog.sensitive));let E="";!this.HIDE_PREVIEW_LINK&&t.card&&(E=this.placePreviewLink(t.card));let T="";if(t.poll){let b="";for(let N in t.poll.options)b+="
  • "+t.poll.options[N].title+"
  • ";T='
    "}let A="";if(!this.HIDE_COUNTER_BAR){let I='
    '+c+"
    ",f='
    '+d+"
    ",_='
    '+n+"
    ";A='
    '+I+f+_+"
    "}let $='
    '+o+i+m+"
    "+h+u.join("")+E+T+A+"
    ";return $},MastodonApi.prototype.formatTootText=function(t){let e=t;return e=this.addTarget2hashtagMention(e),this.HIDE_EMOJOS||(e=this.showEmojos(e,this.FETCHED_DATA.emojos)),this.MARKDOWN_BLOCKQUOTE&&(e=this.replaceHTMLtag(e,"

    >","

    ","

    ","

    ")),e},MastodonApi.prototype.addTarget2hashtagMention=function(t){let e=t.replaceAll('rel="tag"','rel="tag" target="_blank"');return e.replaceAll('class="u-url mention"','class="u-url mention" target="_blank"')},MastodonApi.prototype.showEmojos=function(t,e){if(!t.includes(":"))return t;for(let o of e){let i=RegExp(`\\:${o.shortcode}\\:`,"g");t=t.replace(i,`Emoji ${o.shortcode}`)}return t},MastodonApi.prototype.replaceHTMLtag=function(t,e,o,i,a){if(!t.includes(e))return t;{let s=RegExp(e+"(.*?)"+o,"gi");return t.replace(s,i+"$1"+a)}},MastodonApi.prototype.placeMedias=function(t,e){let o=e||!1,i=t.type,a="";return"image"===i&&(a='
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    '),"audio"===i&&(a=t.preview_url?'
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    ':'
    '+(o?'':"")+'
    '),"video"===i&&(a=this.HIDE_VIDEO_PREVIEW?'
    '+(o?'':"")+'
    ':'
    '+(o?'':"")+''+(t.description?this.escapeHtml(t.description):
    '),a},MastodonApi.prototype.placePreviewLink=function(t){let e=''+(t.image?'
    '+this.escapeHtml(t.image_description)+'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+this.parseHTMLstring(t.provider_name)+"":"")+''+t.title+""+(t.author_name?''+this.parseHTMLstring(t.author_name)+"":"")+"
    ";return e},MastodonApi.prototype.formatDate=function(t){let e=new Date(t),o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][e.getMonth()]+" "+e.getDate()+", "+e.getFullYear();return o},MastodonApi.prototype.parseHTMLstring=function(t){let e=new DOMParser,o=e.parseFromString(t,"text/html");return o.body.textContent},MastodonApi.prototype.escapeHtml=function(t){return(t??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")},MastodonApi.prototype.manageSpinner=function(){let t=this.SPINNER_CLASS,e=function(){this.parentNode.classList.remove(t),this.removeEventListener("load",e),this.removeEventListener("error",e)};this.CONTAINER_BODY_ID.querySelectorAll(`.${this.SPINNER_CLASS} > img`).forEach(t=>{t.addEventListener("load",e),t.addEventListener("error",e)})};