Ferium add command for modrinth

2022/6/6 19:57:03

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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>`
  }
}