Greasy Fork is available in English.

Greasy Fork+

Adds various features and improves the Greasy Fork experience

// ==UserScript==
// @name               Greasy Fork+
// @name:de            Greasy Fork+
// @name:es            Greasy Fork+
// @name:fr            Greasy Fork+
// @name:it            Greasy Fork+
// @name:ru            Greasy Fork+
// @name:zh-CN         Greasy Fork+
// @author             Davide <iFelix18@protonmail.com>
// @namespace          https://github.com/iFelix18
// @icon               https://www.google.com/s2/favicons?domain=https://greasyfork.org
// @description        Adds various features and improves the Greasy Fork experience
// @description:de     Fügt verschiedene Funktionen hinzu und verbessert das Greasy Fork-Erlebnis
// @description:es     Agrega varias funciones y mejora la experiencia de Greasy Fork
// @description:fr     Ajoute diverses fonctionnalités et améliore l'expérience Greasy Fork
// @description:it     Aggiunge varie funzionalità e migliora l'esperienza di Greasy Fork
// @description:ru     Добавляет различные функции и улучшает работу с Greasy Fork
// @description:zh-CN  添加各种功能并改善 Greasy Fork 体验
// @copyright          2021, Davide (https://github.com/iFelix18)
// @license            MIT
// @version            2.0.6
// @homepage           https://github.com/iFelix18/Userscripts#readme
// @homepageURL        https://github.com/iFelix18/Userscripts#readme
// @supportURL         https://github.com/iFelix18/Userscripts/issues
// @require            https://fastly.jsdelivr.net/gh/sizzlemctwizzle/GM_config@2207c5c1322ebb56e401f03c2e581719f909762a/gm_config.min.js
// @require            https://fastly.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
// @require            https://fastly.jsdelivr.net/npm/@ifelix18/utils@6.5.0/lib/index.min.js
// @require            https://fastly.jsdelivr.net/npm/@violentmonkey/shortcut@1.2.6/dist/index.min.js
// @match              *://greasyfork.org/*
// @match              *://sleazyfork.org/*
// @connect            greasyfork.org
// @compatible         chrome
// @compatible         edge
// @compatible         firefox
// @compatible         safari
// @grant              GM_getValue
// @grant              GM_setValue
// @grant              GM.deleteValue
// @grant              GM.getValue
// @grant              GM.notification
// @grant              GM.registerMenuCommand
// @grant              GM.setValue
// @run-at             document-start
// @inject-into        page
// ==/UserScript==

/* global $, GM_config, UU, VM */
/* eslint-disable unicorn/prefer-top-level-await */

