Preemptively added Threads support. This won't work yet, because Threads is not a real fediverse server, but if it ever becomes one, the code will be ready.
This commit is contained in:
parent
6135022762
commit
76e86a24b5
1
fediverse-share-button/icons/threads.svg
Normal file
1
fediverse-share-button/icons/threads.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg width="512" xmlns="http://www.w3.org/2000/svg" height="512" id="screenshot-58e2ee3b-6ed5-8049-8004-2216443373fd" viewBox="0 0 512 512" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1"><g id="shape-58e2ee3b-6ed5-8049-8004-2216443373fd"><defs><clipPath id="frame-clip-58e2ee3b-6ed5-8049-8004-2216443373fd-render-1" class="frame-clip frame-clip-def"><rect rx="20" ry="20" x="0" y="0" width="512" height="512" transform="matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)"/></clipPath></defs><g clip-path="url(#frame-clip-58e2ee3b-6ed5-8049-8004-2216443373fd-render-1)" fill="none"><g class="fills" id="fills-58e2ee3b-6ed5-8049-8004-2216443373fd"><rect rx="20" ry="20" x="0" y="0" width="512" height="512" transform="matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)" class="frame-background"/></g><g class="frame-children"><g id="shape-a2e26dde-73a9-8088-8004-2920fb95a0a7" rx="0" ry="0" style="fill: rgb(0, 0, 0);"><g id="shape-a2e26dde-73a9-8088-8004-2920fb97bf25"><g class="fills" id="fills-a2e26dde-73a9-8088-8004-2920fb97bf25"><path d="M378.520,237.302C376.315,236.245,374.075,235.228,371.805,234.254C367.853,161.435,328.064,119.747,261.253,119.320C260.950,119.318,260.649,119.318,260.347,119.318C220.385,119.318,187.150,136.376,166.693,167.415L203.437,192.621C218.719,169.435,242.702,164.493,260.364,164.493C260.568,164.493,260.773,164.493,260.975,164.495C282.973,164.635,299.573,171.031,310.317,183.504C318.136,192.585,323.365,205.133,325.955,220.970C306.451,217.655,285.357,216.636,262.808,217.929C199.287,221.588,158.451,258.634,161.194,310.112C162.585,336.224,175.594,358.688,197.821,373.363C216.614,385.768,240.819,391.835,265.974,390.461C299.195,388.640,325.256,375.965,343.437,352.789C357.245,335.189,365.979,312.381,369.835,283.643C385.667,293.197,397.400,305.771,403.880,320.885C414.899,346.579,415.541,388.800,381.091,423.221C350.907,453.376,314.624,466.421,259.791,466.824C198.966,466.373,152.965,446.867,123.056,408.845C95.049,373.243,80.575,321.819,80.035,256.000C80.575,190.181,95.049,138.756,123.056,103.154C152.965,65.133,198.965,45.627,259.790,45.175C321.056,45.630,367.859,65.230,398.912,103.435C414.139,122.170,425.619,145.730,433.187,173.201L476.245,161.713C467.072,127.899,452.637,98.762,432.995,74.597C393.184,25.618,334.960,0.520,259.940,0.000L259.640,0.000C184.772,0.519,127.200,25.711,88.523,74.878C54.106,118.630,36.353,179.509,35.757,255.820L35.755,256.000L35.757,256.180C36.353,332.491,54.106,393.371,88.523,437.123C127.200,486.288,184.772,511.483,259.640,512.000L259.940,512.000C326.501,511.539,373.419,494.112,412.069,455.496C462.637,404.976,461.115,341.651,444.448,302.776C432.491,274.899,409.693,252.257,378.520,237.302ZZM263.596,345.352C235.756,346.920,206.833,334.424,205.407,307.659C204.350,287.813,219.530,265.669,265.305,263.031C270.547,262.729,275.691,262.581,280.744,262.581C297.371,262.581,312.925,264.197,327.067,267.288C321.792,333.160,290.853,343.856,263.596,345.352ZZ" fill="var(--barcelona-primary-icon)" style="fill: var(--barcelona-primary-icon);"/></g></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 3 KiB |
|
@ -22,6 +22,7 @@
|
|||
"pleroma",
|
||||
"sharkey",
|
||||
"socialhome",
|
||||
"threads",
|
||||
"xmpp",
|
||||
"zap",
|
||||
];
|
||||
|
@ -35,6 +36,7 @@
|
|||
"mastodon",
|
||||
"misskey",
|
||||
"sharkey",
|
||||
"threads",
|
||||
];
|
||||
|
||||
// Helper functions.
|
||||
|
@ -65,7 +67,11 @@
|
|||
|
||||
supportNote.classList.add("fsb-d-none");
|
||||
|
||||
if (domainInput.value && domainInput.value.trim().length > 0 && !supportedSoftware.includes(software)){
|
||||
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");
|
||||
|
@ -184,6 +190,8 @@
|
|||
if (domainInput?.dataset?.software) {
|
||||
if (domainInput.dataset.software === "diaspora") {
|
||||
shareURL = `https://${domain}/bookmarklet?url=${getPageURL()}&title=${shareText}¬e=${getPageDescription()}`;
|
||||
} else if (domainInput.dataset.software === "threads") {
|
||||
shareURL = `https://${domain}/intent/post?text=${shareText}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
fediverse-share-button/script.min.js
vendored
2
fediverse-share-button/script.min.js
vendored
|
@ -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","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`;iconElement.alt=`${software} platform logo`;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","threads","xmpp","zap"];const supportedSoftware=["diaspora","glitch-soc","firefish","hometown","lemmy","mastodon","misskey","sharkey","threads"];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`;iconElement.alt=`${software} platform logo`;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()}`}else if(domainInput.dataset.software==="threads"){shareURL=`https://${domain}/intent/post?text=${shareText}`}}window.open(shareURL)}}))}))})();
|
||||
|
|
Loading…
Reference in a new issue