Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active May 6, 2024 05:08
Show Gist options
  • Save tomhodgins/9159770c91aabb1fec53bda791333782 to your computer and use it in GitHub Desktop.
Save tomhodgins/9159770c91aabb1fec53bda791333782 to your computer and use it in GitHub Desktop.
/* JSON XPath search */ (await import('https://unpkg.com/espath')).default(window.dataLayer, '//string')
/* cookie to object */ Object.fromEntries(document.cookie.split('; ').map(entry => entry.split('=')))
/* cookie to object */ (await import('https://v2.crocdn.com/_plugins/cookie-to-object.js')).default()
/* css elements search */ document.querySelectorAll ('*')
/* xpath element search */ (await import('https://unpkg.com/queryxpath/queryxpath.es.js')).queryXPathAll ('//*')
/* check if opted into Convert Test (by id) */ (id => Object.fromEntries(document.cookie.split('; ').map(entry => entry.split('=')))._conv_v.includes(id)) (12345)
/* parse JSON in script[type*=json] */ [...document.querySelectorAll('script[type*="json"]')].map(tag => JSON.parse(tag.textContent))
/* strip circular references */ (a=>{const b=new WeakSet;return JSON.parse(JSON.stringify(a,(c,d)=>{if(d!==null&&typeof d==='object'){if(b.has(d))return;b.add(d)}return d}))}) (window)
/* window.navigator to object */ (obj => Object.fromEntries(Object.keys(obj.__proto__).map(key => [key, obj[key]])))(navigator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment