// ==UserScript== // @name GM_DL // @namespace Violentmonkey Scripts // @grant GM.xmlHttpRequest // @version 1.2 // @author https://greasyfork.org/en/users/1409235-paywalldespiser // @description GM_download but it actually works // @license MIT // @require https://cdn.jsdelivr.net/npm/file-saver@2.0.5/dist/FileSaver.min.js // ==/UserScript== /** * GM_download but it actually works * * @param {{ url: string | URL; data?: string; headers?: { [key: string]: string }; redirect?: 'follow' | 'error' | 'manual' = ['follow']; filename: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS' | 'CONNECT' = ['GET']; }} * @returns {Promise} */ function GM_DL({ url, filename, method = 'GET', redirect, data, headers }) { return GM.xmlHttpRequest({ url, method, responseType: 'blob', redirect, data, headers, }).then(({ response }) => saveAs(response, filename)); }