Webpack

Expose webpack modules to userscripts

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

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

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

QingJ © 2025

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