// ==UserScript== // @name Nexus Mods - Stardew Valley - Download Mod Faster - Improved UX // @namespace https://bitbucket.org/antonolsson91/nexus-mods-stardew-valley-improved-ux/ // @version 1.0.2 // @tags nexusmods.com, nexusmods, stardew valley, stardewvalley, stardew valley mods, sdv mods, stv mods, improved ux // @description Improves the user experience for nexusmods.com visitors by adding Insta-DL buttons in various places like |1) categories mod tiles |2) mod description/file page // @author Anton Olsson // @authoremail eagleenterprises08+nexusmods@gmail.com // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html // @editURL https://gitpod.io/#https://bitbucket.org/antonolsson91/nexus-mods-stardew-valley-improved-ux/src/master/ // @include https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js // @match https://www.nexusmods.com/stardewvalley/* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/421906/Nexus%20Mods%20-%20Stardew%20Valley%20-%20Download%20Mod%20Faster%20-%20Improved%20UX.user.js // @updateURL https://update.greasyfork.icu/scripts/421906/Nexus%20Mods%20-%20Stardew%20Valley%20-%20Download%20Mod%20Faster%20-%20Improved%20UX.meta.js // ==/UserScript== (($) => { let DMF = { STVGameId: 1303, startDownload: function (file_id, game_id, btn) { console.log(`Called startDownload(${file_id},${game_id}, ${btn})`) $.ajax( { type: "POST", url: "/Core/Libs/Common/Managers/Downloads?GenerateDownloadUrl", data: { fid: file_id, game_id: game_id, }, success: function (data, error) { if (data && data.url) { console.log('Success'); //window.location.href = data.url; window.open(data.url) btn.attr("disabled", "true").append(`✅`) $('.donation-wrapper > p').html('

Your download has started

If you are having trouble, click here to download manually

'); } else { console.trace("Error posting:", error); } }, error: function (e) { console.trace(e); } } ); }, loader: function(){ return $(` `) }, initiateDownload: function ( btn_manualDl ) { console.log("initiateDownload got", btn_manualDl, $(btn_manualDl).attr("href"), $(btn_manualDl).prop("tagName")) let linkParamString = $(btn_manualDl).prop("tagName").toLowerCase() == "a" ? $(btn_manualDl).attr("href").split("?")[1] : $(btn_manualDl).find('a').attr("href").split("?")[1] let searchParams = new URLSearchParams(linkParamString) let id = searchParams.has('file_id') ? searchParams.get('file_id') : searchParams.get('id'); if( !id ) return false; this.startDownload(id, this.STVGameId, btn_manualDl); }, btn: function(){ let btn = $(``) btn.on("click", async (event) => { event.preventDefault() let btn_manualDl; if(document.location.href.includes("nexusmods.com/stardewvalley/mods/categories/")){ let current = $(event.target).parents('.mod-tile'); let modUrl = current.find('h3 a').attr('href') let loader = this.loader() loader.appendTo(current.parent()) await $.get(modUrl, source => { loader.hide() btn_manualDl = $(`
${source}
`).find('#action-manual'); initiateDownload(btn_manualDl) }); } else { let $this = $( event.target ) btn_manualDl = $this.data('button') ? $this.data('button')[0] : $('#action-manual') } this.initiateDownload(btn_manualDl) }) return btn; }, main: function(){ if(document.location.href.includes("nexusmods.com/stardewvalley/mods/categories/")){ $('.mod-tile').each( (i, e) => { $(e).find(".tile-data ul").append( $(`
  • `).append( this.btn() ) ) } ); } else { // Header, download latest file $('#action-manual').parent().append(this.btn()) // Files tab $(`.tabcontent-mod-page a.btn.inline-flex`).each((i, e) => { let p = $(e).parent() if($(e).html().includes("Manual download")){ p.append(this.btn().data('button', $(e))) } }) } } } window.DMF = DMF; window.DMF.main(); })(jQuery);