// ==UserScript== // @name Nexus Mods - Download Mod Faster - Improved UX (All Games) // @namespace https://bitbucket.org/antonolsson91/nexus-mods-stardew-valley-improved-ux/ // @version 1.6 // @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, TetteDev // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js // @match https://www.nexusmods.com/*/* // @grant none // @noframes // @downloadURL none // ==/UserScript== (($) => { const resolveGameId = () => { try { return parseInt(Object.keys(window.GlobalModStats)[0]); } catch (err) { debugger; console.error("Could not derive the current game id, please inform the author of this script!", err); return -1; } }; let DMF = { STVGameId: resolveGameId(), 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) { id = new URLSearchParams(window.location.href).get("file_id"); if (!id) return false; } this.startDownload(id, this.STVGameId, btn_manualDl); }, btn: function(){ this.btn_extended(); let btn = $(``) btn.on("click", async (event) => { event.preventDefault() let btn_manualDl; if(document.location.href.includes("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; }, btn_extended: function() { if (document.querySelector("#bypassFastDownloadButton")) return; let btn = document.createElement("td"); btn.innerHTML = ``; btn.onclick = async (event) => { event.preventDefault() let btn_manualDl; if(document.location.href.includes("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) }; try { const insertionNode = (document.querySelector("#slowDownloadButton") || document.querySelector("#fastDownloadButton")).parentNode.parentNode; if (!insertionNode) { console.warn("Could not add fast-download button next to the existing download buttons!"); return; } insertionNode.appendChild(btn); } catch (err) { } }, main: function(){ // TODO: make this check better in the future if (!window.location.pathname.includes("/mods/") || window.location.pathname.includes("categories")) return; if (window.DMF.STVGameId == -1) { return; } const isLoggedIn = window["USER_ID"] !== undefined; if (!isLoggedIn) return; let dl = document.querySelector("#slowDownloadButton"); if (dl) { dl.removeAttribute("data-download-url"); dl.onclick = () => { let dlButton = document.querySelector(".rj-vortex-button"); if (!dlButton) { this.btn(); dlButton = document.querySelector(".rj-vortex-button"); if (!dlButton) { alert("Please use the Insta-Download button instead"); return; } } dlButton.click(); }; } if(document.location.href.includes("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))) } }) } } } try { window.DMF = DMF; window.DMF.main(); } catch (error) { debugger; console.error("Please disable the 'Nexus Mods - Download Mod Faster' userscript as it failed!", error) alert("Please disable the 'Nexus Mods - Download Mod Faster' userscript as it failed!"); } })(jQuery);