Webpack Hacks

__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED

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

  1. // ==UserScript==
  2. // @name Webpack Hacks
  3. // @namespace xuyiming.open@outlook.com
  4. // @description __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
  5. // @author xymopen
  6. // @version 1.0.0
  7. // @grant none
  8. // @license BSD-3-Clause
  9. // ==/UserScript==
  10.  
  11. const WebpackHacks = {
  12. RequireProperties: Object.freeze({
  13. /** the bundle public path */
  14. publicPath: "p",
  15.  
  16. /** the module id of the entry point */
  17. entryModuleId: "s",
  18.  
  19. /** the module cache */
  20. moduleCache: "c",
  21.  
  22. /** the module functions */
  23. moduleFactories: "m",
  24.  
  25. /** the chunk ensure function */
  26. ensureChunk: "e",
  27.  
  28. /** an object with handlers to ensure a chunk */
  29. ensureChunkHandlers: "f",
  30.  
  31. /** the chunk prefetch function */
  32. prefetchChunk: "E",
  33.  
  34. /** an object with handlers to prefetch a chunk */
  35. prefetchChunkHandlers: "F",
  36.  
  37. /** the chunk preload function */
  38. preloadChunk: "G",
  39.  
  40. /** an object with handlers to preload a chunk */
  41. preloadChunkHandlers: "H",
  42.  
  43. /** the exported property define getters function */
  44. definePropertyGetters: "d",
  45.  
  46. /** define compatibility on export */
  47. makeNamespaceObject: "r",
  48.  
  49. /** create a fake namespace object */
  50. createFakeNamespaceObject: "t",
  51.  
  52. /** compatibility get default export */
  53. compatGetDefaultExport: "n",
  54.  
  55. /** harmony module decorator */
  56. harmonyModuleDecorator: "hmd",
  57.  
  58. /** node.js module decorator */
  59. nodeModuleDecorator: "nmd",
  60.  
  61. /** the webpack hash */
  62. getFullHash: "h",
  63.  
  64. /** an object containing all installed WebAssembly.Instance export objects keyed by module id */
  65. wasmInstances: "w",
  66.  
  67. /** instantiate a wasm instance from module exports object, id, hash and importsObject */
  68. instantiateWasm: "v",
  69.  
  70. /** the uncaught error handler for the webpack runtime */
  71. uncaughtErrorHandler: "oe",
  72.  
  73. /** the script nonce */
  74. scriptNonce: "nc",
  75.  
  76. /**
  77. * function to load a script tag.
  78. * Arguments: (url: string, done: (event) => void), key?: string | number, chunkId?: string | number) => void
  79. * done function is called when loading has finished or timeout occurred.
  80. * It will attach to existing script tags with data-webpack == uniqueName + ":" + key or src == url.
  81. */
  82. loadScript: "l",
  83.  
  84. /**
  85. * function to promote a string to a TrustedScript using webpack's Trusted
  86. * Types policy
  87. * Arguments: (script: string) => TrustedScript
  88. */
  89. createScript: "ts",
  90.  
  91. /**
  92. * function to promote a string to a TrustedScriptURL using webpack's Trusted
  93. * Types policy
  94. * Arguments: (url: string) => TrustedScriptURL
  95. */
  96. createScriptUrl: "tu",
  97.  
  98. /**
  99. * function to return webpack's Trusted Types policy
  100. * Arguments: () => TrustedTypePolicy
  101. */
  102. getTrustedTypesPolicy: "tt",
  103.  
  104. /** the chunk name of the chunk with the runtime */
  105. chunkName: "cn",
  106.  
  107. /** the runtime id of the current runtime */
  108. runtimeId: "j",
  109.  
  110. /** the filename of the script part of the chunk */
  111. getChunkScriptFilename: "u",
  112.  
  113. /** the filename of the css part of the chunk */
  114. getChunkCssFilename: "k",
  115.  
  116. /** the filename of the script part of the hot update chunk */
  117. getChunkUpdateScriptFilename: "hu",
  118.  
  119. /** the filename of the css part of the hot update chunk */
  120. getChunkUpdateCssFilename: "hk",
  121.  
  122. /**
  123. * startup signal from runtime
  124. * This will be called when the runtime chunk has been loaded.
  125. */
  126. startup: "x",
  127.  
  128. /**
  129. * method to startup an entrypoint with needed chunks.
  130. * Signature: (moduleId: Id, chunkIds: Id[]) => any.
  131. * Returns the exports of the module or a Promise
  132. */
  133. startupEntrypoint: "X",
  134.  
  135. /**
  136. * register deferred code, which will run when certain
  137. * chunks are loaded.
  138. * Signature: (chunkIds: Id[], fn: () => any, priority: int >= 0 = 0) => any
  139. * Returned value will be returned directly when all chunks are already loaded
  140. * When (priority & 1) it will wait for all other handlers with lower priority to
  141. * be executed before itself is executed
  142. */
  143. onChunksLoaded: "O",
  144.  
  145. /**
  146. * method to install a chunk that was loaded somehow
  147. * Signature: ({ id, ids, modules, runtime }) => void
  148. */
  149. externalInstallChunk: "C",
  150.  
  151. /** interceptor for module executions */
  152. interceptModuleExecution: "i",
  153.  
  154. /** the global object */
  155. global: "g",
  156.  
  157. /** an object with all share scopes */
  158. shareScopeMap: "S",
  159.  
  160. /**
  161. * The sharing init sequence function (only runs once per share scope).
  162. * Has one argument, the name of the share scope.
  163. * Creates a share scope if not existing
  164. */
  165. initializeSharing: "I",
  166.  
  167. /** The current scope when getting a module from a remote */
  168. currentRemoteGetScope: "R",
  169.  
  170. /** the filename of the HMR manifest */
  171. getUpdateManifestFilename: "hmrF",
  172.  
  173. /** function downloading the update manifest */
  174. hmrDownloadManifest: "hmrM",
  175.  
  176. /** array with handler functions to download chunk updates */
  177. hmrDownloadUpdateHandlers: "hmrC",
  178.  
  179. /** object with all hmr module data for all modules */
  180. hmrModuleData: "hmrD",
  181.  
  182. /** array with handler functions when a module should be invalidated */
  183. hmrInvalidateModuleHandlers: "hmrI",
  184.  
  185. /** the prefix for storing state of runtime modules when hmr is enabled */
  186. hmrRuntimeStatePrefix: "hmrS",
  187.  
  188. /** the AMD define function */
  189. amdDefine: "amdD",
  190.  
  191. /** the AMD options */
  192. amdOptions: "amdO",
  193.  
  194. /** the System polyfill object */
  195. system: "System",
  196.  
  197. /**
  198. * the shorthand for Object.prototype.hasOwnProperty
  199. * using of it decreases the compiled bundle size
  200. */
  201. hasOwnProperty: "o",
  202.  
  203. /** the System.register context object */
  204. systemContext: "y",
  205.  
  206. /** the baseURI of current document */
  207. baseURI: "b",
  208.  
  209. /** a RelativeURL class when relative URLs are used */
  210. relativeUrl: "U",
  211.  
  212. /**
  213. * Creates an async module. The body function must be a async function.
  214. * "module.exports" will be decorated with an AsyncModulePromise.
  215. * The body function will be called.
  216. * To handle async dependencies correctly do this: "([a, b, c] = await handleDependencies([a, b, c]));".
  217. * If "hasAwaitAfterDependencies" is truthy, "handleDependencies()" must be called at the end of the body function.
  218. * Signature: function(
  219. * module: Module,
  220. * body: (handleDependencies: (deps: AsyncModulePromise[]) => Promise<any[]> & () => void,
  221. * hasAwaitAfterDependencies?: boolean
  222. * ) => void
  223. */
  224. asyncModule: "a",
  225. }),
  226.  
  227. /**
  228. * @param {string} chunkLoadingGlobal
  229. */
  230. interceptChunkLoading: (unsafeWindow, chunkLoadingGlobal, callback) => {
  231. /** @type {WebpackChunk[]} */
  232. const webpackChunk = unsafeWindow[chunkLoadingGlobal];
  233. let webpackChunkLoading = null;
  234. let proto = null;
  235.  
  236. function onChunksLoaded(...args) {
  237. callback(...args);
  238. return webpackChunkLoading.apply(this, args);
  239. };
  240.  
  241. if (Object.hasOwn(webpackChunk, "push")) {
  242. // We are called after runtime initializing
  243. webpackChunkLoading = webpackChunk.push;
  244. webpackChunk.push = onChunksLoaded;
  245. } else {
  246. // We are called before runtime initializing
  247. proto = Object.getPrototypeOf(webpackChunk);
  248. Object.setPrototypeOf(webpackChunk, Object.create(proto, Object.getOwnPropertyDescriptors({
  249. get push() {
  250. return proto.push;
  251. },
  252. set push(value) {
  253. Object.setPrototypeOf(webpackChunk, proto);
  254. proto = null;
  255.  
  256. webpackChunkLoading = value;
  257. webpackChunk.push = onChunksLoaded;
  258. }
  259. })));
  260. }
  261.  
  262. return () => {
  263. if (webpackChunkLoading !== null) {
  264. webpackChunk.push = webpackChunkLoading;
  265. } else if (proto !== null) {
  266. Object.setPrototypeOf(webpackChunk, proto);
  267. }
  268. };
  269. },
  270.  
  271. /**
  272. * @param {string} chunkLoadingGlobal
  273. * @param {PropertyKey} chunkId
  274. * @param {WebpackRuntimeChunkCallback} callback
  275. */
  276. loadFakeChink: (unsafeWindow, chunkLoadingGlobal, chunkId, callback) => {
  277. /** @type {WebpackChunk[]} */
  278. let webpackChunk;
  279.  
  280. if (Object.hasOwn(unsafeWindow, chunkLoadingGlobal)) {
  281. webpackChunk = unsafeWindow[chunkLoadingGlobal];
  282. } else {
  283. webpackChunk = unsafeWindow[chunkLoadingGlobal] = [];
  284. }
  285.  
  286. const fakeChunk = [[chunkId], [], (__webpack_require__) => {
  287. // Based on `APIPlugin` and `RuntimeGlobals`
  288. const {
  289. p: __webpack_public_path__,
  290. b: __webpack_base_uri__,
  291. m: __webpack_modules__,
  292. e: __webpack_chunk_load__,
  293. nc: __webpack_nonce__,
  294. cn: __webpack_chunkname__,
  295. u: __webpack_get_script_filename__,
  296. j: __webpack_runtime_id__,
  297. y: __system_context__,
  298. S: __webpack_share_scopes__,
  299. I: __webpack_init_sharing__,
  300. } = __webpack_require__;
  301. const __webpack_hash__ = __webpack_require__.h?.();
  302. callback({
  303. __webpack_require__,
  304. __webpack_public_path__,
  305. __webpack_base_uri__,
  306. __webpack_modules__,
  307. __webpack_chunk_load__,
  308. __webpack_nonce__,
  309. __webpack_chunkname__,
  310. __webpack_get_script_filename__,
  311. __webpack_runtime_id__,
  312. __system_context__,
  313. __webpack_share_scopes__,
  314. __webpack_init_sharing__,
  315. __webpack_hash__,
  316. });
  317. Promise.resolve().then(() => {
  318. const i = webpackChunk.indexOf(fakeChunk);
  319.  
  320. if (i >= 0) {
  321. webpackChunk.splice(i, 1);
  322. }
  323. });
  324. }];
  325.  
  326. webpackChunk.push(fakeChunk);
  327. },
  328. };
  329.  
  330. /**
  331. * @typedef WebpackRuntimeContext
  332. * @property {string} __webpack_require__ - the internal require function
  333. * @property {string} __webpack_public_path__ - the bundle public path
  334. * @property {string} __webpack_base_uri__ - the baseURI of current document
  335. * @property {() => any[]} __webpack_modules__ - the module functions
  336. * @property {string} __webpack_chunk_load__ - the chunk ensure function
  337. * @property {string} __webpack_nonce__ - the script nonce
  338. * @property {string} __webpack_chunkname__ - the chunk name of the chunk with the runtime
  339. * @property {string} __webpack_get_script_filename__ - the filename of the script part of the chunk
  340. * @property {string} __webpack_runtime_id__ - the runtime id of the current runtime
  341. * @property {string} __system_context__ - the System.register context object
  342. * @property {string} __webpack_share_scopes__ - an object with all share scopes
  343. * @property {string} __webpack_init_sharing__ - The sharing init sequence function (only runs once per share scope).
  344. * Has one argument, the name of the share scope.
  345. * Creates a share scope if not existing
  346. * @property {string} [__webpack_hash__] - the webpack hash
  347. */
  348.  
  349. /**
  350. * @callback WebpackRuntimeChunkCallback
  351. * @param {WebpackRuntimeContext} context
  352. */
  353.  
  354. /**
  355. * @typedef {[chunkIds: string[], moreModules: Record<string, () => void>, runtime?: () => void]} WebpackChunk
  356. */

QingJ © 2025

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