Ferium add command for modrinth

2022/6/6 19:57:03

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        Ferium add command for modrinth
// @namespace   Violentmonkey Scripts
// @match       https://modrinth.com/*
// @license     MIT
// @grant       none
// @version     0.2.3
// @author      -
// @description 2022/6/6 19:57:03
// ==/UserScript==

const observer = new MutationObserver((mutations, observer) => {
    for(const mutation of mutations) {
        if (mutation.type === 'childList' && mutation.target.id === 'search-results') {
            for(const node of mutation.addedNodes) {
                if(!node) continue
                const buttons = node.querySelector('.title')
                if(node.className === 'project-card base-card padding-bg' && !buttons.querySelector('button[title^="ferium"]')) {
                  const title = node.querySelector('.title a').href.match(/.*\/(.*)/)[1]
                  buttons.innerHTML += `<button class="iconified-button" onclick='navigator.clipboard.writeText("ferium add ${title}");this.innerText="Copied!"' title="ferium add ${title}">Ferium</button>`
                }
            }
        }
    }
});
observer.observe(document.body, { attributes: false, childList: true, subtree: true });

// Mod detail
const tabs = document.querySelector(".navigation-card > nav");
const id = location.href.match(/mod\/(.+?)\/?$/)
if(tabs && id) {
  tabs.innerHTML += `<a class="nav-link button-animation" data-v-5a76b3fa="" href="javascript:void(0)" onclick='navigator.clipboard.writeText("ferium add ${id[1]}");this.innerHTML="<span>Copied!</span>"' title="ferium add ${id[1]}"><span>Ferium</span></button>`
}


for(const node of Array.from(document.querySelectorAll('.project-card.base-card'))) {
  console.log(node)
  const buttons = node.querySelector('.title')
  if(!buttons.querySelector('button[title^="ferium"]')) {
    const title = node.querySelector('.title a').href.match(/.*\/(.*)/)[1]
    buttons.innerHTML += `<button class="iconified-button" onclick='navigator.clipboard.writeText("ferium add ${title}");this.innerText="Copied!"' title="ferium add ${title}">Ferium</button>`
  }
}