coofoUtils-tampermonkeyUtils

tampermonkeyUtils扩展包

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/453330/1541594/coofoUtils-tampermonkeyUtils.js

  1. // ==UserScript==
  2. // @name coofoUtils-tampermonkeyUtils
  3. // @namespace https://github.com/coofo/someScript
  4. // @version 0.0.2
  5. // @license MIT License
  6. // @description tampermonkeyUtils扩展包
  7. // @author coofo
  8. // @downloadURL https://github.com/coofo/someScript/raw/main/tampermonkey/coofoUtils-tampermonkeyUtils.user.js
  9. // @supportURL https://github.com/coofo/someScript/issues
  10. // @grant GM_download
  11. // @grant GM_xmlhttpRequest
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. window.coofoUtils.tampermonkeyUtils = {
  17. downloadHelp: {
  18. toBlob: {
  19. asBlob: function (url, onSuccess) {
  20. GM_xmlhttpRequest({
  21. method: "GET",
  22. url: url,
  23. nocache: true,
  24. responseType: "arraybuffer",
  25. onload: function (responseDetails) {
  26. onSuccess(responseDetails);
  27. }
  28. });
  29. }
  30. },
  31. toUser: {
  32. asGMdownload: function (url, fileName, setting) {
  33. let details;
  34. if (typeof setting === "object" && typeof setting.gmDownload === "object") {
  35. details = setting.gmDownload;
  36. } else {
  37. details = {saveAs: false};
  38. }
  39. details.url = url;
  40. details.name = fileName;
  41. // console.log(details.url);
  42. // console.log(details.name);
  43. GM_download(details);
  44. }
  45. }
  46. }
  47. };
  48. })();