Widget Script Help - IQ Air

I’m trying to load an IQ Air Widget but it doesn’t seem to display.

<div name="airvisual_widget" key="64a07bcdc24bea78d0166522"></div> 
<script type="text/javascript" src="https://widget.iqair.com/script/widget_v3.0.js"></script>

It is calling this code:

'use strict'
!(function (t) {
  window.AVWidget || (window.AVWidget = { cache: {} })
  const e = window.AVWidget.cache
  function n(t) {
    return document.getElementById(t.getAttribute('data-target'))
  }
  !(function () {
    for (
      var n = document.getElementsByName('airvisual_widget'),
        i = function (i) {
          const a = n[i]
          const s = a.getAttribute('key')
          !(function r(n, i) {
            if (e[n]) {
              if ('success' === e[n].status) return i(e[n].data)
              if ('fetching' === e[n].status)
                return setTimeout(function () {
                  return r(n, i)
                }, 100)
            }
            e[n] = { status: 'fetching' }
            const a = new XMLHttpRequest()
            a.open('GET', t + '/widgets/custom/' + n, !0)
            a.onreadystatechange = function () {
              let t = ''
              if (4 !== a.readyState || 200 !== a.status) return i(t)
              try {
                ;(t = JSON.parse(a.responseText)), (e[n].status = 'success')
              } catch (s) {
                e[n].status = 'failed'
              }
              ;(e[n].data = t), i(t)
            }
            a.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
            a.send()
          })(s, function (t) {
            return (function (t, e) {
              if ('string' == typeof e) return void (t.innerHTML = e)
              e.html && (t.innerHTML = e.html)
              if (e.js) {
                const n = document.createElement('script')
                ;(n.innerHTML = e.js), document.body.appendChild(n)
              }
            })(a, t)
          })
        },
        a = 0;
      a < n.length;
      ++a
    )
      i(a)
  })(),
    (window.AVWidget.showDetails = function (t) {
      const e = t.target
      const i = n(e)
      if (e && i) {
        const a = e.getBoundingClientRect()
        const s = i.getBoundingClientRect()
        const r = Math.max(a.left + a.width / 2 - s.width - 164, 0)
        const o = a.top + a.height + 10
        ;(i.style.left = r + 'px'), (i.style.top = o + 'px'), (i.style.display = 'block')
      }
    }),
    (window.AVWidget.hideDetails = function (t) {
      const e = n(t.target)
      e && (e.style.display = 'none')
    })
})('https://www.airvisual.com')

Any suggestions to make this work?

Hey @JoeT! When replying with a block of code, it’s important to put it into a code block so the formatting is maintained. You can tap the </> button in the toolbar to insert a code block (or highlight your text and then tap that button to format it).

Can you share more details about where or how you’ve used this code?

Edit: I edited your reply to wrap the code in code blocks and it’s a bit more clear what you were doing now. (Without the code block, big chunks of your reply were missing from the post)

I just tried the snippet in an HTML Custom Tile and it loaded for me:

It looks like that widget doesn’t automatically scale to fit, so it might not be ideal. If you’re looking for a Custom Weather tile that fills the space properly, you might consider: Weather Tile - Open Weather - Current and Forecast

Thanks @josh I see what I did now and have it displaying. I am going to check with IQ Air to see if they can create a friendlier layout for these types of uses.