From 3b8d6159a434be4a77bcbd2b804e969e9c35059a Mon Sep 17 00:00:00 2001 From: Stefan Bohacek Date: Fri, 17 May 2024 08:37:57 -0400 Subject: [PATCH] Switched JS minifier. --- README.md | 5 +++-- fediverse-share-button/script.min.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ed7657..64da20f 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,9 @@ Note that if you need to change the path at which the `fediverse-share-button` f After making changes to the JS and CSS files, make sure to minify them. ```sh -npm i minify -g -minify fediverse-share-button/script.js > fediverse-share-button/script.min.js +npm install terser -g +npm install minify -g +terser fediverse-share-button/script.js > fediverse-share-button/script.min.js minify fediverse-share-button/styles.css > fediverse-share-button/styles.min.css ``` diff --git a/fediverse-share-button/script.min.js b/fediverse-share-button/script.min.js index 74ca5fa..3c464bc 100644 --- a/fediverse-share-button/script.min.js +++ b/fediverse-share-button/script.min.js @@ -1 +1 @@ -(async ()=>{var a=['calckey','diaspora','ecko','firefish','friendica','glitch-soc','gnu_social','gotosocial','groundpolis','hometown','hubzilla','kepi','lemmy','mastodon','misskey','misty','osada','pleroma','socialhome','xmpp','zap'],b=['diaspora','glitch-soc','firefish','hometown','lemmy','mastodon','misskey'],c=()=>{var A=document.getElementsByClassName('fsb-script')[0];src=A.src;return src.replace('/script.js','')},d=(_,B)=>{const C=_.parentElement.parentElement.parentElement.getElementsByClassName('fsb-domain')[0],D=_.parentElement.parentElement.parentElement.getElementsByClassName('fsb-support-note')[0],E=_.parentElement.parentElement.parentElement.getElementsByClassName('fsb-support-note-link')[0];_.src=`${c()}/icons/${B}.svg`;b.includes(B)?D.classList.add('fsb-d-none'):E.href=`https:\\${C.value}`},e=_a=>{clearTimeout(l);_a.value?l=setTimeout(()=>f(_a),m):d(_a.parentElement.getElementsByClassName('fsb-icon')[0],'question')},f=async _A=>{const _b=k(_A.value),_e=_d?.software?.name,F=_A.parentElement.getElementsByClassName('fsb-icon')[0];const _c=await fetch(`https://fediverse-info.stefanbohacek.dev/node-info?domain=${_b}`);const _d=await _c.json();_A.dataset.software=_e;_e&&a.includes(_e)?d(F,_e):d(F,'question')},g=()=>{try {pageTitle=document.querySelector('meta[property=\'og:title\']').getAttribute('content')} catch {}return encodeURIComponent(document.title)},h=()=>{const aA=document.querySelector('meta[name=\'description\']')||document.querySelector('meta[property=\'og:description\']')||null;aA?.getAttribute&&(pageDescription=aA.getAttribute('content'));return encodeURIComponent('')},i=()=>{let aB='';window.getSelection?aB=`${window.getSelection()}`:document.selection&&document.selection.type!='Control'&&(aB=document.selection.createRange().text);return aB},j=()=>encodeURIComponent(window.location.href),k=aC=>aC.replace(/(^\w+:|^)\/\//,''),m=1300,n=localStorage.getItem('fsb-domain');let l;for(const aD of document.getElementsByClassName('fsb-prompt')){var o=aD.getElementsByClassName('fsb-domain')[0];n&&(o.value=n,e(o));o.addEventListener('input',()=>e(o));aD.addEventListener('submit',aE=>{aE.preventDefault();var _B=k(o?.value?.trim());if(_B?.length){var _C=i()||g();localStorage.setItem('fsb-domain',_B);o?.dataset?.software&&o.dataset.software=='diaspora'&&(shareURL=`https://${_B}/bookmarklet?url=${j()}&title=${_C}¬e=${h()}`);window.open(`https://${_B}/share?text=${_C+'%0A%0A'+j()}`)}})}})(); +(async()=>{const knownSoftware=["calckey","diaspora","ecko","firefish","friendica","glitch-soc","gnu_social","gotosocial","groundpolis","hometown","hubzilla","kepi","lemmy","mastodon","misskey","misty","osada","pleroma","socialhome","xmpp","zap"];const supportedSoftware=["diaspora","glitch-soc","firefish","hometown","lemmy","mastodon","misskey"];const getFSBPath=()=>{var scripts=document.getElementsByClassName("fsb-script")[0];src=scripts.src;return src.replace("/script.min.js","")};const updateTheIcon=(iconElement,software)=>{const domainInput=iconElement.parentElement.parentElement.parentElement.getElementsByClassName("fsb-domain")[0];const supportNote=iconElement.parentElement.parentElement.parentElement.getElementsByClassName("fsb-support-note")[0];const supportNoteLink=iconElement.parentElement.parentElement.parentElement.getElementsByClassName("fsb-support-note-link")[0];iconElement.src=`${getFSBPath()}/icons/${software}.svg`;if(supportedSoftware.includes(software)){supportNote.classList.add("fsb-d-none")}else{supportNoteLink.href=`https:\\${domainInput.value}`;supportNoteLink.innerHTML=domainInput.value;supportNote.classList.remove("fsb-d-none")}};const updateIcon=async domainInput=>{clearTimeout(typingTimer);if(domainInput.value){typingTimer=setTimeout((()=>{doneTyping(domainInput)}),doneTypingInterval)}else{const iconEl=domainInput.parentElement.getElementsByClassName("fsb-icon")[0];updateTheIcon(iconEl,"question")}};const doneTyping=async el=>{const domain=getDomain(el.value);const resp=await fetch(`https://fediverse-info.stefanbohacek.dev/node-info?domain=${domain}`);const respJSON=await resp.json();const software=respJSON?.software?.name;const iconEl=el.parentElement.getElementsByClassName("fsb-icon")[0];el.dataset.software=software;if(software&&knownSoftware.includes(software)){updateTheIcon(iconEl,software)}else{updateTheIcon(iconEl,"question")}};const getPageTitle=()=>{let pageTitle=document.title;try{pageTitle=document.querySelector("meta[property='og:title']").getAttribute("content")}catch(error){}return encodeURIComponent(pageTitle)};const getPageDescription=()=>{let pageDescription="";const metaDescription=document.querySelector("meta[name='description']")||document.querySelector("meta[property='og:description']")||null;if(metaDescription&&metaDescription.getAttribute){pageDescription=metaDescription.getAttribute("content")}return encodeURIComponent(pageDescription)};const getSelectedText=()=>{let text="";if(window.getSelection){text=window.getSelection().toString()}else if(document.selection&&document.selection.type!="Control"){text=document.selection.createRange().text}return text};const getPageURL=()=>encodeURIComponent(window.location.href);const getDomain=str=>str.replace(/(^\w+:|^)\/\//,"");let typingTimer;const doneTypingInterval=1300;const savedDomain=localStorage.getItem("fsb-domain");[...document.getElementsByClassName("fsb-prompt")].forEach((fsbPrompt=>{const domainInput=fsbPrompt.getElementsByClassName("fsb-domain")[0];if(savedDomain){domainInput.value=savedDomain;updateIcon(domainInput)}domainInput.addEventListener("input",(()=>{updateIcon(domainInput)}));fsbPrompt.addEventListener("submit",(ev=>{ev.preventDefault();const domain=getDomain(domainInput?.value?.trim());if(domain?.length){const shareText=getSelectedText()||getPageTitle();localStorage.setItem("fsb-domain",domain);let shareURL=`https://${domain}/share?text=${shareText+"%0A%0A"+getPageURL()}`;if(domainInput?.dataset?.software){if(domainInput.dataset.software==="diaspora"){shareURL=`https://${domain}/bookmarklet?url=${getPageURL()}&title=${shareText}¬e=${getPageDescription()}`}}window.open(shareURL)}}))}))})();