(async () => {
  //* Constants
  const id = 'greasyfork-plus'
  const title = `${GM.info.script.name} v${GM.info.script.version} Settings`
  const fields = {
    hideBlacklistedScripts: {
      label: 'Hide blacklisted scripts:<br><span>Choose which lists to activate in the section below, press <b>Ctrl + Alt + B</b> to show Blacklisted scripts</span>',
      section: ['Features'],
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    hideHiddenScript: {
      label: 'Hide scripts:<br><span>Add a button to hide the script<br>See and edit the list of hidden scripts below, press <b>Ctrl + Alt + H</b> to show Hidden script',
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    showInstallButton: {
      label: 'Install button:<br><span>Add to the scripts list a button to install the script directly</span>',
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    showTotalInstalls: {
      label: 'Installations:<br><span>Shows the number of daily and total installations on the user profile</span>',
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    milestoneNotification: {
      label: 'Milestone notifications:<br><span>Get notified whenever your total installs got over any of these milestone<br>Separate milestones with a comma, leave blank to turn off notifications</span>',
      labelPos: 'left',
      type: 'text',
      title: 'Separate milestones with a comma!',
      size: 150,
      default: '10, 100, 500, 1000, 2500, 5000, 10000, 100000, 1000000'
    },
    nonLatins: {
      label: 'Non-Latin:<br><span>This list blocks all scripts with non-Latin characters in the title/description</span>',
      section: ['Lists'],
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    blacklist: {
      label: 'Blacklist:<br><span>A "non-opinionable" list that blocks all scripts with emoji in the title/description, references to "bots", "cheats" and some online game sites, and other "bullshit"</span>',
      labelPos: 'right',
      type: 'checkbox',
      default: true
    },
    customBlacklist: {
      label: 'Custom Blacklist:<br><span>Personal blacklist defined by a set of unwanted words<br>Separate unwanted words with a comma (example: YouTube, Facebook, pizza), leave blank to disable this list</span>',
      labelPos: 'left',
      type: 'text',
      title: 'Separate unwanted words with a comma!',
      size: 150,
      default: ''
    },
    hiddenList: {
      label: 'Hidden Scripts:<br><span>Block individual undesired scripts by their unique IDs<br>Separate IDs with a comma</span>',
      labelPos: 'left',
      type: 'textarea',
      title: 'Separate IDs with a comma!',
      default: '',
      save: false
    },
    logging: {
      label: 'Logging',
      section: ['Developer options'],
      labelPos: 'right',
      type: 'checkbox',
      default: false
    },
    debugging: {
      label: 'Debugging',
      labelPos: 'right',
      type: 'checkbox',
      default: false
    }
  }
  const logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gYRBAceMUIR3QAAEg9JREFUeNrtXWlwVNW2/k4n3RkbM5FRMEHUBOIAekGMJV4lYVDBAeQ+IYTJODAVjwBXfRZFQRn04vthiQgGEOMDiylY4lB6g1CG8VFJLF4SSYiBRBDTSZM06aQzdH/vB+ccex5Id9IBV9WuJDvnnL3P+s7+9tprr723gBsUkkoAEAShG96VQABqAOHiz+EARog/7wAwGECkmMLEe/QAropJA+AigPMAKsWfbQCuianH7B2iAOgFQehEP4kA/xClqOQHANwL4B4AdwEYCiCkl8/uAFAPoAbAOQBnAZQDqALQhVtcEgAsB3AcwG/il0ofpzaxrONi2Qm3ksIFAFEAxgHYDqDVE+VJEhISwoKCAra0tFCj0TA/P9/uddb363Q6/vTTT/Lfw4YNo0KhaBXrMk6sm3CzKj8JwKsAvlGpVO2zZ8/mkSNHePnyZRoMBrsKcwTAnj17aC2LFi1yCYB1/vnz57ljxw7p73YA34h1TLqZFB8MIDcwMLBi6NChHUuXLuXFixdpT9wF4MyZMxw5ciQHDRrEjz/+mCR5+vRpjwGw/jszM5NRUVEdACoA5Ip1H7ASC+A5AP/rLf6WZMyYMXJeQkICSfLatWu9BqCjo4Pfffed+T0lAB4xs7YGjEwRrQ2jNztQSVQqlUeKdfc6B/e1ANgEIG0gKD4QwGYA3QCoUCgoCAIFQWBqaip//fVXOhN3AfBUsQCoUqluFACK73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\p{Script=Latin}\p{Script=Common}\p{Script=Inherited}]/gu
  const blacklist = new RegExp([ /* cSpell: disable-next-line */
    '\\bagar((.)?io)?\\b', '\\bagma((.)?io)?\\b', '\\baimbot\\b', '\\barras((.)?io)?\\b', '\\bbot(s)?\\b', '\\bbubble((.)?am)?\\b', '\\bcheat(s)?\\b', '\\bdiep((.)?io)?\\b', '\\bfreebitco((.)?in)?\\b', '\\bgota((.)?io)?\\b', '\\bhack(s)?\\b', '\\bkrunker((.)?io)?\\b', '\\blostworld((.)?io)?\\b', '\\bmoomoo((.)?io)?\\b', '\\broblox(.com)?\\b', '\\bshell\\sshockers\\b', '\\bshellshock((.)?io)?\\b', '\\bshellshockers\\b', '\\bskribbl((.)?io)?\\b', '\\bslither((.)?io)?\\b', '\\bsurviv((.)?io)?\\b', '\\btaming((.)?io)?\\b', '\\bvenge((.)?io)?\\b', '\\bvertix((.)?io)?\\b', '\\bzombs((.)?io)?\\b', '\\p{Extended_Pictographic}'
  ].join('|'), 'giu')
  const hiddenList = await GM.getValue('hiddenList', [])
  const lang = $('html').attr('lang')
  const locales = { /* cSpell: disable */
    de: {
      downgrade: 'Auf zurückstufen',
      hide: '❌ Dieses skript ausblenden',
      install: 'Installieren',
      notHide: '✔️ Dieses skript nicht ausblenden',
      milestone: 'Herzlichen Glückwunsch, Ihre Skripte haben den Meilenstein von insgesamt $1 Installationen überschritten!',
      reinstall: 'Erneut installieren',
      update: 'Auf aktualisieren'
    },
    en: {
      downgrade: 'Downgrade to',
      hide: '❌ Hide this script',
      install: 'Install',
      notHide: '✔️ Not hide this script',
      milestone: 'Congrats, your scripts got over the milestone of $1 total installs!',
      reinstall: 'Reinstall',
      update: 'Update to'
    },
    es: {
      downgrade: 'Degradar a',
      hide: '❌ Ocultar este script',
      install: 'Instalar',
      notHide: '✔️ No ocultar este script',
      milestone: '¡Felicidades, sus scripts superaron el hito de $1 instalaciones totales!',
      reinstall: 'Reinstalar',
      update: 'Actualizar a'
    },
    fr: {
      downgrade: 'Revenir à',
      hide: '❌ Cacher ce script',
      install: 'Installer',
      notHide: '✔️ Ne pas cacher ce script',
      milestone: 'Félicitations, vos scripts ont franchi le cap des $1 installations au total!',
      reinstall: 'Réinstaller',
      update: 'Mettre à'
    },
    it: {
      downgrade: 'Riporta a',
      hide: '❌ Nascondi questo script',
      install: 'Installa',
      notHide: '✔️ Non nascondere questo script',
      milestone: 'Congratulazioni, i tuoi script hanno superato il traguardo di $1 installazioni totali!',
      reinstall: 'Reinstalla',
      update: 'Aggiorna a'
    },
    ru: {
      downgrade: 'Откатить до',
      hide: '❌ Скрыть этот скрипт',
      install: 'Установить',
      notHide: '✔️ Не скрывать этот сценарий',
      milestone: 'Поздравляем, ваши скрипты преодолели рубеж в $1 установок!',
      reinstall: 'Переустановить',
      update: 'Обновить до'
    },
    'zh-CN': {
      downgrade: '降级到',
      hide: '❌ 隐藏此脚本',
      install: '安装',
      notHide: '✔️ 不隐藏此脚本',
      milestone: '恭喜,您的脚本超过了 $1 次总安装的里程碑!',
      reinstall: '重新安装',
      update: '更新到'
    }
  } /* cSpell: enable */

  //* GM_config
  GM_config.init({
    id,
    title,
    fields,
    css: '#greasyfork-plus *{font-family:Open Sans,sans-serif,Segoe UI Emoji!important;font-size:12px}#greasyfork-plus .section_header{background-color:#670000!important;background-image:linear-gradient(#670000,#900)!important;border:1px solid transparent!important;color:#fff!important}#greasyfork-plus .field_label{margin-bottom:4px!important}#greasyfork-plus .field_label span{font-size:95%!important;font-style:italic!important;opacity:.8!important}#greasyfork-plus .field_label b{color:#670000!important}#greasyfork-plus .config_var{display:flex!important}#greasyfork-plus_customBlacklist_var,#greasyfork-plus_hiddenList_var,#greasyfork-plus_milestoneNotification_var{flex-direction:column!important;margin-left:21px!important}#greasyfork-plus_field_customBlacklist,#greasyfork-plus_field_milestoneNotification{flex:1!important}#greasyfork-plus_field_hiddenList{box-sizing:border-box!important;overflow:hidden!important;resize:none!important;width:100%!important}',
    events: {
      init: () => {
        // ? remove old hiddenList from Greasy Fork+ 1.x
        if (!Array.isArray(hiddenList)) {
          GM.deleteValue('hiddenList')
          setTimeout(window.location.reload(false), 500)
        }

        //! Userscripts Safari: GM.registerMenuCommand is missing
        if (GM.info.scriptHandler !== 'Userscripts') GM.registerMenuCommand('Configure', () => GM_config.open())
      },
      open: async (document) => {
        const textarea = $(document).find(`#${id}_field_hiddenList`)

        // show unsaved hidden list in config panel
        const hiddenList = await GM.getValue('hiddenList', [])
        const unsavedHiddenList = GM_config.get('hiddenList') !== '' ? GM_config.get('hiddenList').split(',').map(Number) : undefined

        if (($(hiddenList).not(unsavedHiddenList).length > 0 || $(unsavedHiddenList).not(hiddenList).length > 0) && !$.isEmptyObject(hiddenList)) {
          GM_config.fields.hiddenList.value = hiddenList.sort((a, b) => a - b).join(', ')

          // ? fix GM_config
          GM_config.close()
          GM_config.open()
        }

        // resize textarea on creation and editing
        const resize = (target) => {
          $(target).height('')
          $(target).height($(target)[0].scrollHeight)
        }

        resize(textarea)
        $(textarea).bind({
          input: (event) => resize(event.target)
        })
      },
      save: (forgotten) => {
        // store unsaved hiddenList
        const unsavedHiddenList = forgotten.hiddenList !== '' ? forgotten.hiddenList.split(',').map(Number).filter((element) => element !== 0) : undefined

        if (GM_config.isOpen) {
          GM.setValue('hiddenList', $.makeArray(unsavedHiddenList))

          UU.alert('settings saved')
          GM_config.close()
          setTimeout(window.location.reload(false), 500)
        }
      }
    }
  })

  //* Utils
  UU.init({ id, logging: GM_config.get('logging') })
  UU.log(nonLatins)
  UU.log(blacklist)
  UU.log(hiddenList)

  //* Shortcuts
  const { register } = VM.shortcut
  register('ctrl-alt-s', () => {
    GM_config.open()
  })
  register('ctrl-alt-b', () => {
    $('.script-list li.blacklisted').toggle()
  })
  register('ctrl-alt-h', () => {
    $('.script-list li.hidden').toggle()
  })

  //* Functions
  /**
   * Adds a link to the menu to access the script configuration
   */
  const addSettingsToMenu = () => {
    const menu = `<li class=${id}><a href=""onclick=return!1>${GM.info.script.name}</a>`

    $('#site-nav > nav > li').first().before(menu)
    $(`.${id}`).click(() => GM_config.open())
  }

  /**
   * Adds buttons to the side menu to quickly show/hide scripts hidden by filters
   */
  const addOptions = () => {
    // create menu
    const html = `<div class=list-option-group id=${id}-options>${GM.info.script.name} Lists:<ul><li class="list-option blacklisted"><a href=/blacklist onclick=return!1>Blacklisted scripts (${$('.script-list li.blacklisted').length})</a><li class="list-option hidden"><a href=/blacklist onclick=return!1>Hidden scripts (${$('.script-list li.hidden').length})</a></ul></div>`
    $('.list-option-groups > div').first().before(html)

    // click
    $('.list-option-group li.blacklisted').click(() => $('.script-list li.blacklisted').toggle())
    $('.list-option-group li.hidden').click(() => $('.script-list li.hidden').toggle())
  }

  /**
   * Get script data from Greasy Fork API
   *
   * @param {number} id Script ID
   * @returns {Promise} Script data
   */
  const getScriptData = async (id) => {
    return new Promise((resolve, reject) => {
      fetch(`https://${window.location.hostname}/scripts/${id}.json`)
        .then((response) => {
          UU.log(`${response.status}: ${response.url}`)
          return response.json()
        })
        .then((data) => resolve(data))
    })
  }

  /**
   * Get user data from Greasy Fork API
   *
   * @param {string} userID User ID
   * @returns {Promise} User data
   */
  const getUserData = (userID) => {
    return new Promise((resolve, reject) => {
      fetch(`https://${window.location.hostname}/users/${userID}.json`)
        .then((response) => {
          UU.log(`${response.status}: ${response.url}`)
          return response.json()
        }).then((data) => resolve(data))
    })
  }

  /**
   * Get user total installs
   *
   * @param {object} data Data
   * @returns {Promise} Total installs
   */
  const getTotalInstalls = (data) => {
    return new Promise((resolve, reject) => {
      const totalInstalls = []

      $.each(data.scripts, (index, element) => {
        totalInstalls.push(Number.parseInt(element.total_installs, 10))
      })

      resolve(totalInstalls.reduce((a, b) => a + b, 0))
    })
  }

  /**
   * Returns installed version
   *
   * @param {string} name Script name
   * @param {string} namespace Script namespace
   * @returns {string} Installed version
   */
  const isInstalled = (name, namespace) => {
    return new Promise((resolve, reject) => {
      if (window.external && window.external.Violentmonkey) {
        window.external.Violentmonkey.isInstalled(name, namespace).then((data) => resolve(data))
        return
      }

      if (window.external && window.external.Tampermonkey) {
        window.external.Tampermonkey.isInstalled(name, namespace, (data) => {
          (data.installed) ? resolve(data.version) : resolve()
        })
        return
      }

      resolve()
    })
  }

  /**
   * Compare two version
   *
   * @param {string} v1 First version
   * @param {string} v2 Second version
   * @returns {number} Comparison value
   */
  const compareVersions = (v1, v2) => {
    if (!v1 || !v2) return
    if (v1 === null || v2 === null) return
    if (v1 === v2) return 0

    const sv1 = v1.split('.').map((index) => +index)
    const sv2 = v2.split('.').map((index) => +index)

    for (let index = 0; index < Math.max(sv1.length, sv2.length); index++) {
      if (sv1[index] > sv2[index]) return 1
      if (sv1[index] < sv2[index]) return -1
    }

    return 0
  }

  /**
   * Return label for the hide script button
   *
   * @param {boolean} hidden Is hidden
   * @returns {string} Label
   */
  const blockLabel = (hidden) => {
    return hidden ? (locales[lang] ? locales[lang].notHide : locales.en.notHide) : (locales[lang] ? locales[lang].hide : locales.en.hide)
  }

  /**
   * Return label for the install button
   *
   * @param {number} update Update value
   * @returns {string} Label
   */
  const installLabel = (update) => {
    switch (update) {
      case undefined: {
        return locales[lang] ? locales[lang].install : locales.en.install
      }
      case 1: {
        return locales[lang] ? locales[lang].update : locales.en.update
      }
      case -1: {
        return locales[lang] ? locales[lang].downgrade : locales.en.downgrade
      }
      default: {
        return locales[lang] ? locales[lang].reinstall : locales.en.reinstall
      }
    }
  }

  /**
   * Hide a blacklisted script
   *
   * @param {object} element  Script
   * @param {string} list     Blacklist name
   */
  const hideBlacklistedScript = (element, list) => {
    const name = $(element).find('.script-link').text()
    const description = $(element).find('.script-description').text()

    if (!name) return

    switch (list) {
      case 'nonLatins':
        if ((nonLatins.test(name) || nonLatins.test(description)) && !$(element).hasClass('blacklisted')) {
          $(element).addClass('blacklisted non-latins')
          if (GM_config.get('hideBlacklistedScripts') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (non-latin)') }
        }
        break
      case 'blacklist':
        if ((blacklist.test(name) || blacklist.test(description)) && !$(element).hasClass('blacklisted')) {
          $(element).addClass('blacklisted blacklist')
          if (GM_config.get('hideBlacklistedScripts') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (blacklist)') }
        }
        break
      case 'customBlacklist': {
        const customBlacklist = new RegExp(GM_config.get('customBlacklist').replace(/\s/g, '').split(',').join('|'), 'giu')
        if ((customBlacklist.test(name) || customBlacklist.test(description)) && !$(element).hasClass('blacklisted')) {
          $(element).addClass('blacklisted custom-blacklist')
          if (GM_config.get('hideBlacklistedScripts') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (custom-blacklist)') }
        }
        break
      }
      default:
        UU.log('No blacklists')
        break
    }
  }

  /**
   * Hide a hidden scripts
   *
   * @param {object} element Script
   * @param {number} id Script ID
   * @param {boolean} list Is list
   */
  const hideHiddenScript = async (element, id, list) => {
    // if is in hiddenList hide it
    if ($.inArray(id, hiddenList) !== -1) {
      $(element).addClass('hidden')
      if (GM_config.get('hideHiddenScript') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (hidden)') }
    }

    // add button to hide the script
    $(element).find('.badge-js, .badge-css').before(`<span class=block-button role=button style=cursor:pointer;font-size:70%>${blockLabel($(element).hasClass('hidden'))}</span>`)
    $(element).find('header h2').append(`<span class=block-button role=button style=cursor:pointer;font-size:50%;margin-left:1ex>${blockLabel($(element).hasClass('hidden'))}</span>`)

    // on click...
    $(element).find('.block-button').click((event) => {
      event.stopPropagation()

      // ...if it is not in the list add it and hide it...
      if ($.inArray(id, hiddenList) === -1) {
        hiddenList.push(id)

        GM.setValue('hiddenList', hiddenList)

        if (list) {
          $(element).hide(750).addClass('hidden').find('.block-button').text(blockLabel($(element).hasClass('hidden')))
          if (GM_config.get('hideHiddenScript') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (hidden)') }
        } else {
          $(element).addClass('hidden').find('.block-button').text(blockLabel($(element).hasClass('hidden')))
          if (GM_config.get('hideHiddenScript') && GM_config.get('debugging')) { $(element).find('.script-link').append(' (hidden)') }
        }
      } else { // ...else remove it
        hiddenList.splice($.inArray(id, hiddenList), 1)

        GM.setValue('hiddenList', hiddenList)

        $(element).removeClass('hidden').find('.block-button').text(blockLabel($(element).hasClass('hidden')))
        if (GM_config.get('hideHiddenScript') && GM_config.get('debugging')) { $(element).find('.script-link').html($(element).find('.script-link').html().replace(' (hidden)', '')) }
      }
    })
  }

  /**
   * Shows a button to install the script
   *
   * @param {object} element Script
   * @param {string} url Script URL
   * @param {string} label Label
   * @param {string} version Script version
   */
  const addInstallButton = (element, url, label, version) => {
    $(element)
      .find('.badge-js, .badge-css')
      .after(`<a class=install-link href=${url} style=float:right;zoom:.7;-moz-transform:scale(.7);text-decoration:none>${label} ${version}</a>`)
  }

  //* Main Script
  $(async () => {
    addSettingsToMenu()

    const userID = $('.user-profile-link a').length > 0 ? $('.user-profile-link a').attr('href') : undefined

    // blacklisted scripts / hidden scripts / install button
    if (window.location.pathname !== userID && !/discussions/.test(window.location.pathname) && (GM_config.get('hideBlacklistedScripts') || GM_config.get('hideHiddenScript') || GM_config.get('showInstallButton'))) {
      // for each script in the list
      UU.observe.creation('.script-list', (scriptList) => {
        $(scriptList).find('li').each(async (index, element) => {
          const scriptID = $(element).data('script-id')

          // blacklisted scripts
          if (GM_config.get('nonLatins')) hideBlacklistedScript(element, 'nonLatins')
          if (GM_config.get('blacklist')) hideBlacklistedScript(element, 'blacklist')
          if (GM_config.get('customBlacklist')) hideBlacklistedScript(element, 'customBlacklist')

          // hidden scripts
          if (GM_config.get('hideHiddenScript')) hideHiddenScript(element, scriptID, true)

          // install button
          if (GM_config.get('showInstallButton')) {
            const script = await getScriptData(scriptID).then()
            const installed = await isInstalled(script.name, script.namespace).then()
            const update = compareVersions(script.version, installed)
            const label = installLabel(update)

            addInstallButton(element, script.code_url, label, script.version)
          }
        })
      })

      // hidden scripts on details page
      if (GM_config.get('hideHiddenScript') && $('#script-info').length > 0) {
        const id = $('#script-info').find('.install-link').data('script-id')
        hideHiddenScript($('#script-info'), id, false)
      }

      // add options and style for blacklisted/hidden scripts
      if (GM_config.get('hideBlacklistedScripts') || GM_config.get('hideHiddenScript')) {
        addOptions()
        UU.addStyle('.script-list li.blacklisted{display:none;background:#321919;color:#e8e6e3}.script-list li.hidden{display:none;background:#321932;color:#e8e6e3}.script-list li.blacklisted a:not(.install-link),.script-list li.hidden a:not(.install-link){color:#ff8484}#script-info.hidden,#script-info.hidden .user-content{background:#321932;color:#e8e6e3}#script-info.hidden a:not(.install-link):not(.install-help-link){color:#ff8484}#script-info.hidden code{background-color:transparent}')
      }
    }

    // total installs
    if (GM_config.get('showTotalInstalls') && $('#user-script-list').length > 0) {
      const dailyInstalls = []
      const totalInstalls = []

      $('#user-script-list').find('li dd.script-list-daily-installs').each((index, element) => {
        dailyInstalls.push(Number.parseInt($(element).text().replace(/\D/g, ''), 10))
      })
      $('#user-script-list').find('li dd.script-list-total-installs').each((index, element) => {
        totalInstalls.push(Number.parseInt($(element).text().replace(/\D/g, ''), 10))
      })

      $('#script-list-sort').find('.list-option.list-current:nth-child(1), .list-option:not(list-current):nth-child(1) a').append(`<span> (${dailyInstalls.reduce((a, b) => a + b, 0).toLocaleString()})</span>`)
      $('#script-list-sort').find('.list-option.list-current:nth-child(2), .list-option:not(list-current):nth-child(2) a').append(`<span> (${totalInstalls.reduce((a, b) => a + b, 0).toLocaleString()})</span>`)
    }

    // milestone notification
    if (GM_config.get('milestoneNotification')) {
      const milestones = GM_config.get('milestoneNotification').replace(/\s/g, '').split(',').map(Number)

      if (!userID) return

      const userData = await getUserData(userID.match(/\d+(?=\D)/g)).then()
      const totalInstalls = await getTotalInstalls(userData).then()
      const lastMilestone = await GM.getValue('lastMilestone', 0)
      const milestone = $($.grep(milestones, (milestone) => totalInstalls >= milestone)).get(-1)

      UU.log(`total installs are "${totalInstalls}", milestone reached is "${milestone}", last milestone reached is "${lastMilestone}"`)

      if (milestone <= lastMilestone) return

      GM.setValue('lastMilestone', milestone)

      const text = (locales[lang] ? locales[lang].milestone : locales.en.milestone).replace('$1', milestone.toLocaleString())
      if (GM.info.scriptHandler !== 'Userscripts') { //! Userscripts Safari: GM.notification is missing
        GM.notification({
          text,
          title: GM.info.script.name,
          image: logo,
          onclick: () => {
            window.location = `https://${window.location.hostname}${userID}#user-script-list-section`
          }
        })
      } else {
        UU.alert(text)
      }
    }
  })
})()