Skip to content

Instantly share code, notes, and snippets.

@theJinxrat
Created March 8, 2021 21:26
Show Gist options
  • Save theJinxrat/adc7ae839247956e13d98f96e92765a6 to your computer and use it in GitHub Desktop.
Save theJinxrat/adc7ae839247956e13d98f96e92765a6 to your computer and use it in GitHub Desktop.

Revisions

  1. theJinxrat created this gist Mar 8, 2021.
    12 changes: 12 additions & 0 deletions rss2json.vanilla.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    const items = []
    fetch('https://example.com/feed.xml')
    .then(res => res.text())
    .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
    .then(data => {
    data.querySelectorAll("item").forEach((item, idx) => {
    const obj = {}
    Array.from(item.children).map(v => obj[v.tagName] = v.textContent)
    items[idx] = obj
    })
    })
    .catch(console.error)