-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshare.min.js
1 lines (1 loc) · 995 Bytes
/
share.min.js
1
const socialUrl={fb:"https://www.facebook.com/sharer.php?u=<URL>",in:"https://www.linkedin.com/shareArticle?mini=true&url=<URL>",ok:"https://connect.ok.ru/offer?url=<URL>",tg:"https://t.me/share/url?url=<URL>",tw:"https://twitter.com/share?url=<URL>",vb:"viber://forward?text=<URL>",vk:"https://vk.com/share.php?url=<URL>",wa:"https://wa.me/?text=<URL>"};function share(id,paramUrl){let pageUrl=document.URL;paramUrl&&"object"==typeof paramUrl&&(paramUrl.search&&(pageUrl+="?"+paramUrl.search),paramUrl.hash&&(pageUrl+="#"+paramUrl.hash));let left=(screen.width-570)/2+(0|screen.availLeft),top=(screen.height-570)/2+(0|screen.availTop),link=socialUrl[id].replace("<URL>",encodeURIComponent(pageUrl)),params="menubar=no,toolbar=no,status=no,width=570,height=570,left="+left+",top="+top;window.open(link,"share",params)}document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[class^=share-]").forEach(el=>el.addEventListener("click",()=>share(el.className.split("-")[1])))});