From 7a75ed180ea59a69d3704cfbde74a9946f399210 Mon Sep 17 00:00:00 2001 From: Stefan Bohacek Date: Fri, 17 May 2024 10:56:48 -0400 Subject: [PATCH] Added Sharkey support. --- fediverse-share-button/icons/sharkey.svg | 7 +++++++ fediverse-share-button/icons/todo.txt | 1 + fediverse-share-button/script.js | 2 ++ fediverse-share-button/script.min.js | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 fediverse-share-button/icons/sharkey.svg diff --git a/fediverse-share-button/icons/sharkey.svg b/fediverse-share-button/icons/sharkey.svg new file mode 100644 index 0000000..dfd1345 --- /dev/null +++ b/fediverse-share-button/icons/sharkey.svg @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/fediverse-share-button/icons/todo.txt b/fediverse-share-button/icons/todo.txt index 3102861..457f4eb 100644 --- a/fediverse-share-button/icons/todo.txt +++ b/fediverse-share-button/icons/todo.txt @@ -3,4 +3,5 @@ - Ecko - Groundpolis - Misty +- Sharkey - XMPP diff --git a/fediverse-share-button/script.js b/fediverse-share-button/script.js index d6a4191..27d6ae1 100644 --- a/fediverse-share-button/script.js +++ b/fediverse-share-button/script.js @@ -20,6 +20,7 @@ "misty", "osada", "pleroma", + "sharkey", "socialhome", "xmpp", "zap", @@ -33,6 +34,7 @@ "lemmy", "mastodon", "misskey", + "sharkey", ]; // Helper functions. diff --git a/fediverse-share-button/script.min.js b/fediverse-share-button/script.min.js index c37f76f..a839826 100644 --- a/fediverse-share-button/script.min.js +++ b/fediverse-share-button/script.min.js @@ -1 +1 @@ -(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`;supportNote.classList.add("fsb-d-none");if(domainInput.value&&domainInput.value.trim().length>0&&!supportedSoftware.includes(software)){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)}}))}))})(); +(async()=>{const knownSoftware=["calckey","diaspora","ecko","firefish","friendica","glitch-soc","gnu_social","gotosocial","groundpolis","hometown","hubzilla","kepi","lemmy","mastodon","misskey","misty","osada","pleroma","sharkey","socialhome","xmpp","zap"];const supportedSoftware=["diaspora","glitch-soc","firefish","hometown","lemmy","mastodon","misskey","sharkey"];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`;supportNote.classList.add("fsb-d-none");if(domainInput.value&&domainInput.value.trim().length>0&&!supportedSoftware.includes(software)){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)}}))}))})();