1window.addEventListener("load",()=>{const mastodonTimeline=new MastodonApi({container_body_id:"mt-body",spinner_class:"loading-spinner",default_theme:"light",instance_url:"https://mstdn.social",timeline_type:"profile",user_id:"109473824982047998",profile_name:"@swissvotes",hashtag_name:"",toots_limit:"2",hide_unlisted:true,hide_reblog:true,hide_replies:true,hide_video_preview:false,hide_preview_link:true,hide_emojos:false,markdown_blockquote:false,hide_counter_bar:true,text_max_lines:"0",link_see_more:"https://mstdn.social/@swissvotes",});});const MastodonApi=function(params_){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;this.USER_ID=params_.user_id||"";this.PROFILE_NAME=this.USER_ID?params_.profile_name:"";this.TIMELINE_TYPE=params_.timeline_type||"local";this.HASHTAG_NAME=params_.hashtag_name||"";this.TOOTS_LIMIT=params_.toots_limit||"20";this.HIDE_UNLISTED=typeof params_.hide_unlisted!=="undefined"?params_.hide_unlisted:false;this.HIDE_REBLOG=typeof params_.hide_reblog!=="undefined"?params_.hide_reblog:false;this.HIDE_REPLIES=typeof params_.hide_replies!=="undefined"?params_.hide_replies:false;this.HIDE_VIDEO_PREVIEW=typeof params_.hide_video_preview!=="undefined"?params_.hide_video_preview:false;this.HIDE_PREVIEW_LINK=typeof params_.hide_preview_link!=="undefined"?params_.hide_preview_link:false;this.HIDE_EMOJOS=typeof params_.hide_emojos!=="undefined"?params_.hide_emojos:false;this.MARKDOWN_BLOCKQUOTE=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.buildTimeline();};MastodonApi.prototype.buildTimeline=async function(){this.setTheme();await this.getTimelineData();this.CONTAINER_BODY_ID.innerHTML="";for(let i in this.FETCHED_DATA.timeline){if(this.FETCHED_DATA.timeline[i].visibility=="public"||(!this.HIDE_UNLISTED&&this.FETCHED_DATA.timeline[i].visibility=="unlisted")){if((this.HIDE_REBLOG&&this.FETCHED_DATA.timeline[i].reblog)||(this.HIDE_REPLIES&&this.FETCHED_DATA.timeline[i].in_reply_to_id)){}else{this.appendToot(this.FETCHED_DATA.timeline[i],Number(i));}}} 2if(this.CONTAINER_BODY_ID.innerHTML===""){this.CONTAINER_BODY_ID.setAttribute("role","none");this.CONTAINER_BODY_ID.innerHTML='<div class="mt-error"><span class="mt-error-icon">ð</span><br/><strong>Sorry, no toots to show</strong><br/><div class="mt-error-message">Got '+ 3this.FETCHED_DATA.timeline.length+" toots from the server. <br/>This may be due to an incorrect configuration in the parameters or to filters applied to hide certains type of toots.</div></div>";}else{if(this.LINK_SEE_MORE){let linkSeeMorePath="";if(this.TIMELINE_TYPE==="profile"){linkSeeMorePath=this.PROFILE_NAME;}else if(this.TIMELINE_TYPE==="hashtag"){linkSeeMorePath="tags/"+this.HASHTAG_NAME;}else if(this.TIMELINE_TYPE==="local"){linkSeeMorePath="public/local";} 4const linkSeeMore='<div class="mt-footer"><a href="'+ 5this.INSTANCE_URL+"/"+ 6this.escapeHtml(linkSeeMorePath)+'" target="_blank" rel="nofollow noopener noreferrer">'+ 7this.LINK_SEE_MORE+"</a></div>";this.CONTAINER_BODY_ID.parentNode.insertAdjacentHTML("beforeend",linkSeeMore);} 8this.manageSpinner();} 9this.CONTAINER_BODY_ID.addEventListener("click",function(e){if(e.target.localName=="article"||e.target.offsetParent?.localName=="article"||(e.target.localName=="img"&&!e.target.parentNode.classList.contains("video-ratio14_7"))){openTootURL(e);} 10if(e.target.localName=="button"&&e.target.className=="spoiler-btn"){toogleSpoiler(e);} 11if(e.target.className=="mt-toot-media-play-icon"||(e.target.localName=="svg"&&e.target.parentNode.className=="mt-toot-media-play-icon")||(e.target.localName=="path"&&e.target.parentNode.parentNode.className=="mt-toot-media-play-icon")||(e.target.localName=="img"&&e.target.parentNode.classList.contains("video-ratio14_7"))){loadTootVideo(e);}});this.CONTAINER_BODY_ID.addEventListener("keydown",function(e){if(e.key==="Enter"&&e.target.localName=="article"){openTootURL(e);}});const openTootURL=function(e){const urlToot=e.target.closest(".mt-toot").dataset.location;if(e.target.localName!=="a"&&e.target.localName!=="span"&&e.target.localName!=="button"&&e.target.localName!=="time"&&e.target.className!=="mt-toot-preview-noImage"&&e.target.parentNode.className!=="mt-toot-avatar-image-big"&&e.target.parentNode.className!=="mt-toot-avatar-image-small"&&e.target.parentNode.className!=="mt-toot-preview-image"&&e.target.parentNode.className!=="mt-toot-preview"&&urlToot){window.open(urlToot,"_blank","noopener");}};const toogleSpoiler=function(e){const nextSibling=e.target.nextSibling;if(nextSibling.localName==="img"||nextSibling.localName==="audio"||nextSibling.localName==="video"){e.target.parentNode.classList.remove("mt-toot-media-spoiler");e.target.style.display="none";}else if(nextSibling.classList.contains("spoiler-text-hidden")||nextSibling.classList.contains("spoiler-text-visible")){if(e.target.textContent=="Show more"){nextSibling.classList.remove("spoiler-text-hidden");nextSibling.classList.add("spoiler-text-visible");e.target.setAttribute("aria-expanded","true");e.target.textContent="Show less";}else{nextSibling.classList.remove("spoiler-text-visible");nextSibling.classList.add("spoiler-text-hidden");
11e.target.setAttribute("aria-expanded","false");e.target.textContent="Show more";}}};const loadTootVideo=function(e){const parentNode=e.target.closest("[data-video-url]");const videoURL=parentNode.dataset.videoUrl;parentNode.replaceChildren();parentNode.innerHTML='<video controls src="'+videoURL+'" autoplay></video>';};};MastodonApi.prototype.setTheme=function(){const setTheme=function(theme){document.documentElement.setAttribute("data-theme",theme);};if(this.DEFAULT_THEME==="auto"){let systemTheme=window.matchMedia("(prefers-color-scheme: dark)");systemTheme.matches?setTheme("dark"):setTheme("light");systemTheme.addEventListener("change",(e)=>{e.matches?setTheme("dark"):setTheme("light");});}else{setTheme(this.DEFAULT_THEME);}};MastodonApi.prototype.getTimelineData=async function(){return new Promise((resolve,reject)=>{async function fetchData(url){const response=await fetch(url);if(!response.ok){throw new Error("Failed to fetch the following URL: "+ 12url+"<hr>"+"Error status: "+ 13response.status+"<hr>"+"Error message: "+ 14response.statusText);} 15const data=await response.json();return data;} 16let urls={};if(this.TIMELINE_TYPE==="profile"){urls.timeline=`${this.INSTANCE_URL}/api/v1/accounts/${this.USER_ID}/statuses?limit=${this.TOOTS_LIMIT}`;}else if(this.TIMELINE_TYPE==="hashtag"){urls.timeline=`${this.INSTANCE_URL}/api/v1/timelines/tag/${this.HASHTAG_NAME}?limit=${this.TOOTS_LIMIT}`;}else if(this.TIMELINE_TYPE==="local"){urls.timeline=`${this.INSTANCE_URL}/api/v1/timelines/public?local=true&limit=${this.TOOTS_LIMIT}`;} 17if(!this.HIDE_EMOJOS){urls.emojos=this.INSTANCE_URL+"/api/v1/custom_emojis";} 18const urlsPromises=Object.entries(urls).map(([key,url])=>{return fetchData(url).then((data)=>({[key]:data})).catch((error)=>{reject(new Error("Something went wrong fetching data"));this.CONTAINER_BODY_ID.innerHTML='<div class="mt-error"><span class="mt-error-icon">â</span><br/><strong>Sorry, request failed:</strong><br/><div class="mt-error-message">'+ 19error.message+"</div></div>";this.CONTAINER_BODY_ID.setAttribute("role","none");return{[key]:[]};});});Promise.all(urlsPromises).then((dataObjects)=>{this.FETCHED_DATA=dataObjects.reduce((result,dataItem)=>{return{...result,...dataItem};},{});resolve();});});};MastodonApi.prototype.appendToot=function(c,i){this.CONTAINER_BODY_ID.insertAdjacentHTML("beforeend",this.assambleToot(c,i));};MastodonApi.prototype.assambleToot=function(c,i){let avatar,user,userName,url,date,formattedDate,favoritesCount,reblogCount,repliesCount;if(c.reblog){url=c.reblog.url;avatar='<a href="'+ 20c.reblog.account.url+'" class="mt-toot-avatar" rel="nofollow noopener noreferrer" target="_blank">'+'<div class="mt-toot-avatar-boosted">'+'<div class="mt-toot-avatar-image-big loading-spinner">'+'<img src="'+ 21c.reblog.account.avatar+'" alt="'+ 22this.escapeHtml(c.reblog.account.username)+' avatar" loading="lazy" />'+"</div>"+'<div class="mt-toot-avatar-image-small">'+'<img src="'+ 23c.account.avatar+'" alt="'+ 24this.escapeHtml(c.account.username)+' avatar" loading="lazy" />'+"</div>"+"</div>"+"</a>";userName=this.showEmojos(c.reblog.account.display_name?c.reblog.account.display_name:c.reblog.account.username,this.FETCHED_DATA.emojos);user='<div class="mt-toot-header-user">'+'<a href="'+ 25c.reblog.account.url+'" rel="nofollow noopener noreferrer" target="_blank">'+ 26userName+'<span class="visually-hidden"> account</span>'+"</a>"+"</div>";date=c.reblog.created_at;repliesCount=c.reblog.replies_count;reblogCount=c.reblog.reblogs_count;favoritesCount=c.reblog.favourites_count;}else{url=c.url;avatar='<a href="'+ 27c.account.url+'" class="mt-toot-avatar" rel="nofollow noopener noreferrer" target="_blank">'+'<div class="mt-toot-avatar-standard">'+'<div class="mt-toot-avatar-image-big loading-spinner">'+'<img src="'+ 28c.account.avatar+'" alt="'+ 29this.escapeHtml(c.account.username)+' avatar" loading="lazy" />'+"</div>"+"</div>"+"</a>";userName=this.showEmojos(c.account.display_name?c.account.display_name:c.account.username,this.FETCHED_DATA.emojos);user='<div class="mt-toot-header-user">'+'<a href="'+ 30c.account.url+'" rel="nofollow noopener noreferrer" target="_blank">'+ 31userName+'<span class="visually-hidden"> account</span>'+"</a>"+"</div>";date=c.created_at;repliesCount=c.replies_count;reblogCount=c.reblogs_count;favoritesCount=c.favourites_count;} 32formattedDate=this.formatDate(date);const timestamp='<div class="mt-toot-header-date">'+'<a href="'+ 33url+'" rel="nofollow noopener noreferrer" target="_blank">'+'<time datetime="'+ 34date+'">'+ 35formattedDate+"</time>"+"</a>"+"</div>";let text_css="";if(this.TEXT_MAX_LINES!=="0"){text_css=" truncate";document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES);} 36let content="";if(c.spoiler_text!==""){content='<div class="mt-toot-text">'+ 37c.spoiler_text+' <button type="button" class="spoiler-btn" aria-expanded="false">Show more</button>'+'<div class="spoiler-text-hidden">'+ 38this.formatTootText(c.content)+"</div>"+"</div>";}else if(c.reblog&&c.reblog.content!==""&&c.reblog.spoiler_text!==""){content='<div class="mt-toot-text">'+ 39c.reblog.spoiler_text+' <button type="button" class="spoiler-btn" aria-expanded="false">Show more</button>'+'<div class="spoiler-text-hidden">'+ 40this.formatTootText(c.reblog.content)+"</div>"+"</div>";}else if(c.reblog&&c.reblog.content!==""&&c.reblog.spoiler_text===""){content='<div class="mt-toot-text'+ 41text_css+'">'+'<div class="mt-toot-text-wrapper">'+ 42this.formatTootText(c.reblog.content)+"</div>"+"</div>";}else{content='<div class="mt-toot-text'+ 43text_css+'">'+'<div class="mt-toot-text-wrapper">'+ 44this.formatTootText(c.content)+"</div>"+"</div>";} 45let media=[];if(c.media_attachments.length>0){for(let i in c.media_attachments){media.push(this.placeMedias(c.media_attachments[i],c.sensitive));}} 46if(c.reblog&&c.reblog.media_attachments.length>0){for(let i in c.reblog.media_attachments){media.push(this.placeMedias(c.reblog.media_attachments[i],c.reblog.sensitive));}} 47let previewLink="";if(!this.HIDE_PREVIEW_LINK&&c.card){previewLink=this.placePreviewLink(c.card);} 48let poll="";if(c.poll){let pollOption="";for(let i in c.poll.options){pollOption+="<li>"+c.poll.options[i].title+"</li>";} 49poll='<div class="mt-toot-poll '+
50(c.poll.expired?"mt-toot-poll-expired":"")+'">'+"<ul>"+ 51pollOption+"</ul>"+"</div>";} 52let counterBar="";if(!this.HIDE_COUNTER_BAR){const repliesTag='<div class="mt-toot-counter-bar-replies">'+'<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960" aria-hidden="true"><path d="M774.913-185.869V-356q0-56.609-35.891-92.5-35.892-35.891-92.5-35.891H258.045L411.435-331l-56 56.566L105.869-524l249.566-249.566 56 56.566-153.39 153.391h388.477q88.957 0 148.566 59.609 59.608 59.609 59.608 148v170.131h-79.783Z"></path></svg>'+ 53repliesCount+"</div>";const reblogTag='<div class="mt-toot-counter-bar-reblog">'+'<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960" aria-hidden="true"><path d="M276.043-65.304 105.869-236.043l170.174-170.175 52.74 54.175-78.652 78.652h449.304v-160h75.261v235.261H250.131l78.652 78.087-52.74 54.74Zm-90.174-457.348v-235.261h524.565L631.782-836l52.74-54.74L854.696-720 684.522-549.26 631.782-604l78.652-78.652H261.13v160h-75.261Z"></path></svg>'+ 54reblogCount+"</div>";const favoritesTag='<div class="mt-toot-counter-bar-favorites">'+'<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960" aria-hidden="true"><path d="m330.955-216.328 149.066-89 149.066 90.023-40.305-168.391 131.217-114.347-172.956-14.87L480-671.869l-67.043 158.521-172.956 14.305 131.427 113.796-40.473 168.919ZM212.086-50.608l70.652-305.305L45.52-561.305l312.645-26.579L480-876.176l121.835 288.292 312.645 26.579-237.218 205.392 71.217 305.306L480-213.173 212.086-50.607ZM480-433.87Z"></path></svg>'+ 55favoritesCount+"</div>";counterBar='<div class="mt-toot-counter-bar">'+ 56repliesTag+ 57reblogTag+ 58favoritesTag+"</div>";} 59const toot='<article class="mt-toot" aria-posinset="'+ 60(i+1)+'" aria-setsize="'+ 61this.TOOTS_LIMIT+'" data-location="'+ 62url+'" tabindex="0">'+'<div class="mt-toot-header">'+ 63avatar+ 64user+ 65timestamp+"</div>"+ 66content+ 67media.join("")+ 68previewLink+ 69poll+ 70counterBar+"</article>";return toot;};MastodonApi.prototype.formatTootText=function(c){let content=c;content=this.addTarget2hashtagMention(content);if(!this.HIDE_EMOJOS){content=this.showEmojos(content,this.FETCHED_DATA.emojos);} 71if(this.MARKDOWN_BLOCKQUOTE){content=this.replaceHTMLtag(content,"<p>>","</p>","<blockquote><p>","</p></blockquote>");} 72return content;};MastodonApi.prototype.addTarget2hashtagMention=function(c){let content=c.replaceAll('rel="tag"','rel="tag" target="_blank"');content=content.replaceAll('class="u-url mention"','class="u-url mention" target="_blank"');return content;};MastodonApi.prototype.showEmojos=function(c,e){if(c.includes(":")){for(const emojo of e){const regex=new RegExp(`\\:${emojo.shortcode}\\:`,"g");c=c.replace(regex,`<img src="${emojo.url}" class="custom-emoji" alt="Emoji ${emojo.shortcode}" />`);} 73return c;}else{return c;}};MastodonApi.prototype.replaceHTMLtag=function(c,initialTagOpen,initialTagClose,replacedTagOpen,replacedTagClose){if(c.includes(initialTagOpen)){const regex=new RegExp(initialTagOpen+"(.*?)"+initialTagClose,"gi");return c.replace(regex,replacedTagOpen+"$1"+replacedTagClose);}else{return c;}};MastodonApi.prototype.placeMedias=function(m,s){const spoiler=s||false;const type=m.type;let media="";if(type==="image"){media='<div class="mt-toot-media img-ratio14_7 '+ 74(spoiler?"mt-toot-media-spoiler ":"")+ 75this.SPINNER_CLASS+'">'+ 76(spoiler?'<button class="spoiler-btn">Show content</button>':"")+'<img src="'+ 77m.preview_url+'" alt="'+ 78(m.description?this.escapeHtml(m.description):"")+'" loading="lazy" />'+"</div>";} 79if(type==="audio"){if(m.preview_url){media='<div class="mt-toot-media img-ratio14_7 '+ 80(spoiler?"mt-toot-media-spoiler ":"")+ 81this.SPINNER_CLASS+'">'+ 82(spoiler?'<button class="spoiler-btn">Show content</button>':"")+'<audio controls src="'+ 83m.url+'"></audio>'+'<img src="'+ 84m.preview_url+'" alt="'+ 85(m.description?this.escapeHtml(m.description):"")+'" loading="lazy" />'+"</div>";}else{media='<div class="mt-toot-media '+ 86(spoiler?"mt-toot-media-spoiler ":"")+'">'+ 87(spoiler?'<button class="spoiler-btn">Show content</button>':"")+'<audio controls src="'+ 88m.url+'"></audio>'+"</div>";}} 89if(type==="video"){if(!this.HIDE_VIDEO_PREVIEW){media='<div class="mt-toot-media video-ratio14_7 '+ 90(spoiler?"mt-toot-media-spoiler ":"")+ 91this.SPINNER_CLASS+'" data-video-url="'+ 92m.url+'">'+ 93(spoiler?'<button class="spoiler-btn">Show content</button>':"")+'<img src="'+ 94m.preview_url+'" alt="'+ 95(m.description?this.escapeHtml(m.description):"")+'" loading="lazy" />'+'<button class="mt-toot-media-play-icon" title="Load video"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 14">
95<path d="M9.5 7l-9 6.3V.7z"/></svg></button>'+"</div>";}else{media='<div class="mt-toot-media video-ratio14_7 '+ 96(spoiler?"mt-toot-media-spoiler ":"")+'">'+ 97(spoiler?'<button class="spoiler-btn">Show content</button>':"")+'<video controls src="'+ 98m.url+'"></video>'+"</div>";}} 99return media;};MastodonApi.prototype.placePreviewLink=function(c){const card='<a href="'+ 100c.url+'" class="mt-toot-preview" target="_blank" rel="noopener noreferrer">'+ 101(c.image?'<div class="mt-toot-preview-image '+ 102this.SPINNER_CLASS+'"><img src="'+ 103c.image+'" alt="'+ 104this.escapeHtml(c.image_description)+'" loading="lazy" /></div>':'<div class="mt-toot-preview-noImage">ð</div>')+"</div>"+'<div class="mt-toot-preview-content">'+ 105(c.provider_name?'<span class="mt-toot-preview-provider">'+ 106this.parseHTMLstring(c.provider_name)+"</span>":"")+'<span class="mt-toot-preview-title">'+ 107c.title+"</span>"+ 108(c.author_name?'<span class="mt-toot-preview-author">'+ 109this.parseHTMLstring(c.author_name)+"</span>":"")+"</div>"+"</a>";return card;};MastodonApi.prototype.formatDate=function(d){const monthNames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",];const date=new Date(d);const displayDate=monthNames[date.getMonth()]+" "+ 110date.getDate()+", "+ 111date.getFullYear();return displayDate;};MastodonApi.prototype.parseHTMLstring=function(s){const parser=new DOMParser();const txt=parser.parseFromString(s,"text/html");return txt.body.textContent;};MastodonApi.prototype.escapeHtml=function(s){return(s??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'");};MastodonApi.prototype.manageSpinner=function(){const spinnerCSS=this.SPINNER_CLASS;const removeSpinner=function(){this.parentNode.classList.remove(spinnerCSS);this.removeEventListener("load",removeSpinner);this.removeEventListener("error",removeSpinner);};this.CONTAINER_BODY_ID.querySelectorAll(`.${this.SPINNER_CLASS} > img`).forEach((e)=>{e.addEventListener("load",removeSpinner);e.addEventListener("error",removeSpinner);});};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.