-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjected.js
More file actions
69 lines (62 loc) · 1.95 KB
/
Copy pathinjected.js
File metadata and controls
69 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Injected script running in page context
// Author: OFJAAAH
(function() {
'use strict';
// Intercept require/import calls if available
if (typeof require !== 'undefined' && require.cache) {
Object.keys(require.cache).forEach(module => {
if (module.includes('node_modules')) {
const parts = module.split('node_modules/');
if (parts[1]) {
const pkgName = parts[1].split('/')[0];
window.postMessage({
type: 'DEPENDENCY_HUNTER_PACKAGE',
package: pkgName,
packageType: 'npm',
source: window.location.href
}, '*');
}
}
});
}
// Monitor webpack modules
if (window.webpackJsonp) {
const original = window.webpackJsonp.push;
window.webpackJsonp.push = function(args) {
if (args && args[1]) {
Object.keys(args[1]).forEach(moduleId => {
const moduleStr = args[1][moduleId].toString();
// Extract requires
const requires = moduleStr.match(/require\(['"]([^'"]+)['"]\)/g);
if (requires) {
requires.forEach(req => {
const match = req.match(/require\(['"]([^'"]+)['"]\)/);
if (match && match[1] && !match[1].startsWith('.')) {
window.postMessage({
type: 'DEPENDENCY_HUNTER_PACKAGE',
package: match[1],
packageType: 'npm',
source: window.location.href
}, '*');
}
});
}
});
}
return original.apply(this, arguments);
};
}
// Monitor global objects for package info
if (window.__NEXT_DATA__) {
console.log('[Dependency Hunter] Next.js detected');
}
if (window.__NUXT__) {
console.log('[Dependency Hunter] Nuxt.js detected');
}
if (window.React) {
console.log('[Dependency Hunter] React detected');
}
if (window.Vue) {
console.log('[Dependency Hunter] Vue detected');
}
})();