Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name CurseForge Modpack Builder
- // @namespace ZeldoKavira
- // @description Modpack Builder
- // @include http://minecraft.curseforge.com/mc-mods/*
- // @include http://minecraft.curseforge.com/mc-mods
- // @include http://minecraft.curseforge.com/projects/*
- // @require http://code.jquery.com/jquery-1.11.2.min.js
- // @require http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.js
- // @version 10
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_listValues
- // @grant GM_deleteValue
- // ==/UserScript==
- var manifest = '{ \n\t"manifestType":"minecraftModpack",\n\t"manifestVersion":1,\n\t"name":"%name%",\n\t"version":"%version%",\n\t"author":"%author%",\n\t"description":"%description%",\n\t"files":[ \n%files%\n\t],\n\t"overrides":"overrides",\n\t"minecraft":{ \n\t\t"version":"%mcversion%",\n\t\t"libraries":"libraries",\n\t\t"additionalJavaArgs":{ \n\t\t\t"1.6":"-XX:JavaArgsAreSoMuchFun",\n\t\t\t"1.7":"-XX:DifferentArgsHereBecauseWhyNot"\n\t\t},\n\t\t"modLoaders":[ \n\t\t\t{ \n\t\t\t\t"id":"%forgeversion%",\n\t\t\t\t"primary":true\n\t\t\t}\n\t\t]\n\t}\n}';
- var editImage = 'https://modpacktool.cursecdn.com/imgs/editField.png';
- var deleteImage = 'https://modpacktool.cursecdn.com/imgs/deleteProject.png';
- var saveImage = 'https://modpacktool.cursecdn.com/imgs/exportProject.png';
- var loadImage = 'https://modpacktool.cursecdn.com/imgs/importProject.png';
- var checkMark = 'https://modpacktool.cursecdn.com/imgs/required.png';
- var noCheckmark = 'https://modpacktool.cursecdn.com/imgs/notRequired.png';
- var deleteFile = 'https://modpacktool.cursecdn.com/imgs/deleteFile.png';
- var mainDivStyleSmall = "p-feedback p-feedback-a roundBorder";
- var mainDivStyleFull = mainDivStyleSmall + " fullStyling";
- if (document.getElementsByClassName('details-versions').length > 0) {
- //We are on a files page.
- document.getElementsByClassName('details-actions') [0].innerHTML += '<a id="zzaddButton" style="text-align:center" class="e-button">Add</a>';
- $('#zzaddButton').click(addFile);
- }
- addSideBar();
- updateSideBar();
- function addSideBar() {
- //CSS Overrides and additions
- //Try and build off the sites CSS so that it flows with any changes as much as possible.
- var head = document.getElementsByTagName("head")[0];
- var style = document.createElement("style");
- style.setAttribute('type', 'text/css');
- style.innerText = ".fullStyling {min-width:258px;overflow:auto;} a.zProjectLink {margin-left: 5px;} span.zHeaders { font-weight:bold;} img.removeFile {margin-left: 6px;} .zProjectLink {margin-top:1px;} #zzSideBarDiv {left:-8px;z-index:3;transform: translateY(-50%);max-height:80%;min-height:36px;} #zzSideBarInnerDiv {text-align:left;cursor:auto;background-color: #5d5d5d;border:none;} #zzSideBarSpan {font-weight: normal;} .mainImgs { width:18px; height: 18px; position: absolute; cursor: pointer;} .infoSpan {background: url('https://dl.dropboxusercontent.com/u/27292492/scripts/imgs/editField.png');background-repeat: no-repeat;background-position: left center;background-size: 15px 15px; background-position-x: 6px;cursor: pointer;} .roundBorder {background-color: rgb(93, 93, 93);border-bottom-color: rgba(0, 0, 0, 0.2);border-bottom-style: solid;border-bottom-width: 4px;border-image-outset: 0px;border-image-repeat: stretch;border-image-slice: 100%;border-image-source: none;border-image-width: 1;border-left-color: rgba(0, 0, 0, 0.2);border-left-style: solid;border-left-width: 4px;border-right-color: rgba(0, 0, 0, 0.2);border-right-style: solid;border-right-width: 4px;border-top-color: rgba(0, 0, 0, 0.2);border-top-style: solid;border-top-width: 4px;-webkit-border-bottom-right-radius:8px;-moz-border-bottom-right-radius:8px;-ms-border-bottom-right-radius:8px;-o-border-bottom-right-radius:8px;border-bottom-right-radius:8px;-webkit-border-top-right-radius:8px;-moz-border-top-right-radius:8px;-ms-border-top-right-radius:8px;-o-border-top-right-radius:8px;border-top-right-radius:8px;} .zLinks a:visited,.zLinks a:link {color:#A9A9A9;}";
- head.appendChild(style);
- style = document.createElement("link");
- style.setAttribute('rel', 'stylesheet');
- style.setAttribute('type', 'text/css');
- style.setAttribute('href', 'http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.css');
- head.appendChild(style);
- //Add the divs needed to create the sidebar
- var parentDiv = document.getElementById('site-main');
- var node = document.createElement('DIV');
- node.setAttribute('class', mainDivStyleFull);
- node.setAttribute("id", "zzSideBarDiv");
- var innerDiv = document.createElement("DIV");
- innerDiv.setAttribute("id", "zzSideBarInnerDiv");
- innerDiv.setAttribute("class", "p-feedback-tab zLinks");
- var spn = document.createElement('SPAN');
- spn.setAttribute("class", "p-feedback-link j-feedback-link-text");
- spn.setAttribute("id", "zzSideBarSpan");
- node.appendChild(innerDiv);
- innerDiv.appendChild(spn);
- parentDiv.insertBefore(node, document.getElementById('footer-push'));
- //Stop the scrolling of the entire page if we are in the modpack div
- $('#zzSideBarDiv').on('DOMMouseScroll mousewheel', function(ev) {
- var $this = $(this),
- scrollTop = this.scrollTop,
- scrollHeight = this.scrollHeight,
- height = $this.height(),
- delta = (ev.type == 'DOMMouseScroll' ?
- ev.originalEvent.detail * -40 :
- ev.originalEvent.wheelDelta),
- up = delta > 0;
- var prevent = function() {
- ev.stopPropagation();
- ev.preventDefault();
- ev.returnValue = false;
- return false;
- }
- if (!up && -delta > scrollHeight - height - scrollTop) {
- $this.scrollTop(scrollHeight);
- return prevent();
- } else if (up && delta > scrollTop) {
- $this.scrollTop(0);
- return prevent();
- }
- });
- }
- function updateSideBar() {
- var parentDiv = document.getElementById('zzSideBarSpan');
- parentDiv.innerHTML="";
- if (GM_listValues().length == 0) {
- var img = document.createElement("img");
- img.setAttribute("src", loadImage);
- img.setAttribute("id", "imgLoad");
- img.setAttribute("class", "mainImgs");
- img.setAttribute("data-qtip", "Load Modpack");
- parentDiv.appendChild(img);
- parentDiv.parentNode.parentNode.setAttribute('class', mainDivStyleSmall);
- return;
- }
- parentDiv.parentNode.parentNode.setAttribute('class', mainDivStyleFull);
- appendText(parentDiv, "Modpack Information:", "zHeaders");
- var img = document.createElement("img");
- img.setAttribute("src", deleteImage);
- img.setAttribute("id", "imgDelete");
- img.setAttribute("class", "mainImgs");
- img.setAttribute("style", "right:8px;");
- img.setAttribute("data-qtip", "Delete Modpack");
- parentDiv.appendChild(img);
- img = document.createElement("img");
- img.setAttribute("src", saveImage);
- img.setAttribute("id", "imgGen");
- img.setAttribute("class", "mainImgs");
- img.setAttribute("style", "right:28px;");
- img.setAttribute("data-qtip", "Generate Modpack");
- parentDiv.appendChild(img);
- img = document.createElement("img");
- img.setAttribute("src", loadImage);
- img.setAttribute("id", "imgLoad");
- img.setAttribute("class", "mainImgs");
- img.setAttribute("style", "right:48px;");
- img.setAttribute("data-qtip", "Load Modpack");
- parentDiv.appendChild(img);
- appendInfoSpan(parentDiv, "maniName", "Name");
- appendInfoSpan(parentDiv, "maniVersion", "Version");
- appendInfoSpan(parentDiv, "maniAuthor", "Author Name");
- appendInfoSpan(parentDiv, "maniDesc", "Desc");
- appendInfoSpan(parentDiv, "maniMinecraft", "MC Ver");
- appendInfoSpan(parentDiv, "maniForge", "Forge Ver");
- var currentFiles = GM_listValues();
- var fileCount = 0;
- for (var i = 0; i < currentFiles.length; i++) {
- if (!isNaN(currentFiles[i].charAt(0))) {
- fileCount++;
- }
- }
- appendNewLine(parentDiv);
- appendNewLine(parentDiv);
- appendText(parentDiv, "Modpack Files (" + fileCount + "):", "zHeaders");
- for (var i = 0; i < currentFiles.length; i++) {
- if (!isNaN(currentFiles[i].charAt(0))) {
- appendNewLine(parentDiv);
- img = document.createElement("img");
- img.setAttribute("src", deleteFile);
- img.setAttribute("dataid", currentFiles[i]);
- img.setAttribute("style", "width:18px");
- img.setAttribute("class", "removeFile");
- img.setAttribute("data-qtip", "Remove file from project");
- parentDiv.appendChild(img);
- img = document.createElement("img");
- img.setAttribute("src", GM_getValue('required' + currentFiles[i], false) ? checkMark : noCheckmark);
- img.setAttribute("datareq", GM_getValue('required' + currentFiles[i], false));
- img.setAttribute("dataid", currentFiles[i]);
- img.setAttribute("style", "width:18px");
- img.setAttribute("class", "setRequired");
- img.setAttribute("data-qtip", GM_getValue('required' + currentFiles[i], false) ? "Click to mark not required" : "Click to mark required");
- parentDiv.appendChild(img);
- //parentDiv.innerHTML += " <a class='zProjectLink' href='/mc-mods/" + currentFiles[i] + "'>" + (GM_getValue('fileName' + currentFiles[i]) == null ? "Unknown filename: (" + currentFiles[i] + ")" : GM_getValue('fileName' + currentFiles[i])) + "</a>";
- appendProjectLink(parentDiv, currentFiles[i]);
- }
- }
- $('span.infoSpan').click(infoSpanClicked);
- $('img.setRequired').click(imgSetRequired);
- $('img.removeFile').click(imgRemoveFile);
- $('#imgLoad').click(parseModPack);
- $('#imgDelete').click(deleteModPack);
- $('#imgGen').click(generateModPack);
- $('[data-qtip!=""]').qtip({
- content: {
- attr: 'data-qtip'
- },
- style: {
- classes: 'qtip-tipsy'
- },
- position: {
- target: 'mouse',
- adjust: {
- x: 10,
- y: 10
- }
- }
- });
- }
- function appendInfoSpan(parent, valName, text) {
- var tSpan = document.createElement("span");
- tSpan.setAttribute("class", "infoSpan");
- tSpan.setAttribute("data-qtip", "Set " + text);
- tSpan.setAttribute("id", valName);
- tSpan.innerHTML = "<br> " + text + ": " + (GM_getValue(valName) == null ? "Not set" : trun(GM_getValue(valName), 45));
- parent.appendChild(tSpan);
- //document.getElementById(valName).addEventListener('click', infoSpanClicked, true);
- }
- function appendText(parent, string, classes) {
- var tSpan = document.createElement("span");
- tSpan.setAttribute("class", classes);
- tSpan.innerHTML = string;
- parent.appendChild(tSpan);
- }
- function appendNewLine(parent) {
- parent.appendChild(document.createElement("br"));
- }
- function appendProjectLink(parent, currentFile) {
- //<a class='zProjectLink' href='/mc-mods/" + currentFiles[i] + "'>" + (GM_getValue('fileName' + currentFiles[i]) == null ? "Unknown filename: (" + currentFiles[i] + ")" : GM_getValue('fileName' + currentFiles[i])) + "</a>"
- var tSpan = document.createElement("a");
- tSpan.setAttribute("class", "zProjectLink");
- tSpan.setAttribute("href", '/mc-mods/' + currentFile);
- tSpan.innerHTML = (GM_getValue('fileName' + currentFile) == null ? "Unknown filename: (" + currentFile + ")" : GM_getValue('fileName' + currentFile));
- parent.appendChild(tSpan);
- }
- function trun(text, maxLength) {
- var ret = text;
- if (ret.length > maxLength) {
- ret = ret.substr(0,maxLength-3) + "...";
- }
- return ret;
- }
- function imgSetRequired(e) {
- switch(e.target.getAttribute("datareq")) {
- case "false":
- GM_setValue("required" + e.target.getAttribute("dataid"), true);
- break;
- case "true":
- GM_setValue("required" + e.target.getAttribute("dataid"), false);
- break;
- }
- updateSideBar();
- }
- function imgRemoveFile(e) {
- if (confirm('Are you sure you want to remove this file?')) {
- GM_deleteValue("required" + e.target.getAttribute("dataid"));
- GM_deleteValue("fileName" + e.target.getAttribute("dataid"));
- GM_deleteValue(e.target.getAttribute("dataid"));
- updateSideBar();
- }
- }
- function infoSpanClicked(e) {
- switch (e.target.id) {
- case "maniName":
- getPrompt('maniName', 'Insert Modpack Name:', false, '', true);
- break;
- case "maniVersion":
- getPrompt('maniVersion', 'Insert Version:', false, '', true);
- break;
- case "maniAuthor":
- getPrompt('maniAuthor', 'Insert Author:', false, '', true);
- break;
- case "maniDesc":
- getPrompt('maniDesc', 'Insert Modpack Description:', false, '', true);
- break;
- case "maniForge":
- getPrompt('maniForge', 'Insert Forge Version:', false, 'forge-10.13.2.1277', true);
- break;
- case "maniMinecraft":
- getPrompt('maniMinecraft', 'Insert Minecraft Version:', false, '1.7.10', true);
- break;
- }
- updateSideBar();
- }
- function getPrompt(varname, promptmsg, isBoolean, defaultAn, doSetVar) {
- if (GM_getValue(varname) != null) {
- defaultAn = GM_getValue(varname);
- }
- if (doSetVar) {
- if (isBoolean) {
- GM_setValue(varname, confirm(promptmsg));
- } else {
- GM_setValue(varname, prompt(promptmsg, defaultAn));
- }
- return GM_getValue(varname);
- } else {
- return isBoolean ? confirm(promptmsg) : prompt(promptmsg, defaultAn);
- }
- }
- function getValueOrPrompt(varname, promptmsg, isBoolean, defaultAn, doSetVar) {
- if (GM_getValue(varname) != null) {
- return GM_getValue(varname);
- } else {
- if (doSetVar) {
- if (isBoolean) {
- GM_setValue(varname, confirm(promptmsg));
- } else {
- GM_setValue(varname, prompt(promptmsg, defaultAn));
- }
- return GM_getValue(varname);
- } else {
- return isBoolean ? confirm(promptmsg) : prompt(promptmsg, defaultAn);
- }
- }
- }
- function deleteModPack() {
- if (confirm('You are about to delete the current modpack. Are you sure?')) {
- var currentFiles = GM_listValues();
- for (var i = 0; i < currentFiles.length; i++) {
- GM_deleteValue(currentFiles[i]);
- }
- updateSideBar();
- alert('Modpack Deleted');
- }
- }
- function addFile() {
- var curWorking = window.location.toString().split('mc-mods/') [1];
- var projectID = curWorking.substr(0, curWorking.indexOf('-'));
- var fileID = curWorking.substr(curWorking.lastIndexOf('/') + 1);
- if (fileID.indexOf("#") > -1) {
- fileID = fileID.substr(0, fileID.indexOf("#"));
- }
- if ((GM_getValue(projectID) != null && confirm('This project already has a file in the modpack, are you sure you want to overwrite it?')) || GM_getValue(projectID) == null) {
- if (confirm('Make this file required to run the modpack? (OK=Yes, Cancel=No)')) {
- GM_setValue('required' + projectID, true);
- } else {
- GM_setValue('required' + projectID, false);
- }
- GM_setValue(projectID, fileID);
- GM_setValue('fileName' + projectID, document.getElementsByClassName("overflow-tip")[1].innerText);
- updateSideBar();
- }
- }
- function generateModPack() {
- var filesList = '';
- var currentFiles = GM_listValues();
- for (var i = 0; i < currentFiles.length; i++) {
- if (!isNaN(currentFiles[i].charAt(0))) {
- console.log('Found mod: ' + currentFiles[i] + ' - Required: ' + GM_getValue('required' + currentFiles[i], false));
- if (filesList != '') {
- filesList += ',\n';
- }
- filesList += '\t\t{\n\t\t\t"projectID": ' + currentFiles[i] + ',\n\t\t\t"fileID": ' + GM_getValue(currentFiles[i]) + (GM_getValue('fileName' + currentFiles[i]) == null ? "" : ',\n\t\t\t"fileName": "' + GM_getValue('fileName' + currentFiles[i]) + '"') + (GM_getValue('required' + currentFiles[i], false) ? ',\n\t\t\t"required": true' : '') + '\n\t\t}';
- }
- }
- var man = manifest.replace('%name%', getValueOrPrompt('maniName', 'Insert Modpack Name:', false, '', true));
- man = man.replace('%version%', getValueOrPrompt('maniVersion', 'Insert Version:', false, '', true));
- man = man.replace('%author%', getValueOrPrompt('maniAuthor', 'Insert Author:', false, '', true));
- man = man.replace('%description%', getValueOrPrompt('maniDesc', 'Insert Modpack Description:', false, '', true));
- man = man.replace('%files%', filesList);
- man = man.replace('%mcversion%', getValueOrPrompt('maniMinecraft', 'Insert Minecraft Version:', false, '1.7.10', true));
- man = man.replace('%forgeversion%', getValueOrPrompt('maniForge', 'Insert Forge Version:', false, 'forge-10.13.2.1277', true));
- console.log('Manifest: ' + man);
- updateSideBar();
- //prompt("Your new manifest: (Ctrl+C to copy)", man);
- download("manifest.json", man);
- }
- function parseModPack() {
- var stuff = prompt("Paste in the manifest from a previous pack: ");
- if (stuff == null || stuff == '')
- return;
- try {
- var prevPack = JSON.parse(stuff);
- } catch (ex) {
- alert("That JSON is invalid!");
- return;
- }
- if (confirm('You are about to delete the current modpack. Are you sure?')) {
- var currentFiles = GM_listValues();
- for (var i = 0; i < currentFiles.length; i++) {
- GM_deleteValue(currentFiles[i]);
- }
- } else {
- return;
- }
- var fileCount = 0;
- console.log("Starting file process");
- for (var i = 0; i < prevPack.files.length; i++) {
- if (prevPack.files[i] != null && prevPack.files[i].projectID != null) {
- fileCount++;
- GM_setValue(prevPack.files[i].projectID, prevPack.files[i].fileID);
- if (prevPack.files[i].required != null) {
- GM_setValue("required" + prevPack.files[i].projectID, prevPack.files[i].required);
- } else {
- GM_setValue("required" + prevPack.files[i].projectID, false);
- }
- if (prevPack.files[i].fileName != null) {
- GM_setValue("fileName" + prevPack.files[i].projectID, prevPack.files[i].fileName);
- }
- }
- }
- console.log("Files done");
- setIfDefined("maniName", prevPack.name);
- setIfDefined('maniVersion', prevPack.version);
- setIfDefined('maniAuthor', prevPack.author);
- setIfDefined('maniDesc', prevPack.description);
- setIfDefined('maniMinecraft', prevPack.minecraft == null ? null : prevPack.minecraft.version);
- setIfDefined('maniForge', prevPack.minecraft == null ? null : prevPack.minecraft.modLoaders == null ? null : prevPack.minecraft.modLoaders[0].id);
- updateSideBar();
- alert("Pack Loaded.\nName: " + GM_getValue('maniName') + "\nAuthor: " + GM_getValue('maniAuthor') + "\nPack Version: " + GM_getValue('maniVersion') + "\nDescription: " + GM_getValue('maniDesc') + "\nMinecraft Version: " + GM_getValue('maniMinecraft') + "\nForge Version: " + GM_getValue('maniForge') + "\nFound " + fileCount + " files.");
- }
- function setIfDefined(varName, toSave) {
- if (toSave != null) {
- GM_setValue(varName, toSave);
- }
- }
- function download(filename, text) {
- var pom = document.createElement('a');
- console.log("Saving: " + text);
- pom.setAttribute('href', 'data:application/json;charset=utf-8,' + encodeURIComponent(text));
- pom.setAttribute('download', filename);
- pom.click();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement