diff --git a/CHANGELOG b/CHANGELOG index 1450e60..831f2a1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +v3.9.4 - 21/09/2023 +- Add replies, reblog (boosts) and favourites counter + v3.9.1 - 06/09/2023 - Fix bug with Markdown-Blockquote function diff --git a/README.md b/README.md index ceb6609..58948d4 100644 --- a/README.md +++ b/README.md @@ -92,17 +92,11 @@ markdown_blockquote: false, // Limit the text content to a maximum number of lines. Default: 0 (unlimited) text_max_lines: "0", +// Hide replies, boosts and favourites toots counter. Default: don't hide +hide_counter_bar: false, + // Customize the text of the link pointing to the Mastodon page (appears after the last toot) link_see_more: "See more posts at Mastodon", - -//set the font icon for replies counter, e.g. (make sure to add FontAwesome to you page to make this sample work) -replies_count_icon: '', - -//set the font icon for boosts counter, e.g. (make sure to add FontAwesome to you page to make this sample work) -boosts_count_icon: '', - -//set the font icon for favourites counter, e.g. (make sure to add FontAwesome to you page to make this sample work) -favourites_count_icon: '', ``` ### Tip diff --git a/src/mastodon-timeline.css b/src/mastodon-timeline.css index 1b6bf22..ded3a6b 100644 --- a/src/mastodon-timeline.css +++ b/src/mastodon-timeline.css @@ -1,4 +1,4 @@ -/* Mastodon embed feed timeline v3.9.1 */ +/* Mastodon embed feed timeline v3.9.4 */ /* More info at: */ /* https://gitlab.com/idotj/mastodon-embed-feed-timeline */ @@ -93,7 +93,7 @@ html[data-theme="dark"] { margin-bottom: 0; } -/* User avatar and name */ +/* User avatar */ .mt-avatar { width: 3rem; height: 3rem; @@ -122,18 +122,29 @@ html[data-theme="dark"] { border-radius: 0.25rem; overflow: hidden; } -.mt-user { - display: table; - font-weight: 600; + +/* User name and date */ +.mt-toot-header { + display: flex; + justify-content: space-between; + align-items: center; margin-bottom: 1rem; } +.mt-user { + font-weight: 600; + padding-right: 1rem; +} .mt-user > a { color: var(--content-text) !important; } +.toot-date { + font-size: 0.75rem; + text-align: right; +} /* Text */ .toot-text { - margin-bottom: 0.25rem; + margin-bottom: 1rem; color: var(--content-text); } .toot-text .spoiler-link { @@ -163,7 +174,6 @@ html[data-theme="dark"] { width: auto; } - /* Poll */ .toot-poll { margin-bottom: 0.25rem; @@ -189,7 +199,7 @@ html[data-theme="dark"] { /* Medias */ .toot-media { overflow: hidden; - margin-bottom: 0.5rem; + margin-bottom: 1rem; } .toot-media-preview { position: relative; @@ -241,7 +251,7 @@ html[data-theme="dark"] { border-radius: 0.5rem; color: var(--link-color); font-size: 0.8rem; - margin: 1rem 0 0.5rem 0; + margin: 1rem 0; overflow: hidden; } .toot-preview-image { @@ -287,9 +297,28 @@ html[data-theme="dark"] { vertical-align: top; } -/* Date */ -.toot-date { +/* Counter bar */ +.mt-counter-bar { + display: flex; + gap: clamp(0.25rem, 1vw, 1.5rem); + color: var(--link-color); +} + +.mt-counter-replies, +.mt-counter-reblog, +.mt-counter-favorites { + display: flex; font-size: 0.75rem; + gap: 0.25rem; + align-items: center; + opacity: 0.5; +} + +.mt-counter-replies > svg, +.mt-counter-reblog > svg, +.mt-counter-favorites > svg { + width: 1rem; + fill: var(--link-color); } /* Error */ diff --git a/src/mastodon-timeline.js b/src/mastodon-timeline.js index bdffc86..e732f55 100644 --- a/src/mastodon-timeline.js +++ b/src/mastodon-timeline.js @@ -1,5 +1,5 @@ /** - * Mastodon embed feed timeline v3.9.1 + * Mastodon embed feed timeline v3.9.4 * More info at: * https://gitlab.com/idotj/mastodon-embed-feed-timeline */ @@ -55,14 +55,8 @@ window.addEventListener("load", () => { // Converts Markdown symbol ">" at the beginning of a paragraph into a blockquote HTML tag. Ddefault: don't apply markdown_blockquote: false, - //set the font icon for replies counter - replies_count_icon: undefined, - - //set the font icon for boosts counter - boosts_count_icon: undefined, - - //set the font icon for favourites counter - favourites_count_icon: undefined, + // Hide replies, boosts and favourites toots counter. Default: don't hide + hide_counter_bar: false, // Limit the text content to a maximum number of lines. Default: 0 (unlimited) text_max_lines: "0", @@ -105,14 +99,12 @@ const MastodonApi = function (params_) { typeof params_.markdown_blockquote !== "undefined" ? params_.markdown_blockquote : false; + this.HIDE_COUNTER_BAR = + params_.hide_counter_bar !== "undefined" ? params_.hide_counter_bar : false; this.TEXT_MAX_LINES = params_.text_max_lines || "0"; this.LINK_SEE_MORE = params_.link_see_more; this.FETCHED_DATA = {}; - this.REPLIES_COUNT_ICON = params_.replies_count_icon || '[Replies]'; - this.BOOSTS_COUNT_ICON = params_.boosts_count_icon || '[Boost]'; - this.FAVOURITES_COUNT_ICON = params_.favourites_count_icon || '[Favourite]'; - this.mtBodyContainer = document.getElementById(this.CONTAINER_BODY_ID); this.buildTimeline(); @@ -192,7 +184,7 @@ MastodonApi.prototype.buildTimeline = async function () { // Check if toot cointainer was clicked if ( e.target.localName == "article" || - e.target.offsetParent.localName == "article" || + e.target.offsetParent?.localName == "article" || (e.target.localName == "img" && e.target.offsetParent.className !== "mt-avatar" && e.target.offsetParent.className !== "mt-avatar-account") @@ -367,7 +359,7 @@ MastodonApi.prototype.appendToot = function (c, i) { * @param {number} i Index of toot */ MastodonApi.prototype.assambleToot = function (c, i) { - let avatar, user, content, url, date; + let avatar, user, url, date; if (c.reblog) { // BOOSTED toot @@ -446,6 +438,16 @@ MastodonApi.prototype.assambleToot = function (c, i) { date = this.formatDate(c.created_at); } + // Date + let timestamp = + '
' + + '' + + date + + "" + + "
"; + // Main text let text_css = ""; if (this.TEXT_MAX_LINES !== "0") { @@ -456,6 +458,7 @@ MastodonApi.prototype.assambleToot = function (c, i) { ); } + let content = ""; if (c.spoiler_text !== "") { content = '
' + @@ -534,32 +537,37 @@ MastodonApi.prototype.assambleToot = function (c, i) { poll = '
' + "" + "
"; } - // Date - const timestamp = - '
' + - '' + - date + - "" + - "
"; + // Counter bar + let counterBar = ""; + if (!this.HIDE_COUNTER_BAR) { + let repliesCount = + '
' + + '' + + c.replies_count + + "
"; - // stats (boosts + favourites counts) >>> - // data - var repliesCountIcon = '' + this.REPLIES_COUNT_ICON +": "+ c.replies_count + ' '; - var boostsCountIcon = '' + this.BOOSTS_COUNT_ICON +": "+ c.reblogs_count + ' '; - var favouritesCountIcon = '' + this.FAVOURITES_COUNT_ICON +": "+ c.favourites_count + ' '; + let reblogCount = + '
' + + '' + + c.reblogs_count + + "
"; - // html nodes - var statusBar = '
' + - repliesCountIcon + - boostsCountIcon + - favouritesCountIcon + - '
'; - + let favoritesCount = + '
' + + '' + + c.favourites_count + + "
"; + + counterBar = + '
' + + repliesCount + + reblogCount + + favoritesCount + + "
"; + } // Add all to main toot container - const toot = + let toot = '
' + avatar + + '
' + user + + timestamp + + "
" + content + media + preview_link + poll + - timestamp + - statusBar + + counterBar + "
"; return toot; diff --git a/src/mastodon-timeline.min.css b/src/mastodon-timeline.min.css index c2af7a7..7da2752 100644 --- a/src/mastodon-timeline.min.css +++ b/src/mastodon-timeline.min.css @@ -1 +1 @@ -:root{--text-max-lines:none}:root,html[data-theme=light]{--bg-color:#fff;--bg-hover-color:#d9e1e8;--line-gray-color:#c0cdd9;--content-text:#000;--link-color:#3a3bff;--error-text-color:#8b0000}html[data-theme=dark]{--bg-color:#282c37;--bg-hover-color:#313543;--line-gray-color:#393f4f;--content-text:#fff;--link-color:#8c8dff;--error-text-color:#fe6c6c}.mt-timeline{height:100%;overflow-y:auto;position:relative;background:var(--bg-color);scrollbar-color:var(--bg-hover-color) rgba(0,0,0,.1)}.mt-timeline a,.mt-timeline a:active,.mt-timeline a:link{text-decoration:none;color:var(--link-color)}.mt-timeline a:not(.toot-preview-link):hover{text-decoration:underline}.mt-timeline::-webkit-scrollbar{width:.75rem;height:.75rem}.mt-timeline::-webkit-scrollbar-corner{background:0 0}.mt-timeline::-webkit-scrollbar-thumb{border:0 var(--content-text);border-radius:2rem;background:var(--bg-hover-color)}.mt-timeline::-webkit-scrollbar-track{border:0 var(--content-text);border-radius:0;background:rgba(0,0,0,.1)}.mt-body{padding:1rem 1.5rem;white-space:pre-wrap;word-wrap:break-word}.mt-body .invisible{font-size:0;line-height:0;display:inline-block;width:0;height:0;position:absolute}.mt-toot{margin:.25rem;padding:1rem .5rem 1.5rem 4rem;position:relative;min-height:3.75rem;background-color:transparent;border-bottom:1px solid var(--line-gray-color)}.mt-toot:focus,.mt-toot:hover{cursor:pointer;background-color:var(--bg-hover-color)}.mt-toot p:last-child{margin-bottom:0}.mt-avatar{width:3rem;height:3rem;position:absolute;top:1rem;left:.25rem;border-radius:.25rem;overflow:hidden}.mt-avatar-image img{width:100%;height:auto}.mt-avatar-image .mt-avatar-boosted{width:2.25rem;height:2.25rem;border-radius:.25rem;overflow:hidden}.mt-avatar-image .mt-avatar-account{width:1.5rem;height:1.5rem;top:1.5rem;left:1.5rem;position:absolute;border-radius:.25rem;overflow:hidden}.mt-user{display:table;font-weight:600;margin-bottom:1rem}.mt-user>a{color:var(--content-text)!important}.toot-text{margin-bottom:.25rem;color:var(--content-text)}.toot-text .spoiler-link{display:inline-block}.toot-text .spoiler-text-hidden{display:none}.toot-text.truncate{display:-webkit-box;overflow:hidden;-webkit-line-clamp:var(--text-max-lines);-webkit-box-orient:vertical}.toot-text:not(.truncate) .ellipsis::after{content:"..."}.toot-text blockquote{border-left:.25rem solid var(--line-gray-color);margin-left:0;padding-left:.5rem}.toot-text .custom-emoji{height:1.5rem;min-width:1.5rem;margin-bottom:-.25rem;width:auto}.toot-poll{margin-bottom:.25rem;color:var(--content-text)}.toot-poll ul{list-style:none;padding:0;margin:0}.toot-poll ul li{font-size:.9rem;margin-bottom:.5rem}.toot-poll ul li:not(:last-child){margin-bottom:.25rem}.toot-poll ul li:before{content:"◯";padding-right:.5rem}.toot-media{overflow:hidden;margin-bottom:.5rem}.toot-media-preview{position:relative;margin-top:.25rem;height:auto;text-align:center;width:100%}.toot-media>.spoiler-link{position:absolute;top:50%;left:50%;z-index:1;transform:translate(-50%,-50%)}.toot-media-spoiler>img{filter:blur(2rem)}.toot-media-preview a{display:block;position:absolute;top:0;right:0;bottom:0;left:0}.img-ratio14_7{position:relative;padding-top:56.95%;width:100%}.img-ratio14_7>img{width:100%;height:auto;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center}.toot-preview-link{min-height:4rem;display:flex;flex-direction:row;border:1px solid var(--line-gray-color);border-radius:.5rem;color:var(--link-color);font-size:.8rem;margin:1rem 0 .5rem 0;overflow:hidden}.toot-preview-image{width:40%;align-self:stretch}.toot-preview-image img{display:block;width:100%;height:100%;object-fit:cover}.toot-preview-noImage{width:40%;font-size:1.5rem;align-self:center;text-align:center}.toot-preview-content{width:60%;display:flex;align-self:center;flex-direction:column;padding:.5rem 1rem;gap:.5rem}.toot-preview-title{font-weight:600}.spoiler-link{border-radius:2px;background-color:var(--line-gray-color);border:0;color:var(--content-text);font-weight:700;font-size:.7rem;padding:0 .35rem;text-transform:uppercase;line-height:1.25rem;cursor:pointer;vertical-align:top}.toot-date{font-size:.75rem}.mt-error{position:absolute;display:flex;flex-direction:column;height:calc(100% - 3.5rem);width:calc(100% - 4.5rem);justify-content:center;align-items:center;color:var(--error-text-color);padding:.75rem;text-align:center}.mt-error-icon{font-size:2rem}.mt-error-message{padding:1rem 0}.mt-error-message hr{color:var(--line-gray-color)}.mt-body>.loading-spinner{position:absolute;width:3rem;height:3rem;margin:auto;top:calc(50% - 1.5rem);right:calc(50% - 1.5rem)}.loading-spinner{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.0' viewBox='0 0 128 128' %3E%3Cg%3E%3Cpath d='M64 128A64 64 0 0 1 18.34 19.16L21.16 22a60 60 0 1 0 52.8-17.17l.62-3.95A64 64 0 0 1 64 128z' fill='%23404040'/%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 64 64' to='360 64 64' dur='1000ms' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/g%3E%3C/svg%3E");background-repeat:no-repeat;background-position:center center;background-color:transparent;background-size:min(2.5rem,calc(100% - .5rem))}.mt-footer{margin:1rem auto 2rem auto;padding:0 2rem;text-align:center}.visually-hidden{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important} \ No newline at end of file +:root{--text-max-lines:none}:root,html[data-theme=light]{--bg-color:#fff;--bg-hover-color:#d9e1e8;--line-gray-color:#c0cdd9;--content-text:#000;--link-color:#3a3bff;--error-text-color:#8b0000}html[data-theme=dark]{--bg-color:#282c37;--bg-hover-color:#313543;--line-gray-color:#393f4f;--content-text:#fff;--link-color:#8c8dff;--error-text-color:#fe6c6c}.mt-timeline{height:100%;overflow-y:auto;position:relative;background:var(--bg-color);scrollbar-color:var(--bg-hover-color) rgba(0,0,0,.1)}.mt-timeline a,.mt-timeline a:active,.mt-timeline a:link{text-decoration:none;color:var(--link-color)}.mt-timeline a:not(.toot-preview-link):hover{text-decoration:underline}.mt-timeline::-webkit-scrollbar{width:.75rem;height:.75rem}.mt-timeline::-webkit-scrollbar-corner{background:0 0}.mt-timeline::-webkit-scrollbar-thumb{border:0 var(--content-text);border-radius:2rem;background:var(--bg-hover-color)}.mt-timeline::-webkit-scrollbar-track{border:0 var(--content-text);border-radius:0;background:rgba(0,0,0,.1)}.mt-body{padding:1rem 1.5rem;white-space:pre-wrap;word-wrap:break-word}.mt-body .invisible{font-size:0;line-height:0;display:inline-block;width:0;height:0;position:absolute}.mt-toot{margin:.25rem;padding:1rem .5rem 1.5rem 4rem;position:relative;min-height:3.75rem;background-color:transparent;border-bottom:1px solid var(--line-gray-color)}.mt-toot:focus,.mt-toot:hover{cursor:pointer;background-color:var(--bg-hover-color)}.mt-toot p:last-child{margin-bottom:0}.mt-avatar{width:3rem;height:3rem;position:absolute;top:1rem;left:.25rem;border-radius:.25rem;overflow:hidden}.mt-avatar-image img{width:100%;height:auto}.mt-avatar-image .mt-avatar-boosted{width:2.25rem;height:2.25rem;border-radius:.25rem;overflow:hidden}.mt-avatar-image .mt-avatar-account{width:1.5rem;height:1.5rem;top:1.5rem;left:1.5rem;position:absolute;border-radius:.25rem;overflow:hidden}.mt-toot-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem}.mt-user{font-weight:600;padding-right:1rem}.mt-user>a{color:var(--content-text)!important}.toot-date{font-size:.75rem;text-align:right}.toot-text{margin-bottom:1rem;color:var(--content-text)}.toot-text .spoiler-link{display:inline-block}.toot-text .spoiler-text-hidden{display:none}.toot-text.truncate{display:-webkit-box;overflow:hidden;-webkit-line-clamp:var(--text-max-lines);-webkit-box-orient:vertical}.toot-text:not(.truncate) .ellipsis::after{content:"..."}.toot-text blockquote{border-left:.25rem solid var(--line-gray-color);margin-left:0;padding-left:.5rem}.toot-text .custom-emoji{height:1.5rem;min-width:1.5rem;margin-bottom:-.25rem;width:auto}.toot-poll{margin-bottom:.25rem;color:var(--content-text)}.toot-poll ul{list-style:none;padding:0;margin:0}.toot-poll ul li{font-size:.9rem;margin-bottom:.5rem}.toot-poll ul li:not(:last-child){margin-bottom:.25rem}.toot-poll ul li:before{content:"◯";padding-right:.5rem}.toot-media{overflow:hidden;margin-bottom:1rem}.toot-media-preview{position:relative;margin-top:.25rem;height:auto;text-align:center;width:100%}.toot-media>.spoiler-link{position:absolute;top:50%;left:50%;z-index:1;transform:translate(-50%,-50%)}.toot-media-spoiler>img{filter:blur(2rem)}.toot-media-preview a{display:block;position:absolute;top:0;right:0;bottom:0;left:0}.img-ratio14_7{position:relative;padding-top:56.95%;width:100%}.img-ratio14_7>img{width:100%;height:auto;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center}.toot-preview-link{min-height:4rem;display:flex;flex-direction:row;border:1px solid var(--line-gray-color);border-radius:.5rem;color:var(--link-color);font-size:.8rem;margin:1rem 0;overflow:hidden}.toot-preview-image{width:40%;align-self:stretch}.toot-preview-image img{display:block;width:100%;height:100%;object-fit:cover}.toot-preview-noImage{width:40%;font-size:1.5rem;align-self:center;text-align:center}.toot-preview-content{width:60%;display:flex;align-self:center;flex-direction:column;padding:.5rem 1rem;gap:.5rem}.toot-preview-title{font-weight:600}.spoiler-link{border-radius:2px;background-color:var(--line-gray-color);border:0;color:var(--content-text);font-weight:700;font-size:.7rem;padding:0 .35rem;text-transform:uppercase;line-height:1.25rem;cursor:pointer;vertical-align:top}.mt-counter-bar{display:flex;gap:clamp(.25rem,1vw,1.5rem);color:var(--link-color)}.mt-counter-favorites,.mt-counter-reblog,.mt-counter-replies{display:flex;font-size:.75rem;gap:.25rem;align-items:center;opacity:.5}.mt-counter-favorites>svg,.mt-counter-reblog>svg,.mt-counter-replies>svg{width:1rem;fill:var(--link-color)}.mt-error{position:absolute;display:flex;flex-direction:column;height:calc(100% - 3.5rem);width:calc(100% - 4.5rem);justify-content:center;align-items:center;color:var(--error-text-color);padding:.75rem;text-align:center}.mt-error-icon{font-size:2rem}.mt-error-message{padding:1rem 0}.mt-error-message hr{color:var(--line-gray-color)}.mt-body>.loading-spinner{position:absolute;width:3rem;height:3rem;margin:auto;top:calc(50% - 1.5rem);right:calc(50% - 1.5rem)}.loading-spinner{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.0' viewBox='0 0 128 128' %3E%3Cg%3E%3Cpath d='M64 128A64 64 0 0 1 18.34 19.16L21.16 22a60 60 0 1 0 52.8-17.17l.62-3.95A64 64 0 0 1 64 128z' fill='%23404040'/%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 64 64' to='360 64 64' dur='1000ms' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/g%3E%3C/svg%3E");background-repeat:no-repeat;background-position:center center;background-color:transparent;background-size:min(2.5rem,calc(100% - .5rem))}.mt-footer{margin:1rem auto 2rem auto;padding:0 2rem;text-align:center}.visually-hidden{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important} \ No newline at end of file diff --git a/src/mastodon-timeline.min.js b/src/mastodon-timeline.min.js index 1b642a5..482b950 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://mastodon.online",timeline_type:"local",user_id:"",profile_name:"",hashtag_name:"",toots_limit:"20",hide_unlisted:!1,hide_reblog:!1,hide_replies:!1,hide_preview_link:!1,hide_emojos:!1,markdown_blockquote:!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_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.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 but due to the "hide filters" applied, no toot is shown
';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 i='";this.mtBodyContainer.parentNode.insertAdjacentHTML("beforeend",i)}this.manageSpinner()}this.mtBodyContainer.addEventListener("click",function(t){("article"==t.target.localName||"article"==t.target.offsetParent.localName||"img"==t.target.localName&&"mt-avatar"!==t.target.offsetParent.className&&"mt-avatar-account"!==t.target.offsetParent.className)&&o(t),"button"==t.target.localName&&"spoiler-link"==t.target.className&&a(t)}),this.mtBodyContainer.addEventListener("keydown",function(t){"Enter"===t.key&&"article"==t.target.localName&&o(t)});let o=function(t){let e=t.target.closest(".mt-toot").dataset.location;"a"!==t.target.localName&&"span"!==t.target.localName&&"button"!==t.target.localName&&"toot-preview-image"!==t.target.parentNode.className&&e&&window.open(e,"_blank")},a=function(t){let e=t.target.nextSibling;"img"===e.localName?(t.target.parentNode.classList.remove("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"))}},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 i(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 i=await e.json();return i}let o={};"profile"===this.TIMELINE_TYPE?o.timeline=`${this.INSTANCE_URL}/api/v1/accounts/${this.USER_ID}/statuses?limit=${this.TOOTS_LIMIT}`:"hashtag"===this.TIMELINE_TYPE?o.timeline=`${this.INSTANCE_URL}/api/v1/timelines/tag/${this.HASHTAG_NAME}?limit=${this.TOOTS_LIMIT}`:"local"===this.TIMELINE_TYPE&&(o.timeline=`${this.INSTANCE_URL}/api/v1/timelines/public?local=true&limit=${this.TOOTS_LIMIT}`),this.HIDE_EMOJOS||(o.emojos=this.INSTANCE_URL+"/api/v1/custom_emojis");let a=Object.entries(o).map(([t,o])=>i(o).then(e=>({[t]:e})).catch(i=>(e(Error("Something went wrong fetching data")),this.mtBodyContainer.innerHTML='

Sorry, request failed:
'+i.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 i,o,a,s,n;t.reblog?(s=t.reblog.url,i='
'+t.reblog.account.username+' avatar
',o='
'+(t.reblog.account.display_name?t.reblog.account.display_name:t.reblog.account.username)+' account
',n=this.formatDate(t.reblog.created_at)):(s=t.url,i='
'+t.account.username+' avatar
',o='
'+(t.account.display_name?t.account.display_name:t.account.username)+' account
',n=this.formatDate(t.created_at));let r="";"0"!==this.TEXT_MAX_LINES&&(r="truncate",document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES)),a=""!==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 l="";if(t.media_attachments.length>0)for(let d in t.media_attachments)l=this.placeMedias(t.media_attachments[d],t.sensitive);if(t.reblog&&t.reblog.media_attachments.length>0)for(let c in t.reblog.media_attachments)l=this.placeMedias(t.reblog.media_attachments[c],t.reblog.sensitive);let h="";!this.HIDE_PREVIEW_LINK&&t.card&&(h=this.placePreviewLink(t.card));let m="",p="";if(t.poll){for(let u in t.poll.options)p+="
  • "+t.poll.options[u].title+"
  • ";m='
    "}let E='
    '+n+"
    ",g='
    '+i+o+a+l+h+m+E+"
    ";return g},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 i of e){let o=RegExp(`\\:${i.shortcode}\\:`,"g");t=t.replace(o,`Emoji ${i.shortcode}`)}return t},MastodonApi.prototype.replaceHTMLtag=function(t,e,i,o,a){if(!t.includes(e))return t;{let s=RegExp(e+"(.*?)"+i,"gi");return t.replace(s,o+"$1"+a)}},MastodonApi.prototype.placeMedias=function(t,e){let i=e||!1,o='
    '+(i?'':"")+''+(t.description?t.description:
    ';return o},MastodonApi.prototype.placePreviewLink=function(t){return''+(t.image?'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+t.provider_name+"":"")+''+t.title+""+(t.author_name?'By '+t.author_name+"":"")+"
    "},MastodonApi.prototype.formatDate=function(t){let e=new Date(t),i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][e.getMonth()]+" "+e.getDate()+", "+e.getFullYear();return i},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)})}; \ No newline at end of file +window.addEventListener("load",()=>{new MastodonApi({container_body_id:"mt-body",spinner_class:"loading-spinner",default_theme:"auto",instance_url:"https://mastodon.online",timeline_type:"local",user_id:"",profile_name:"",hashtag_name:"",toots_limit:"20",hide_unlisted:!1,hide_reblog:!1,hide_replies:!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_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 but due to the "hide filters" applied, no toot is shown
    ';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 i='";this.mtBodyContainer.parentNode.insertAdjacentHTML("beforeend",i)}this.manageSpinner()}this.mtBodyContainer.addEventListener("click",function(t){("article"==t.target.localName||t.target.offsetParent?.localName=="article"||"img"==t.target.localName&&"mt-avatar"!==t.target.offsetParent.className&&"mt-avatar-account"!==t.target.offsetParent.className)&&o(t),"button"==t.target.localName&&"spoiler-link"==t.target.className&&a(t)}),this.mtBodyContainer.addEventListener("keydown",function(t){"Enter"===t.key&&"article"==t.target.localName&&o(t)});let o=function(t){let e=t.target.closest(".mt-toot").dataset.location;"a"!==t.target.localName&&"span"!==t.target.localName&&"button"!==t.target.localName&&"toot-preview-image"!==t.target.parentNode.className&&e&&window.open(e,"_blank")},a=function(t){let e=t.target.nextSibling;"img"===e.localName?(t.target.parentNode.classList.remove("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"))}},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 i(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 i=await e.json();return i}let o={};"profile"===this.TIMELINE_TYPE?o.timeline=`${this.INSTANCE_URL}/api/v1/accounts/${this.USER_ID}/statuses?limit=${this.TOOTS_LIMIT}`:"hashtag"===this.TIMELINE_TYPE?o.timeline=`${this.INSTANCE_URL}/api/v1/timelines/tag/${this.HASHTAG_NAME}?limit=${this.TOOTS_LIMIT}`:"local"===this.TIMELINE_TYPE&&(o.timeline=`${this.INSTANCE_URL}/api/v1/timelines/public?local=true&limit=${this.TOOTS_LIMIT}`),this.HIDE_EMOJOS||(o.emojos=this.INSTANCE_URL+"/api/v1/custom_emojis");let a=Object.entries(o).map(([t,o])=>i(o).then(e=>({[t]:e})).catch(i=>(e(Error("Something went wrong fetching data")),this.mtBodyContainer.innerHTML='

    Sorry, request failed:
    '+i.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 i,o,a,s;t.reblog?(a=t.reblog.url,i='
    '+t.reblog.account.username+' avatar
    ',o='
    '+(t.reblog.account.display_name?t.reblog.account.display_name:t.reblog.account.username)+' account
    ',s=this.formatDate(t.reblog.created_at)):(a=t.url,i='
    '+t.account.username+' avatar
    ',o='
    '+(t.account.display_name?t.account.display_name:t.account.username)+' account
    ',s=this.formatDate(t.created_at));let r='
    '+s+"
    ",n="";"0"!==this.TEXT_MAX_LINES&&(n="truncate",document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES));let l="";l=""!==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 d="";if(t.media_attachments.length>0)for(let c in t.media_attachments)d=this.placeMedias(t.media_attachments[c],t.sensitive);if(t.reblog&&t.reblog.media_attachments.length>0)for(let h in t.reblog.media_attachments)d=this.placeMedias(t.reblog.media_attachments[h],t.reblog.sensitive);let m="";!this.HIDE_PREVIEW_LINK&&t.card&&(m=this.placePreviewLink(t.card));let p="",u="";if(t.poll){for(let v in t.poll.options)u+="
  • "+t.poll.options[v].title+"
  • ";p='
    "}let g="";if(!this.HIDE_COUNTER_BAR){let _='
    '+t.replies_count+"
    ",E;g='
    '+_+('
    '+t.reblogs_count+"
    ")+('
    '+t.favourites_count)+"
    "}return'
    '+i+'
    '+o+r+"
    "+l+d+m+p+g+"
    "},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 i of e){let o=RegExp(`\\:${i.shortcode}\\:`,"g");t=t.replace(o,`Emoji ${i.shortcode}`)}return t},MastodonApi.prototype.replaceHTMLtag=function(t,e,i,o,a){if(!t.includes(e))return t;{let s=RegExp(e+"(.*?)"+i,"gi");return t.replace(s,o+"$1"+a)}},MastodonApi.prototype.placeMedias=function(t,e){let i=e||!1,o='
    '+(i?'':"")+''+(t.description?t.description:
    ';return o},MastodonApi.prototype.placePreviewLink=function(t){return''+(t.image?'
    ':'
    \uD83D\uDCC4
    ')+'
    '+(t.provider_name?''+t.provider_name+"":"")+''+t.title+""+(t.author_name?'By '+t.author_name+"":"")+"
    "},MastodonApi.prototype.formatDate=function(t){let e=new Date(t),i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",][e.getMonth()]+" "+e.getDate()+", "+e.getFullYear();return i},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)})}; \ No newline at end of file