Ferium add command for modrinth

2022/6/6 19:57:03

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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>`
  }
}