ModuleRaid with unsafeWindow

This is build 5.1.2 of pixeldesu's moduleraid, patched to target unsafeWindow to work consistently within userscripts

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/470991/1221077/ModuleRaid%20with%20unsafeWindow.js

  1. // ==UserScript==
  2. // @name ModuleRaid with unsafeWindow
  3. // @namespace Itsnotlupus Industries
  4. // @version 5.1.2
  5. // @description This is build 5.1.2 of pixeldesu's moduleraid, patched to target unsafeWindow to work consistently within userscripts
  6. // @author pixeldesu
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10.  
  11. // source: https://unpkg.com/moduleraid@5.1.2/dist/moduleraid.umd.js
  12. // tweak: s/window/unsafeWindow/g
  13.  
  14. ! function(t, e) {
  15. "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t || self).moduleraid = e()
  16. }(this, function() {
  17. function t() {
  18. return (t = Object.assign || function(t) {
  19. for (var e = 1; e < arguments.length; e++) {
  20. var o = arguments[e];
  21. for (var n in o) Object.prototype.hasOwnProperty.call(o, n) && (t[n] = o[n])
  22. }
  23. return t
  24. }).apply(this, arguments)
  25. }
  26. return function() {
  27. function e(e) {
  28. var o, n = this;
  29. this.entrypoint = void 0, this.debug = void 0, this.moduleID = Math.random().toString(36).substring(7), this.functionArguments = [
  30. [
  31. [0],
  32. [function(t, e, o) {
  33. var r = o.c;
  34. Object.keys(r).forEach(function(t) {
  35. n.modules[t] = r[t].exports
  36. }), n.constructors = o.m, n.get = o
  37. }]
  38. ],
  39. [
  40. [1e3], (o = {}, o[this.moduleID] = function(t, e, o) {
  41. var r = o.c;
  42. Object.keys(r).forEach(function(t) {
  43. n.modules[t] = r[t].exports
  44. }), n.constructors = o.m, n.get = o
  45. }, o), [
  46. [this.moduleID]
  47. ]
  48. ]
  49. ], this.arrayArguments = [this.functionArguments[1],
  50. [
  51. [this.moduleID], {},
  52. function(t) {
  53. Object.keys(t.m).forEach(function(e) {
  54. try {
  55. n.modules[e] = t(e)
  56. } catch (t) {
  57. n.log("[arrayArguments/1] Failed to require(" + e + ") with error:\n" + t + "\n" + t.stack)
  58. }
  59. }), n.get = t
  60. }
  61. ]
  62. ], this.modules = {}, this.constructors = [], this.get = null;
  63. var r = {
  64. entrypoint: "webpackJsonp",
  65. debug: !1
  66. };
  67. "object" == typeof e ? r = t({}, r, e) : "boolean" == typeof e && (console.warn("[moduleRaid] Using a single boolean argument is deprecated, please use 'new ModuleRaid({ debug: true })'"), r.debug = e), this.entrypoint = r.entrypoint, this.debug = r.debug, this.fillModules(), this.replaceGet()
  68. }
  69. var o = e.prototype;
  70. return o.log = function(t) {
  71. this.debug && console.warn("[moduleRaid] " + t)
  72. }, o.replaceGet = function() {
  73. var t = this;
  74. null === this.get && (this.get = function(e) {
  75. return t.modules[e]
  76. })
  77. }, o.fillModules = function() {
  78. var t = this;
  79. if ("function" == typeof webpackJsonp ? this.functionArguments.forEach(function(e, o) {
  80. try {
  81. var n;
  82. (n = unsafeWindow)[t.entrypoint].apply(n, e)
  83. } catch (e) {
  84. t.log("moduleRaid.functionArguments[" + o + "] failed:\n" + e + "\n" + e.stack)
  85. }
  86. }) : this.arrayArguments.forEach(function(e, o) {
  87. try {
  88. if (unsafeWindow[t.entrypoint].push(e), t.modules && Object.keys(t.modules).length > 0) return
  89. } catch (e) {
  90. t.log("Pushing moduleRaid.arrayArguments[" + o + "] into " + t.entrypoint + " failed:\n" + e + "\n" + e.stack)
  91. }
  92. }), this.modules && 0 == Object.keys(this.modules).length) {
  93. var e = !1,
  94. o = 0;
  95. if (!unsafeWindow[this.entrypoint]([], [], [o])) throw Error("Unknown Webpack structure");
  96. for (; !e;) try {
  97. this.modules[o] = unsafeWindow[this.entrypoint]([], [], [o]), o++
  98. } catch (t) {
  99. e = !0
  100. }
  101. }
  102. }, o.findModule = function(t) {
  103. var e = this,
  104. o = [],
  105. n = Object.keys(this.modules);
  106. if (0 === n.length) throw new Error("There are no modules to search through!");
  107. return n.forEach(function(n) {
  108. var r = e.modules[n];
  109. try {
  110. if ("string" == typeof t) switch (t = t.toLowerCase(), typeof r) {
  111. case "string":
  112. r.includes(t) && o.push(r);
  113. break;
  114. case "function":
  115. r.toString().toLowerCase().includes(t) && o.push(r);
  116. break;
  117. case "object":
  118. if ("object" == typeof r.default)
  119. for (n in r.default) n.toLowerCase() === t && o.push(r);
  120. for (n in r) n.toLowerCase() === t && o.push(r)
  121. } else {
  122. if ("function" != typeof t) throw new TypeError("findModule can only find via string and function, " + typeof t + " was passed");
  123. t(r) && o.push(r)
  124. }
  125. } catch (t) {
  126. e.log("There was an error while searching through module '" + n + "':\n" + t + "\n" + t.stack)
  127. }
  128. }), o
  129. }, o.findConstructor = function(t) {
  130. var e = this,
  131. o = [],
  132. n = Object.keys(this.constructors);
  133. if (0 === n.length) throw new Error("There are no constructors to search through!");
  134. return n.forEach(function(n) {
  135. var r = e.constructors[n];
  136. try {
  137. "string" == typeof t ? (t = t.toLowerCase(), r.toString().toLowerCase().includes(t) && o.push([e.constructors[n], e.modules[n]])) : "function" == typeof t && t(r) && o.push([e.constructors[n], e.modules[n]])
  138. } catch (t) {
  139. e.log("There was an error while searching through constructor '" + n + "':\n" + t + "\n" + t.stack)
  140. }
  141. }), o
  142. }, e
  143. }()
  144. });