Skip to content

Instantly share code, notes, and snippets.

@lazybios
Last active August 27, 2017 14:16
Show Gist options
  • Save lazybios/6e25cf0d31b09b7e16cd043d739c4c1c to your computer and use it in GitHub Desktop.
Save lazybios/6e25cf0d31b09b7e16cd043d739c4c1c to your computer and use it in GitHub Desktop.
function getShareMetas(){var title="",description="",image="";var title_element=document.querySelector('meta[property=\"wechat:title\"]');if(title_element){title=title_element.getAttribute(\"content\")}else{title=document.title}var description_element=document.querySelector('meta[property=\"wechat:description\"]');if(description_element){description=description_element.getAttribute(\"content\")}else{description=document.getElementsByName(\"description\")[0].content}var image_element=document.querySelector('meta[property=\"wechat:image\"]');if(image_element){image=image_element.getAttribute(\"content\")}else{image=document.getElementsByTagName(\"img\")[0].src}return'{\"title\":\"'+title+'\",\"description\":\"'+description+'\",\"image\":\"'+image+'\"}'};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment