1. // ==UserScript==
  2. // @name Blob fake for Mega hosting
  3. // @include http://mega.co.nz*
  4. // @include https://mega.co.nz*
  5. // @comment This script works in conjunction with custom UserAgent string
  6. // ==/UserScript==
  7. /*
  8. .:HOW TO USE:.
  9. 0. Save this file to your userscripts folder with name like "megafix.js"
  10. 1. Add this to %appdata%/Opera/override.ini:
  11. [Overrides]
  12. mega.co.nz
  13. [mega.co.nz]
  14. User Prefs|Custom User-Agent=Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0
  15. 2. Go to a mega download page and copy file name to clipboard.
  16. 3. Press download and wait until it is complete.
  17. 4. Press "Save as" and paste the filename.
  18. .:OR:.
  19. 1. Update your browser. x_X
  20. */
  21. (function(){
  22. var style = document.createElement('style');style.type = 'text/css';style.textContent = 'div[class^="ads-"],#ind_db,.st-main-bottom{display:none}';document.getElementsByTagName('head')[0].appendChild(style);
  23. window.localStorage['dlMethod'] = 'MemoryIO';
  24. /* Blob.js
  25. * A Blob implementation.
  26. * 2014-07-24
  27. *
  28. * By Eli Grey, http://eligrey.com
  29. * By Devin Samarin, https://github.com/eboyjr
  30. * License: X11/MIT
  31. * See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
  32. */
  33. (function (view) {
  34. "use strict";
  35. view.URL = view.URL || view.webkitURL;
  36. if (view.Blob && view.URL) {
  37. try {
  38. new Blob;
  39. return;
  40. } catch (e) {}
  41. }
  42. // Internally we use a BlobBuilder implementation to base Blob off of
  43. // in order to support older browsers that only have BlobBuilder
  44. var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function (view) {
  45. var get_class = function (object) {
  46. return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
  47. },
  48. FakeBlobBuilder = function BlobBuilder() {
  49. this.data = [];
  50. },
  51. FakeBlob = function Blob(data, type, encoding) {
  52. this.data = data;
  53. this.size = data.length;
  54. this.type = type;
  55. this.encoding = encoding;
  56. },
  57. FBB_proto = FakeBlobBuilder.prototype,
  58. FB_proto = FakeBlob.prototype,
  59. FileReaderSync = view.FileReaderSync,
  60. FileException = function (type) {
  61. this.code = this[this.name = type];
  62. },
  63. file_ex_codes = ("NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR " + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR").split(" "),
  64. file_ex_code = file_ex_codes.length,
  65. real_URL = view.URL || view.webkitURL || view,
  66. real_create_object_URL = real_URL.createObjectURL,
  67. real_revoke_object_URL = real_URL.revokeObjectURL,
  68. URL = real_URL,
  69. btoa = view.btoa,
  70. atob = view.atob,
  71. ArrayBuffer = view.ArrayBuffer,
  72. Uint8Array = view.Uint8Array,
  73. origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/;
  74. FakeBlob.fake = FB_proto.fake = true;
  75. while (file_ex_code--) {
  76. FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
  77. }
  78. // Polyfill URL
  79. if (!real_URL.createObjectURL) {
  80. URL = view.URL = function (uri) {
  81. var uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a"),
  82. uri_origin;
  83. uri_info.href = uri;
  84. if (!("origin" in uri_info)) {
  85. if (uri_info.protocol.toLowerCase() === "data:") {
  86. uri_info.origin = null;
  87. } else {
  88. uri_origin = uri.match(origin);
  89. uri_info.origin = uri_origin && uri_origin[1];
  90. }
  91. }
  92. return uri_info;
  93. };
  94. }
  95. URL.createObjectURL = function (blob) {
  96. var type = blob.type,
  97. data_URI_header;
  98. if (type === null || type === "") {
  99. type = "application/octet-stream";
  100. }
  101. if (blob instanceof FakeBlob) {
  102. data_URI_header = "data:" + type;
  103. if (blob.encoding === "base64") {
  104. return data_URI_header + ";base64," + blob.data;
  105. } else if (blob.encoding === "URI") {
  106. return data_URI_header + "," + decodeURIComponent(blob.data);
  107. }
  108. if (btoa) {
  109. return data_URI_header + ";base64," + btoa(blob.data);
  110. } else {
  111. return data_URI_header + "," + encodeURIComponent(blob.data);
  112. }
  113. } else if (real_create_object_URL) {
  114. return real_create_object_URL.call(real_URL, blob);
  115. }
  116. };
  117. URL.revokeObjectURL = function (object_URL) {
  118. if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
  119. real_revoke_object_URL.call(real_URL, object_URL);
  120. }
  121. };
  122. FBB_proto.append = function (data /*, endings*/ ) {
  123. var bb = this.data;
  124. // decode data to a binary string
  125. if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
  126. var str = "",
  127. buf = new Uint8Array(data),
  128. i = 0,
  129. buf_len = buf.length;
  130. for (; i < buf_len; i++) {
  131. str += String.fromCharCode(buf[i]);
  132. }
  133. bb.push(str);
  134. } else if (get_class(data) === "Blob" || get_class(data) === "File") {
  135. if (FileReaderSync) {
  136. var fr = new FileReaderSync;
  137. bb.push(fr.readAsBinaryString(data));
  138. } else {
  139. // async FileReader won't work as BlobBuilder is sync
  140. throw new FileException("NOT_READABLE_ERR");
  141. }
  142. } else if (data instanceof FakeBlob) {
  143. if (data.encoding === "base64" && atob) {
  144. bb.push(atob(data.data));
  145. } else if (data.encoding === "URI") {
  146. bb.push(decodeURIComponent(data.data));
  147. } else if (data.encoding === "raw") {
  148. bb.push(data.data);
  149. }
  150. } else {
  151. if (typeof data !== "string") {
  152. data += ""; // convert unsupported types to strings
  153. }
  154. // decode UTF-16 to binary string
  155. bb.push(unescape(encodeURIComponent(data)));
  156. }
  157. };
  158. FBB_proto.getBlob = function (type) {
  159. if (!arguments.length) {
  160. type = null;
  161. }
  162. return new FakeBlob(this.data.join(""), type, "raw");
  163. };
  164. FBB_proto.toString = function () {
  165. return "[object BlobBuilder]";
  166. };
  167. FB_proto.slice = function (start, end, type) {
  168. var args = arguments.length;
  169. if (args < 3) {
  170. type = null;
  171. }
  172. return new FakeBlob(
  173. this.data.slice(start, args > 1 ? end : this.data.length), type, this.encoding);
  174. };
  175. FB_proto.toString = function () {
  176. return "[object Blob]";
  177. };
  178. FB_proto.close = function () {
  179. this.size = 0;
  180. delete this.data;
  181. };
  182. return FakeBlobBuilder;
  183. }(view));
  184. view.Blob = function (blobParts, options) {
  185. var type = options ? (options.type || "") : "";
  186. var builder = new BlobBuilder();
  187. if (blobParts) {
  188. for (var i = 0, len = blobParts.length; i < len; i++) {
  189. builder.append(blobParts[i]);
  190. }
  191. }
  192. return builder.getBlob(type);
  193. };
  194. }(window));
  195. })();