forked from grayleonard/mastodon-share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfedi-share.min.js
1 lines (1 loc) · 1.42 KB
/
fedi-share.min.js
1
Array.prototype.forEach||(Array.prototype.forEach=function(e){var t,o;if(null==this)throw new TypeError("this is null or not defined");var n=Object(this),r=n.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(t=arguments[1]),o=0;o<r;){var i;o in n&&(i=n[o],e.call(t,i,o,n)),o+=1}}),document.addEventListener("DOMContentLoaded",(function(){document.querySelectorAll(".fedi-share").forEach((function(e,t){e.querySelector(".fedi-check-toggle").id="fedi-check-toggle-"+t,e.querySelector(".fedi-check-label").htmlFor="fedi-check-toggle-"+t,e.querySelector(".fedi-share-button").addEventListener("click",(function(t){var o=new RegExp("^(?:(?:https?|ftp)://)?(?:\\S+(?::\\S*)?@|\\d{1,3}(?:\\.\\d{1,3}){3}|(?:(?:[a-z\\d\\u00a1-\\uffff]+-?)*[a-z\\d\\u00a1-\\uffff]+)(?:\\.(?:[a-z\\d\\u00a1-\\uffff]+-?)*[a-z\\d\\u00a1-\\uffff]+)*(?:\\.[a-z\\u00a1-\\uffff]{2,6}))(?::\\d+)?(?:[^\\s]*)?$","i"),n=e.querySelector('input[name="fedi-instance-input"]');if(o.test(n.value)){var r=`http://${n.value.replace(/(^\w+:|^)\/\//,"")}/share?text=${encodeURIComponent(document.title)} ${encodeURIComponent(location.href)}`;window.open(r,"new","toolbar=no,location=no,status=yes,resizable=yes,scrollbars=yes,height=600,width=400")}else n.classList.add("invalid"),setTimeout((function(){n.classList.remove("invalid")}),300)})),e.addEventListener("mouseleave",(function(t){e.querySelector(".fedi-check-toggle").checked=!1}))}))}));