sloane.sh/js/JekyllWebmentionIO.js

2 lines
34 KiB
JavaScript
Raw Normal View History

2025-01-28 17:53:02 -05:00
!function(t,e){function n(){for(var t,n=e.querySelectorAll("template[id^=webmention-]"),i=n.length;i--;)(t=n[i]).content.querySelector("ol")?f[t.id]=t.content.querySelector("ol"):f[t.id]=t.content;t=null}function i(){for(var t=e.querySelectorAll("[id^=webmention-]"),n=t.length;n--;)JekyllWebmentionIO.existing_webmentions.push(t[n].getAttribute("id").replace("webmention-",""));t=null}function r(){for(var t,n,i,r,s=e.querySelectorAll(".webmentions"),o=s.length;o--;){n="webmentions",(t=s[o]).className.indexOf("webmentions--")>-1&&(n=t.className.match(/webmentions\-\-(.*)/)[1]),t.type=n,f["webmention-"+n]&&(t.template=f["webmention-"+n]),r=(i="dataset"in t&&"webmentionTypes"in t.dataset?t.dataset.webmentionTypes.split(","):[n]).length;for(;r--;)(n=i[r])in d||(d[n]=[]),d[n].push(t)}t=null}function s(t){var e,n,i,r,s=0,a={},l=Object.keys(d),u=function(t){return JekyllWebmentionIO.types[t]===this.type};for(s=l.length;s--;)a[l[s]]=[];for(s=t.length;s--;)n=t[s],r=u.bind(n),i=Object.keys(JekyllWebmentionIO.types).filter(r)[0],l.indexOf(i)>-1&&a[i].push(n),a.webmentions&&a.webmentions.push(n);for(s=l.length;s--;)for(e=d[l[s]].length;e--;)a[l[s]].length>0&&o(a[l[s]],d[l[s]][e])}function o(e,n){if(e.length<1)console.warn("No webmentions to add, check your application code");else if(n.template)if("Liquid"in t){var i,r=n.querySelector(".webmentions__list"),s=n.template,o="append";r?s=Liquid.parse(s.innerHTML):(s=Liquid.parse(s.outerHTML),o="replace"),i=s.render({webmentions:e}),"append"==o?r.innerHTML+=i:n.innerHTML=i}else console.error("Liquid parsing engine is not available");else console.error("No template found for this webmention group",n)}function a(t){for(var e,n,i=t.length;i--;)e=t[i].id,(n=t[i].data.url||t[i].source)&&n.indexOf("twitter.com/")>-1&&n.indexOf("#favorited-by")<0&&(e=n.replace(/^.*?status\/(\d+)$/,"$1")),t[i].id=e+"";return t}function l(t){t.reverse();for(var e=[],n=t.length;n--;)JekyllWebmentionIO.existing_webmentions.indexOf(t[n].id)<0&&(e.push(t[n]),JekyllWebmentionIO.existing_webmentions.push(t[n].id));return e}function u(t){t.reverse();for(var e,n,i,r,s,o,a,l=t.length,u=function(t){t&&c(this.id,this.uri,t)};l--;)r=!1,(i=(e=t[l]).data.url||e.source).indexOf("twitter.com/")?r="twitter":i.indexOf("/googleplus/")>-1&&(r="googleplus"),!(s=e.data.published_ts)&&e.verified_date&&(s=e.verified_date),s&&(s=new Date(s).getTime()),n={id:e.id,url:i,source:r,pubdate:s,raw:t[l]},"author"in e.data&&(n.author=t[l].data.author),(o=t[l].activity.type)||(o="googleplus"==r?i.indexOf("/like/")>-1?"like":i.indexOf("/repost/")>-1?"repost":i.indexOf("/comment/")>-1?"reply":"link":"post"),n.type=o,!1,"post"==o&&h(i,u.bind({id:n.id,uri:i})),a=e.data.content,"bookmark"!=o&&"link"!=o&&"post"!=o&&"reply"!=o&&(a=e.activity.sentence_html),n.content=a,t[l]=n;return t}function c(t,n,i){var r,s,o,a=e.querySelector("#webmention-"+t),l=a.querySelector(".webmention__title"),u=e.createElement("html"),c="";u.innerHTML=i,s=u.querySelector("title"),o=u.querySelector("h1"),l.length<0&&(l=a.querySelector(".webmention__content")),l.length>0&&(c=s.length>0?s.innerText:o.length>0?o.innerHTML:"No title available")&&(c=c.replace(/<\/?[^>]+?>}/,""),(r=e.createElement("a")).href=n,r.appendChild(e.createTextNode(c)),l.innerHTML=r.outerHTML)}function h(e,n){if("XMLHttpRequest"in t){var i=new XMLHttpRequest;h=function(t,e){var n=!1;t="//whateverorigin.org/get?url="+encodeURIComponent(t),i.onreadystatechange=function(){4!=this.readyState||n||(n=!0,e(i.responseText))},i.onabort=function(){n||(n=!0,e(!1))},i.onerror=i.onabort,i.open("GET",t),i.send(null)}}else h=function(t,e){e(!1)};return h(e,n)}if("querySelectorAll"in e&&"filter"in[]&&"content"in e.createElement("template")){"JekyllWebmentionIO"in t||(t.JekyllWebmentionIO={}),JekyllWebmentionIO.existing_webmentions=[],JekyllWebmentionIO.processWebmentions=function(t){if(t&&!("error"in t)){var n=t.links.reverse();(n=l(n=a(n))).length&&(s(n=u(n)),this.counter_update_event&&e.dispatchEvent(this.counter_update_event))}};var d={},f={};n(),i(),r()}}(this,this.document),function(t){"use strict";t.location.origin||(t.l
split=split||function(t){var e,n=String.prototype.split,i=/()??/.exec("")[1]===t;return e=function(e,r,s){if("[object RegExp]"!==Object.prototype.toString.call(r))return n.call(e,r,s);var o,a,l,u,c=[],h=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.extended?"x":"")+(r.sticky?"y":""),d=0;r=new RegExp(r.source,h+"g");for(e+="",i||(o=new RegExp("^"+r.source+"$(?!\\s)",h)),s=s===t?-1>>>0:s>>>0;(a=r.exec(e))&&!((l=a.index+a[0].length)>d&&(c.push(e.slice(d,a.index)),!i&&a.length>1&&a[0].replace(o,function(){for(var e=1;e<arguments.length-2;e++)arguments[e]===t&&(a[e]=t)}),a.length>1&&a.index<e.length&&Array.prototype.push.apply(c,a.slice(1)),u=a[0].length,d=l,c.length>=s));)r.lastIndex===a.index&&r.lastIndex++;return d===e.length?!u&&r.test("")||c.push(""):c.push(e.slice(d)),c.length>s?c.slice(0,s):c},String.prototype.split=function(t,n){return e(this,t,n)},e}(),"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=Liquid),exports.Liquid=Liquid),function(t,e,n){"use strict";function i(){for(var t,i,s,o,a,l=r.length;l--;)if("dataset"in(t=r[l])&&"webmentionTypes"in t.dataset){for(s=(i=t.dataset.webmentionTypes.split(",")).length,a=0;s--;)o=n.types[i[s]],a+=e.querySelectorAll(".webmention.webmention--"+o).length;t.innerText=a}else t.innerText=e.querySelectorAll(".webmention").length}if("querySelectorAll"in e){"JekyllWebmentionIO"in t||(t.JekyllWebmentionIO={});var r=e.querySelectorAll(".webmention-count"),s="JekyllWebmentionIO:update_counters";r.length&&(n.counter_update_event=new Event(s),e.addEventListener(s,i,!1))}}(this,this.document,this.JekyllWebmentionIO),function(t,e){if("querySelectorAll"in e){"JekyllWebmentionIO"in t||(t.JekyllWebmentionIO={});var n,i=[],r=e.querySelector('meta[property="webmention:redirected_from"]'),s=t.location.origin;i.push(s+t.location.pathname),r&&(r.getAttribute("content").split(",").forEach(function(t){i.push(t.indexOf("//")<0?s+t:t)}),!1),(n=e.createElement("script")).async=!0,n.src="https://webmention.io/api/mentions?jsonp=window.JekyllWebmentionIO.processWebmentions&target[]="+i.join("&target[]="),e.querySelector("head").appendChild(n)}}(this,this.document),function(t,e){"JekyllWebmentionIO"in t||(t.JekyllWebmentionIO={}),e.types={bookmarks:"bookmark",likes:"like",links:"link",posts:"post",replies:"reply",reposts:"repost",rsvps:"rsvp"}}(this,this.JekyllWebmentionIO);