Skip to content

Instantly share code, notes, and snippets.

@smbarbour
Last active July 28, 2023 06:04
Show Gist options
  • Save smbarbour/251e005ca1297ef29ac47858c76b5916 to your computer and use it in GitHub Desktop.
Save smbarbour/251e005ca1297ef29ac47858c76b5916 to your computer and use it in GitHub Desktop.
legacy.curseforge.com TamperMonkey script for MCUpdater
// ==UserScript==
// @name Curseforge MCUpdater URL getter
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Copies the download URL for the mod jar for MCUpdater to clipboard
// @author edwardg
// @match https://legacy.curseforge.com/minecraft/mc-mods/*/files/*
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
// Article is the box that holds all the information about the file
var Article = document.getElementsByTagName("article");
// Buttons is the Download and Install buttons
let Buttons = Article[0].getElementsByClassName("flex")[3];
// Run on button click to copy to clipboard
function copyToClipboard()
{
var Article = document.getElementsByTagName("article");
var Filename = Article[0].getElementsByClassName("text-sm")[1].textContent;
var CurseURL = window.location.href;
var fileStrIndex = CurseURL.indexOf("files/");
var fileID = CurseURL.slice(fileStrIndex + 6); // Leaves with just 7 numbers from end of URL
var File_URL = "https://edge.forgecdn.net/files/";
File_URL = File_URL + fileID.slice(0,4) + "/" + fileID.slice(4) + "/" + Filename;
//alert(fileID + "\n" + Filename + "\n" + File_URL);
GM_setClipboard(File_URL);
}
// Adds the copy button next to the other buttons
function addCopyButton(Element)
{
var newButton = document.createElement("button");
newButton.innerHTML = "<img src=\"https://files.mcupdater.com/MCU_TM.png\"/>";
newButton.onclick = () => {
copyToClipboard();
}
newButton.style.marginRight = "10px";
Element.insertBefore(newButton, Buttons.childNodes[0]);
}
// This calls the run
addCopyButton(Buttons)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment