Skip to content

Instantly share code, notes, and snippets.

@PhoneDroid
Last active February 5, 2024 10:42
Show Gist options
  • Select an option

  • Save PhoneDroid/88ccad17e9cc4efd7a14c7f9be2b20ab to your computer and use it in GitHub Desktop.

Select an option

Save PhoneDroid/88ccad17e9cc4efd7a14c7f9be2b20ab to your computer and use it in GitHub Desktop.
Queries the first JSON-LD schema and copies it when clicking on the page.
const script = document.querySelector(`[ type = 'application/ld+json' ]`)
const raw = script.textContent
const text = JSON.stringify(JSON.parse(raw),null,4)
async function log (){
document.removeEventListener('click',log)
await navigator.clipboard.writeText(text)
console.clear()
console.debug(text)
window.alert(`Copied Schema.org Data`)
}
document.addEventListener('click',log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment