Webpack

Expose webpack modules to userscripts

目前为 2023-08-26 提交的版本。查看 最新版本

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

  1. function isNonEmptyObj(obj) {
  2. if (obj === null || (typeof obj !== "function" && typeof obj !== "object")) {
  3. return false;
  4. }
  5. for (const key in obj) {
  6. return true;
  7. }
  8. return false;
  9. }
  10.  
  11. // Based on `Webpack-module-crack` and `moduleRaid`
  12. class Webpack {
  13. constructor(options) {
  14. const { moduleId, chunkId, entryPoint } = options || {};
  15. this.moduleId = moduleId || Math.random().toString(36).substring(2, 6);
  16. this.chunkId = chunkId || Math.floor(101 + Math.random() * 899);
  17. this.modules = {};
  18. this.data = [
  19. [this.chunkId],
  20. {
  21. [this.moduleId]: (module, exports, require) => {
  22. const installedModules = require.c;
  23. for (const id in installedModules) {
  24. const exports = installedModules[id].exports;
  25. if (isNonEmptyObj(exports)) {
  26. this.modules[id] = exports;
  27. }
  28. }
  29. },
  30. },
  31. [[this.moduleId]],
  32. ];
  33. if (entryPoint) {
  34. this.inject(entryPoint);
  35. } else {
  36. this.inject("webpackJsonp");
  37. }
  38. }
  39.  
  40. inject(entryPoint) {
  41. try {
  42. if (unsafeWindow) {
  43. unsafeWindow[entryPoint].push(this.data);
  44. } else {
  45. window[entryPoint].push(this.data);
  46. }
  47. } catch (err) {
  48. throw new Error(`Injection failed: ${err.message}`);
  49. }
  50. }
  51. }

QingJ © 2025

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