Avatar Linker

Looks up the solution to avatars.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Avatar Linker
// @namespace   Marascripts
// @description Looks up the solution to avatars.
// @author      marascript
// @version     2.0.1
// @grant       none
// @match       https://www.marapets.com/stalker.php*
// @match       https://www.marapets.com/avatars.php?missing=1*
// @homepageURL https://github.com/marascript/userscripts
// @supportURL	https://github.com/marascript/userscripts/issues
// @license     MIT
// ==/UserScript==

/**
 * TODO: Add links to obtained avatars
 * TODO: Refactor functions
 */

;(async () => {
  'use strict'

  if (document.URL.includes('/avatars.php')) {
    const missingAvatars = document.querySelectorAll('#eachitemdiv')

    for (const avatar in missingAvatars) {
      missingAvatars[avatar].style.paddingBottom = '15px'

      if (!missingAvatars[avatar].querySelector('.offline')) {
        const name = missingAvatars[avatar]
          .querySelector('.itempadding .bigger')
          .innerText.replace(/ /g, '+')
        const link = document.createElement('a')
        const linkText = document.createTextNode('Check Solution')

        link.appendChild(linkText)
        link.href = `https://www.maraforce.com/avatars.php?search=${name}`
        link.target = '_blank'
        link.style.color = 'gray'
        link.style.fontWeight = 700

        missingAvatars[avatar].appendChild(link)
      }
    }
  }

  if (document.URL.includes('/stalker.php')) {
    const avatar = document
      .querySelector('.sbigger')
      ?.innerText.split(' Hidden Avatar')[0]

    if (avatar) {
      const urlEncodedAvatar = avatar.replace(/ /g, '+')
      const checkSolution = document.querySelector('.pricecheck').parentElement
      checkSolution.href = `https://www.maraforce.com/avatars.php?search=${urlEncodedAvatar}`
    }
  }
})()