Ferium add command for modrinth

2022/6/6 19:57:03

当前为 2022-12-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Ferium add command for modrinth
  3. // @namespace Violentmonkey Scripts
  4. // @match https://modrinth.com/*
  5. // @license MIT
  6. // @grant none
  7. // @version 0.2.2
  8. // @author -
  9. // @description 2022/6/6 19:57:03
  10. // ==/UserScript==
  11.  
  12. const observer = new MutationObserver((mutations, observer) => {
  13. for(const mutation of mutations) {
  14. if (mutation.type === 'childList' && mutation.target.id === 'search-results') {
  15. for(const node of mutation.addedNodes) {
  16. const buttons = node.querySelector('.right-side .buttons')
  17. if(node.className === 'project-card card' && !buttons.querySelector('button[title^="ferium"]')) {
  18. const title = node.querySelector('.title a').href.match(/.*\/(.*)/)[1]
  19. buttons.innerHTML += `<button class="iconified-button" onclick='navigator.clipboard.writeText("ferium add ${title}");this.innerText="Copied!"' title="ferium add ${title}">Ferium</button>`
  20. }
  21. }
  22. }
  23. }
  24. });
  25. observer.observe(document.body, { attributes: false, childList: true, subtree: true });
  26.  
  27. // Mod detail
  28. const tabs = document.querySelector(".navigation.card");
  29. if(tabs) {
  30. const id = location.href.match(/mod\/(.+?)\/?$/)[1]
  31. tabs.innerHTML += `<a class="nav-link button-animation" data-v-5a76b3fa="" href="javascript:void(0)" onclick='navigator.clipboard.writeText("ferium add ${id}");this.innerHTML="<span>Copied!</span>"' title="ferium add ${id}"><span>Ferium</span></button>`
  32. }