;(function () {
  const previousGetItem = window.Storage.prototype.getItem
  localStorage.getItem = function (key) {
    if (key === 'bloom.allowedCallbacks') {
      return null
    }
    return previousGetItem.call(localStorage, key)
  }
  const previousWindowGetItem = window.Storage.prototype.getItem
  window.Storage.prototype.getItem = function (key) {
    if (key === 'bloom.allowedCallbacks') {
      return null
    }
    return previousWindowGetItem.call(this, key)
  }
  const allowedCallbacks = JSON.parse(
    previousGetItem.call(localStorage, 'bloom.allowedCallbacks') || '[]'
  )
  const isBloomElement = (el) => {
    return (
      el?.textContent?.includes('🌸') ||
      el?.textContent?.toLowerCase()?.includes('bloom') ||
      el?.style?.border?.includes('rgb(238, 167, 237)') ||
      el?.innerHTML?.includes('bloom') ||
      el?.innerHTML?.toLowerCase()?.includes('eea7ed')
    )
  }
  const setInterval = window.setInterval
  const match = (callback) => {
    return callback.toString().toLowerCase().includes('bloom')
  }
  window.setInterval = (callback, delay) => {
    const _a = '[native code]'
    if (match(callback)) {
      return
    }
    return setInterval(callback, delay)
  }
  const previousRequestIdleCallback = window.requestIdleCallback
  window.requestIdleCallback = (callback, options) => {
    if (
      callback.toString().includes('&&o()') ||
      callback.toString().toLowerCase().includes('bloom')
    ) {
      return
    }
    return previousRequestIdleCallback(callback, options)
  }
  const previousElementQuerySelectorAll = Element.prototype.querySelectorAll
  Element.prototype.querySelectorAll = function (selector) {
    const elements = previousElementQuerySelectorAll.call(this, selector)
    return Array.from(elements).filter((e) => !isBloomElement(e))
  }
  const previousDocumentQuerySelectorAll = document.querySelectorAll
  document.querySelectorAll = function (selector) {
    const elements = previousDocumentQuerySelectorAll.call(this, selector)
    return Array.from(elements).filter((e) => !isBloomElement(e))
  }
  const setTimeout = window.setTimeout
  window.setTimeout = function (callback, delay, ...args) {
    const _a = '[native code]'
    if (delay > 500 && !allowedCallbacks.includes(callback.toString())) {
      return setTimeout(callback, 0, ...args)
    }
    return setTimeout(callback, delay, ...args)
  }
})()
