diff --git a/src/mastodon-timeline.css b/src/mastodon-timeline.css index d37f147..cd45beb 100644 --- a/src/mastodon-timeline.css +++ b/src/mastodon-timeline.css @@ -51,7 +51,6 @@ html[data-theme="dark"] { background: transparent; } .mt-timeline::-webkit-scrollbar-thumb { - border-radius: 0; border: 0 var(--content-text); border-radius: 2rem; background: var(--bg-hover-color); diff --git a/src/mastodon-timeline.js b/src/mastodon-timeline.js index 7c0d1d2..36c7567 100644 --- a/src/mastodon-timeline.js +++ b/src/mastodon-timeline.js @@ -87,7 +87,9 @@ MastodonApi.prototype.getToots = function () { requestURL = this.INSTANCE_URI + '/api/v1/timelines/public?limit=' + this.TOOTS_LIMIT; } - fetch(requestURL, { method: 'get' }) + fetch(requestURL, { + method: 'get' + }) .then( response => { if (response.ok) { @@ -267,7 +269,7 @@ MastodonApi.prototype.getToots = function () { // Add all to main toot container let toot = - '
' + '
' + avatar + user + content diff --git a/src/mastodon-timeline.min.css b/src/mastodon-timeline.min.css new file mode 100644 index 0000000..d3a88d8 --- /dev/null +++ b/src/mastodon-timeline.min.css @@ -0,0 +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,0.1)}.mt-timeline a:link,.mt-timeline a:active,.mt-timeline a{text-decoration:none;color:var(--link-color)}.mt-timeline a:hover{text-decoration:underline}.mt-timeline::-webkit-scrollbar{width:.75rem;height:.75rem}.mt-timeline::-webkit-scrollbar-corner{background:transparent}.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,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 2rem 4rem;position:relative;min-height:3.75rem;background-color:transparent;border-bottom:1px solid var(--line-gray-color)}.mt-toot:hover,.mt-toot:focus{cursor:pointer;background-color:var(--bg-hover-color)}.mt-toot p:last-child{margin-bottom:0}.mt-avatar{position:absolute;top:1rem;left:5px;width:3rem;height:3rem;background-color:transparent;background-repeat:no-repeat;background-position:50% 50%;background-size:contain;background-color:var(--bg-color);border-radius:5px}.mt-avatar-boosted{width:2.5rem;height:2.5rem}.mt-avatar-booster{width:1.5rem;height:1.5rem;top:1.5rem;left:1.5rem}.mt-user{display:table;font-weight:600}.mt-user>a{color:var(--content-text) !important}.toot-text{margin-bottom:.25rem;color:var(--content-text)}.toot-text .spoiler-link{display:inline-block;border-radius:2px;background-color:var(--bg-hover-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-text .spoiler-text{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:"..."}.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}.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:.25rem}.toot-media-preview{position:relative;margin-top:.25rem;height:auto;text-align:center;width:100%}.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:48.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-date{font-size:.75rem;opacity:.5}.mt-body>.loading-spinner{position:absolute;width:3rem;height:3rem;margin:auto;top:calc(50% - 1.5rem);right:calc(50% - 1.5rem)}.loading-spinner{height:100%;background-image:url("data:image/svg+xml;charset=utf8,%3Csvgxmlns: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='00128128'%3E%3Cg%3E%3Cpathd='M64128A646400118.3419.16L21.1622a606001052.8-17.17l.62-3.95A646400164128z'fill='%23404040'/%3E%3CanimateTransformattributeName='transform'type='rotate'from='06464'to='3606464'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 new file mode 100644 index 0000000..893999c --- /dev/null +++ b/src/mastodon-timeline.min.js @@ -0,0 +1 @@ +document.addEventListener("DOMContentLoaded",()=>{new MastodonApi({container_body_id:"mt-body",default_theme:"auto",instance_uri:"https://mastodon.online",user_id:"000180745",profile_name:"@idotj",toots_limit:"20",hide_reblog:!1,hide_replies:!1,text_max_lines:"0",link_see_more:"See more posts at Mastodon"})});let MastodonApi=function(t){this.DEFAULT_THEME=t.default_theme||"auto",this.INSTANCE_URI=t.instance_uri,this.USER_ID=t.user_id||"",this.PROFILE_NAME=this.USER_ID?t.profile_name:"",this.TOOTS_LIMIT=t.toots_limit||"20",this.HIDE_REBLOG=void 0!==t.hide_reblog&&t.hide_reblog,this.HIDE_REPLIES=void 0!==t.hide_replies&&t.hide_replies,this.TEXT_MAX_LINES=t.text_max_lines||"0",this.LINK_SEE_MORE=t.link_see_more,this.mtBodyContainer=document.getElementById(t.container_body_id),this.applyTheme(),this.getToots()};MastodonApi.prototype.applyTheme=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.getToots=function(){let t=this,e="";fetch(e=this.USER_ID?this.INSTANCE_URI+"/api/v1/accounts/"+this.USER_ID+"/statuses?limit="+this.TOOTS_LIMIT:this.INSTANCE_URI+"/api/v1/timelines/public?limit="+this.TOOTS_LIMIT,{method:"get"}).then(t=>{if(t.ok)return t.json();if(404===t.status)throw Error("404 Not found",{cause:t});throw Error(t.status)}).then(e=>{for(let o in this.mtBodyContainer.innerHTML="",e)("public"==e[o].visibility||"unlisted"==e[o].visibility)&&(t.HIDE_REBLOG&&e[o].reblog||t.HIDE_REPLIES&&e[o].in_reply_to_id||a.call(t,e[o],o));let r=document.querySelectorAll("#mt-body .hashtag, .u-url.mention");for(let i=0;i'+t.LINK_SEE_MORE+"":'",this.mtBodyContainer.parentNode.insertAdjacentHTML("beforeend",n)}}).catch(t=>{this.mtBodyContainer.innerHTML='
✖️
Request Failed:
'+t+"
",this.mtBodyContainer.setAttribute("role","none")});let a=function(t,e){let a,o,r,i,n;t.reblog?(i=t.reblog.url,a='
'+t.account.username+" avatar
",o='',n=this.formatDate(t.reblog.created_at)):(i=t.url,a=''+t.account.username+" avatar",o='',n=this.formatDate(t.created_at));let l="";"0"!==this.TEXT_MAX_LINES&&(l="truncate",document.documentElement.style.setProperty("--text-max-lines",this.TEXT_MAX_LINES)),r=""!==t.spoiler_text?'
'+t.spoiler_text+'
'+t.content+"
":t.reblog&&""!==t.reblog.content?'
'+t.reblog.content+"
":'
'+t.content+"
";let s="";if(t.media_attachments.length>0)for(let d in t.media_attachments)s=this.replaceMedias(t.media_attachments[d],t.sensitive);if(t.reblog&&t.reblog.media_attachments.length>0)for(let c in t.reblog.media_attachments)s=this.replaceMedias(t.reblog.media_attachments[c],t.sensitive);let m="",u="";if(t.poll){for(let h in t.poll.options)u+="
  • "+t.poll.options[h].title+"
  • ";m='
      '+u+"
    "}let p='",g='
    '+a+o+r+s+m+p+"
    ";this.mtBodyContainer.insertAdjacentHTML("beforeend",g)};this.mtBodyContainer.addEventListener("click",function(t){("article"==t.target.localName||"article"==t.target.offsetParent.localName||"img"==t.target.localName)&&openTootURL(t),"button"==t.target.localName&&"spoiler-link"==t.target.className&&toogleSpoiler(t)}),this.mtBodyContainer.addEventListener("keydown",function(t){"Enter"===t.code&&"article"==t.target.localName&&openTootURL(t)}),openTootURL=function(t){let e=t.target.closest(".mt-toot").dataset.location;"a"!==t.target.localName&&"span"!==t.target.localName&&"button"!==t.target.localName&&e&&window.open(e,"_blank")},toogleSpoiler=function(t){let e=t.target.nextSibling,a=t.target.textContent;e.classList.toggle("spoiler-text"),"Show more"==a?(a="Show less",t.target.setAttribute("aria-expanded","true")):(a="Show more",t.target.setAttribute("aria-expanded","false"))}},MastodonApi.prototype.replaceMedias=function(t,e){return'
    '},MastodonApi.prototype.formatDate=function(t){let e=new Date(t);return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()]+" "+e.getDate()+", "+e.getFullYear()},removeSpinner=function(t){let e="loading-spinner",a=t.closest("."+e);a&&a.classList.remove(e)}; \ No newline at end of file