FileSaver

自用

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/498746/1399668/FileSaver.js

  1. (function (a, b) {
  2. if ("function" == typeof define && define.amd) define([], b);
  3. else if ("undefined" != typeof exports) b();
  4. else {
  5. b(), (a.FileSaver = { exports: {} }.exports);
  6. }
  7. })(this, function () {
  8. "use strict";
  9. function b(a, b) {
  10. return (
  11. "undefined" == typeof b
  12. ? (b = { autoBom: !1 })
  13. : "object" != typeof b &&
  14. (console.warn("Deprecated: Expected third argument to be a object"),
  15. (b = { autoBom: !b })),
  16. b.autoBom &&
  17. /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(
  18. a.type
  19. )
  20. ? new Blob(["\uFEFF", a], { type: a.type })
  21. : a
  22. );
  23. }
  24. function c(a, b, c) {
  25. var d = new XMLHttpRequest();
  26. d.open("GET", a),
  27. (d.responseType = "blob"),
  28. (d.onload = function () {
  29. g(d.response, b, c);
  30. }),
  31. (d.onerror = function () {
  32. console.error("could not download file");
  33. }),
  34. d.send();
  35. }
  36. function d(a) {
  37. var b = new XMLHttpRequest();
  38. b.open("HEAD", a, !1);
  39. try {
  40. b.send();
  41. } catch (a) {}
  42. return 200 <= b.status && 299 >= b.status;
  43. }
  44. function e(a) {
  45. try {
  46. a.dispatchEvent(new MouseEvent("click"));
  47. } catch (c) {
  48. var b = document.createEvent("MouseEvents");
  49. b.initMouseEvent(
  50. "click",
  51. !0,
  52. !0,
  53. window,
  54. 0,
  55. 0,
  56. 0,
  57. 80,
  58. 20,
  59. !1,
  60. !1,
  61. !1,
  62. !1,
  63. 0,
  64. null
  65. ),
  66. a.dispatchEvent(b);
  67. }
  68. }
  69. var f =
  70. "object" == typeof window && window.window === window
  71. ? window
  72. : "object" == typeof self && self.self === self
  73. ? self
  74. : "object" == typeof global && global.global === global
  75. ? global
  76. : void 0,
  77. a =
  78. f.navigator &&
  79. /Macintosh/.test(navigator.userAgent) &&
  80. /AppleWebKit/.test(navigator.userAgent) &&
  81. !/Safari/.test(navigator.userAgent),
  82. g =
  83. f.saveAs ||
  84. ("object" != typeof window || window !== f
  85. ? function () {}
  86. : "download" in HTMLAnchorElement.prototype && !a
  87. ? function (b, g, h) {
  88. var i = f.URL || f.webkitURL,
  89. j = document.createElement("a");
  90. (g = g || b.name || "download"),
  91. (j.download = g),
  92. (j.rel = "noopener"),
  93. "string" == typeof b
  94. ? ((j.href = b),
  95. j.origin === location.origin
  96. ? e(j)
  97. : d(j.href)
  98. ? c(b, g, h)
  99. : e(j, (j.target = "_blank")))
  100. : ((j.href = i.createObjectURL(b)),
  101. setTimeout(function () {
  102. i.revokeObjectURL(j.href);
  103. }, 4e4),
  104. setTimeout(function () {
  105. e(j);
  106. }, 0));
  107. }
  108. : "msSaveOrOpenBlob" in navigator
  109. ? function (f, g, h) {
  110. if (((g = g || f.name || "download"), "string" != typeof f))
  111. navigator.msSaveOrOpenBlob(b(f, h), g);
  112. else if (d(f)) c(f, g, h);
  113. else {
  114. var i = document.createElement("a");
  115. (i.href = f),
  116. (i.target = "_blank"),
  117. setTimeout(function () {
  118. e(i);
  119. });
  120. }
  121. }
  122. : function (b, d, e, g) {
  123. if (
  124. ((g = g || open("", "_blank")),
  125. g &&
  126. (g.document.title = g.document.body.innerText =
  127. "downloading..."),
  128. "string" == typeof b)
  129. )
  130. return c(b, d, e);
  131. var h = "application/octet-stream" === b.type,
  132. i = /constructor/i.test(f.HTMLElement) || f.safari,
  133. j = /CriOS\/[\d]+/.test(navigator.userAgent);
  134. if ((j || (h && i) || a) && "undefined" != typeof FileReader) {
  135. var k = new FileReader();
  136. (k.onloadend = function () {
  137. var a = k.result;
  138. (a = j
  139. ? a
  140. : a.replace(/^data:[^;]*;/, "data:attachment/file;")),
  141. g ? (g.location.href = a) : (location = a),
  142. (g = null);
  143. }),
  144. k.readAsDataURL(b);
  145. } else {
  146. var l = f.URL || f.webkitURL,
  147. m = l.createObjectURL(b);
  148. g ? (g.location = m) : (location.href = m),
  149. (g = null),
  150. setTimeout(function () {
  151. l.revokeObjectURL(m);
  152. }, 4e4);
  153. }
  154. });
  155. (f.saveAs = g.saveAs = g),
  156. "undefined" != typeof module && (module.exports = g);
  157. });
  158.  
  159. //# sourceMappingURL=FileSaver.min.js.map

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址