Igneez

Automatic Nexus Mod Downloader- 1

May 23rd, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Automated Nexus Mod Downloader - 1
  3. // @version      1
  4. // @description  Downloads mods from a list sequentially with timeouts in between each download
  5. // @author       Igneez
  6. // @match        https://www.nexusmods.com/skyrim
  7. // @grant        none
  8. // @run-at       document-end
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.   "use strict";
  13.  
  14.   let smallDownloadIDs = [
  15.     ["3863", "0", "Sky UI"],    
  16.     ["11811", "0", "FNIS"],  
  17.     ["29624", "0", "Racemenu"],
  18.     ["53996", "0", "HDT PE "],
  19.     ["36213", "0", "HDT HighHeels"],
  20.     ["68000", "0", "XP32"],
  21.    
  22.     ["9557", "0", "Alternate Start"],
  23.     ["57046", "0", "UIExtensions"],
  24.     ["64905", "0", "AddItemMenu"],
  25.     ["14884", "0", "Silent Voice"],
  26.     ["27371", "0", "Better Dialogue Controls"],
  27.     ["28170", "0", "Better MessageBox Controls"],
  28.     ["58705", "0", "PapyrusUtil"],
  29.     ["95017", "0", "PaprusExtender"],  
  30.     ["75795", "0", "SKSE Preloader"],
  31.     ["72725", "0", "Crash Fixes"],  
  32.     ["76747", "0", "Bug Fixes"],  
  33.     ["96734", "0", "Cobb Bug Fixes"],
  34.     ["85443", "0", "Load Game CTD Fix"],
  35.     ["40706", "0", "OneTweak"],
  36.    
  37.     ["49743", "0", "JContainers"],
  38.     ["10753", "0", "Auto Unequip Ammo"],
  39.     ["66257", "0", "ConsoleUtil"],
  40.   ];
  41.  
  42.  
  43.   let largeDownloadIDs = [
  44.     ["2666", "0", "CBBE"],
  45.     ["71214", "0", "Unofficial Skyrim Patch"],
  46.     ["49015", "0", "Bodyslide"],
  47.   ];
  48.  
  49.   let smallLowerBound = 10000;
  50.   let smallUpperBound = 16000;
  51.   let largeLowerBound = 30000;
  52.   let largeUpperBound = 60000;
  53.  
  54.   //HTML Elements & CSS Declaration
  55.  
  56.   let myEle = {
  57.     main: $("<div id='autoDownloaderContent'></div>"),
  58.     modList: $("<div id='myModList'></div>"),
  59.     smallModList: $("<ul id='mySmallModList'></ul>"),
  60.     largeModList: $("<ul id='myLargeModList'></ul>"),
  61.     smallModListTitle: $("<div id='mySmallModListTitle'>Small Mod List</div>"),
  62.     largeModListTitle: $("<ul id='myLargeModListTitle'>Large Mod List</ul>"),
  63.   };
  64.  
  65.   let myBtns = {
  66.     smallDownloads: $("<button>", {
  67.       text: "Small Downloads",
  68.       click: function () { initDownload(smallDownloadIDs, getRndInteger(smallLowerBound, smallUpperBound)) },
  69.       id: "smallDownloadBtn",
  70.       class: "btn"
  71.     }),
  72.     largeDownloads: $("<button>", {
  73.       text: "Large Downloads",
  74.       click: function () { initDownload(largeDownloadIDs, getRndInteger(largeLowerBound, largeUpperBound)) },
  75.       id: "largeDownloadBtn",
  76.       class: "btn"
  77.     }),
  78.     showModList: $("<button>", {
  79.       text: "Show/Hide Mod List",
  80.       click: function() {
  81.         myEle.modList.toggle();
  82.         myEle.smallModList.toggle();
  83.         myEle.largeModList.toggle();
  84.       },
  85.       id: "showModListBtn",
  86.       class: "btn"
  87.     })
  88.   };
  89.  
  90.   let myCSS = {
  91.     modList: {
  92.       "display": "none",
  93.       "list-style": "none",
  94.       "column-count": "3",
  95.       "margin": "0.5rem 0"
  96.     },
  97.     title: {
  98.       "color": "white",
  99.       "font-weight": "800",
  100.       "margin-top": "0.5rem"
  101.     }
  102.   };
  103.  
  104.  
  105.   myEle.modList.css("display", "none");
  106.   myEle.smallModListTitle.css(myCSS.title);
  107.   myEle.largeModListTitle.css(myCSS.title);
  108.   myEle.smallModList.css(myCSS.modList);
  109.   myEle.largeModList.css(myCSS.modList);
  110.  
  111.   myBtns.smallDownloads.css("margin", "0 0.5rem");
  112.   myBtns.largeDownloads.css("margin", "0 0.5rem");
  113.   myBtns.showModList.css("margin", "0 0.5rem");
  114.    
  115.   window.onload = init
  116.  
  117.   function init() {        
  118.     myEle.smallModList = createModList(smallDownloadIDs, myEle.smallModList);
  119.     myEle.largeModList = createModList(largeDownloadIDs, myEle.largeModList);
  120.    
  121.     myEle.modList.append([myEle.smallModListTitle, myEle.smallModList, myEle.largeModListTitle, myEle.largeModList]);
  122.     myEle.main.append([myBtns.smallDownloads, myBtns.largeDownloads, myBtns.showModList, myEle.modList]);
  123.        
  124.     $("#mainContent").prepend(myEle.main);
  125.  
  126.   }
  127.  
  128.   async function initDownload(list, time) {
  129.     for (let i = 0; i < list.length; i++) {
  130.      
  131.       localStorage.setItem("downloadIt", "1");
  132.       localStorage.setItem("fileIndex", list[i][1]);
  133.      
  134.       window.open(`https://www.nexusmods.com/skyrim/mods/${list[i][0]}?tab=files`, "_blank");
  135.      
  136.       $(`#${list[i][0]}`).css("color", "green");
  137.        
  138.       await timer(time);
  139.     }
  140.   }
  141.  
  142.   function createModList(list, listElement) {
  143.     for (let i = 0; i < list.length; i++) {
  144.       let item = $(`<li id="${list[i][0]}">${list[i][2]} - ${list[i][0]}</li>`);
  145.  
  146.       item.click(function () {
  147.         localStorage.setItem("downloadIt", "1");
  148.         localStorage.setItem("fileIndex", list[i][1]);
  149.  
  150.         window.open(`https://www.nexusmods.com/skyrim/mods/${list[i][0]}?tab=files`, "_blank");
  151.       });
  152.  
  153.       item.css({
  154.         "color": "white",
  155.         "font-weight": "600",
  156.         "font-size": "0.8rem"
  157.       });
  158.  
  159.       listElement.append(item);
  160.     }
  161.    
  162.     return listElement;
  163.   }
  164.  
  165.   const timer = ms => new Promise(res => setTimeout(res, ms));
  166.   const getRndInteger = (min, max) => Math.floor(Math.random() * (max - min)) + min;
  167. })();
Advertisement
Add Comment
Please, Sign In to add comment