browser-extension-manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/TODO.md +0 -0
- package/bin/browser-extension-manager +7 -0
- package/dist/assets/css/fontawesome.scss +2 -0
- package/dist/assets/css/main.scss +3 -0
- package/dist/assets/js/main.js +4 -0
- package/dist/assets/js copy/base.js +7 -0
- package/dist/assets/js copy/core.js +81 -0
- package/dist/assets/js copy/main.js +10 -0
- package/dist/background.js +261 -0
- package/dist/build.js +92 -0
- package/dist/cli.js +70 -0
- package/dist/commands/clean.js +33 -0
- package/dist/commands/install.js +52 -0
- package/dist/commands/setup.js +484 -0
- package/dist/commands/version.js +12 -0
- package/dist/config/manifest.json +78 -0
- package/dist/content.js +52 -0
- package/dist/defaults/.nvmrc +1 -0
- package/dist/defaults/.vscode/settings.json +8 -0
- package/dist/defaults/_.gitignore +71 -0
- package/dist/defaults/hooks/build:post.js +8 -0
- package/dist/defaults/hooks/build:pre.js +8 -0
- package/dist/defaults/src/_locales/en/messages.json +14 -0
- package/dist/defaults/src/assets/css/content.scss +2 -0
- package/dist/defaults/src/assets/css/options.scss +2 -0
- package/dist/defaults/src/assets/css/popup.scss +2 -0
- package/dist/defaults/src/assets/images/_ +0 -0
- package/dist/defaults/src/assets/images/icons/icon.png +0 -0
- package/dist/defaults/src/assets/js/background.js +11 -0
- package/dist/defaults/src/assets/js/content.js +8 -0
- package/dist/defaults/src/assets/js/popup.js +7 -0
- package/dist/defaults/src/assets/vendor/_ +0 -0
- package/dist/defaults/src/manifest.json +86 -0
- package/dist/defaults/src/pages/options.html +21 -0
- package/dist/defaults/src/pages/popup.html +21 -0
- package/dist/gulp/main.js +50 -0
- package/dist/gulp/plugins/webpack/replace.js +52 -0
- package/dist/gulp/tasks/developmentRebuild.js +94 -0
- package/dist/gulp/tasks/distribute.js +163 -0
- package/dist/gulp/tasks/icons.js +149 -0
- package/dist/gulp/tasks/package.js +167 -0
- package/dist/gulp/tasks/sass.js +74 -0
- package/dist/gulp/tasks/serve.js +183 -0
- package/dist/gulp/tasks/test.js +16 -0
- package/dist/gulp/tasks/webpack.js +186 -0
- package/dist/index.js +27 -0
- package/dist/lib/affiliatizer.js +198 -0
- package/dist/lib/extension.js +104 -0
- package/dist/lib/logger.js +56 -0
- package/dist/lib/messaging.js +48 -0
- package/package.json +87 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('webpack');
|
|
4
|
+
const { watch, series } = require('gulp');
|
|
5
|
+
const glob = require('glob').globSync;
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const wp = require('webpack');
|
|
8
|
+
const ReplacePlugin = require('../plugins/webpack/replace.js');
|
|
9
|
+
const version = require('wonderful-version');
|
|
10
|
+
|
|
11
|
+
// Load package
|
|
12
|
+
const package = Manager.getPackage('main');
|
|
13
|
+
const project = Manager.getPackage('project');
|
|
14
|
+
const manifest = Manager.getManifest();
|
|
15
|
+
const config = Manager.getConfig();
|
|
16
|
+
|
|
17
|
+
// Load variables
|
|
18
|
+
const firebaseVersion = version.clean(require('web-manager/package.json').dependencies.firebase);
|
|
19
|
+
|
|
20
|
+
// Settings
|
|
21
|
+
// const MINIFY = false;
|
|
22
|
+
const MINIFY = Manager.getEnvironment() === 'production';
|
|
23
|
+
const input = [
|
|
24
|
+
// Include the project's src files
|
|
25
|
+
'src/assets/js/**/*.js',
|
|
26
|
+
|
|
27
|
+
// Include service worker
|
|
28
|
+
'src/assets/js/background.js',
|
|
29
|
+
|
|
30
|
+
// Include UJ's dist files
|
|
31
|
+
path.join(__dirname, '../../../dist/assets/js/**/*.js'),
|
|
32
|
+
|
|
33
|
+
// Files to exclude
|
|
34
|
+
// '!dist/**',
|
|
35
|
+
];
|
|
36
|
+
const delay = 250;
|
|
37
|
+
|
|
38
|
+
const settings = {
|
|
39
|
+
mode: 'production',
|
|
40
|
+
target: ['web', 'es5'],
|
|
41
|
+
plugins: [
|
|
42
|
+
new ReplacePlugin({
|
|
43
|
+
// App & Project
|
|
44
|
+
...project,
|
|
45
|
+
...manifest,
|
|
46
|
+
...config,
|
|
47
|
+
|
|
48
|
+
// Additional
|
|
49
|
+
environment: Manager.getEnvironment(),
|
|
50
|
+
|
|
51
|
+
// Specific
|
|
52
|
+
firebaseVersion: firebaseVersion,
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
entry: {
|
|
56
|
+
// Entry is dynamically generated
|
|
57
|
+
},
|
|
58
|
+
output: {
|
|
59
|
+
// Set the path to the dist folder
|
|
60
|
+
path: path.resolve(process.cwd(), 'dist/assets/js'),
|
|
61
|
+
|
|
62
|
+
// Set the public path
|
|
63
|
+
// publicPath: '',
|
|
64
|
+
publicPath: '/assets/js/',
|
|
65
|
+
|
|
66
|
+
// https://github.com/webpack/webpack/issues/959
|
|
67
|
+
chunkFilename: (data) => {
|
|
68
|
+
// Special case for the main chunk
|
|
69
|
+
if (data.chunk.name === 'main') {
|
|
70
|
+
return '[name].chunk.js';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Otherwise, use the default chunk filename
|
|
74
|
+
return '[name].chunk.[chunkhash].js';
|
|
75
|
+
},
|
|
76
|
+
filename: (data) => {
|
|
77
|
+
// Special case for the background chunk
|
|
78
|
+
// if (data.chunk.name === 'background') {
|
|
79
|
+
// return 'background.js';
|
|
80
|
+
// }
|
|
81
|
+
|
|
82
|
+
// Otherwise, use the default filename
|
|
83
|
+
return '[name].bundle.js';
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
resolveLoader: {
|
|
87
|
+
modules: [
|
|
88
|
+
path.resolve(process.cwd(), 'node_modules', package.name, 'node_modules'), // Path to your helper module's node_modules
|
|
89
|
+
path.resolve(process.cwd(), 'node_modules'), // Default project node_modules
|
|
90
|
+
'node_modules', // Fallback to global
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
module: {
|
|
94
|
+
rules: [
|
|
95
|
+
{
|
|
96
|
+
test: /\.js$/,
|
|
97
|
+
exclude: /node_modules/,
|
|
98
|
+
use: {
|
|
99
|
+
loader: 'babel-loader',
|
|
100
|
+
options: {
|
|
101
|
+
// presets: ['@babel/preset-env'],
|
|
102
|
+
presets: [
|
|
103
|
+
require.resolve('@babel/preset-env', {
|
|
104
|
+
paths: [path.resolve(process.cwd(), 'node_modules', package.name, 'node_modules')]
|
|
105
|
+
})
|
|
106
|
+
],
|
|
107
|
+
compact: MINIFY,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
optimization: {
|
|
114
|
+
minimize: MINIFY,
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Task
|
|
119
|
+
function webpack(complete) {
|
|
120
|
+
// Log
|
|
121
|
+
logger.log('Starting...');
|
|
122
|
+
|
|
123
|
+
// Update entry points
|
|
124
|
+
updateEntryPoints();
|
|
125
|
+
|
|
126
|
+
// Compiler
|
|
127
|
+
const compiler = wp(settings, (e, stats) => {
|
|
128
|
+
// Log
|
|
129
|
+
logger.log('Finished!');
|
|
130
|
+
|
|
131
|
+
// Error
|
|
132
|
+
if (e) {
|
|
133
|
+
logger.error(e);
|
|
134
|
+
} else {
|
|
135
|
+
logger.log('Stats:\n', stats.toString({ colors: true }));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Complete
|
|
139
|
+
return complete(e);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Watcher task
|
|
143
|
+
function webpackWatcher(complete) {
|
|
144
|
+
// Quit if in build mode
|
|
145
|
+
if (Manager.isBuildMode()) {
|
|
146
|
+
logger.log('[watcher] Skipping watcher in build mode');
|
|
147
|
+
return complete();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Log
|
|
151
|
+
logger.log('[watcher] Watching for changes...');
|
|
152
|
+
|
|
153
|
+
// Watch for changes
|
|
154
|
+
watch(input, { delay: delay }, webpack)
|
|
155
|
+
.on('change', function(path) {
|
|
156
|
+
// Log
|
|
157
|
+
logger.log(`[watcher] File ${path} was changed`);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Complete
|
|
161
|
+
return complete();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function updateEntryPoints() {
|
|
165
|
+
// Get all JS files
|
|
166
|
+
const files = glob(input);
|
|
167
|
+
|
|
168
|
+
// Update from src
|
|
169
|
+
settings.entry = files.reduce((acc, file) => {
|
|
170
|
+
// Get the file name
|
|
171
|
+
const name = path.basename(file, path.extname(file));
|
|
172
|
+
|
|
173
|
+
// Add to entry points starting with "./"
|
|
174
|
+
// acc[name] = `./${file}`;
|
|
175
|
+
acc[name] = path.resolve(file);
|
|
176
|
+
|
|
177
|
+
// Return
|
|
178
|
+
return acc;
|
|
179
|
+
}, {});
|
|
180
|
+
|
|
181
|
+
// Log
|
|
182
|
+
logger.log('Updated entry points:', settings.entry);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Default Task
|
|
186
|
+
module.exports = series(webpack, webpackWatcher);
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const WebManager = require('web-manager');
|
|
3
|
+
|
|
4
|
+
// Class
|
|
5
|
+
function Manager() {
|
|
6
|
+
const self = this;
|
|
7
|
+
|
|
8
|
+
// Return
|
|
9
|
+
return self;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Initialize
|
|
13
|
+
Manager.prototype.initialize = function (callback) {
|
|
14
|
+
const self = this;
|
|
15
|
+
|
|
16
|
+
// Initiate the web manager
|
|
17
|
+
self._manager = new WebManager();
|
|
18
|
+
|
|
19
|
+
// Initialize
|
|
20
|
+
self._manager.init(window.Configuration, callback);
|
|
21
|
+
|
|
22
|
+
// Return
|
|
23
|
+
return self._manager;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Export
|
|
27
|
+
module.exports = Manager;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const ext = require('./extension.js');
|
|
3
|
+
const storage = ext.storage;
|
|
4
|
+
|
|
5
|
+
// Suppported affiliates
|
|
6
|
+
const map = [
|
|
7
|
+
// Amazon
|
|
8
|
+
{
|
|
9
|
+
id: 'amazon',
|
|
10
|
+
match: /amazon.com/,
|
|
11
|
+
replace: {
|
|
12
|
+
href: 'https://giftly.app/product?url=https%3A%2F%2Fwww.amazon.com%2Fdp%2FB07PCMWTSG%3F%26linkCode%3Dll2%26tag%3Ditwcw1--promo-server-20%26linkId%3D38af0d81784751e4cf5b1136b8c32f63%26language%3Den_US%26ref_%3Das_li_ss_tl',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
// Meals
|
|
17
|
+
{
|
|
18
|
+
id: 'factor',
|
|
19
|
+
match: /factor75.com/,
|
|
20
|
+
replace: {
|
|
21
|
+
href: 'https://www.factor75.com/plans?c=HS-HC5E50S4I&discount_comm_id=cd2585e3-0672-4633-90a6-64f6883222a3&plans_ab=true&utm_campaign=clipboard&utm_medium=referral&utm_source=raf-share-hpt',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Rewards
|
|
26
|
+
{
|
|
27
|
+
id: 'honeygain',
|
|
28
|
+
match: /honeygain.com/,
|
|
29
|
+
replace: {
|
|
30
|
+
href: 'https://r.honeygain.me/IANA1DCDB1',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'jumptask',
|
|
35
|
+
match: /app.jumptask.io/,
|
|
36
|
+
replace: {
|
|
37
|
+
href: 'https://www.jumptask.io/r/dazelafojafy',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'pawns',
|
|
42
|
+
match: /pawns.app/,
|
|
43
|
+
replace: {
|
|
44
|
+
href: 'https://pawns.app/?r=5798401',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Shopping
|
|
49
|
+
{
|
|
50
|
+
id: 'capitaloneshopping',
|
|
51
|
+
match: /capitaloneshopping.com/,
|
|
52
|
+
replace: {
|
|
53
|
+
href: 'https://capitaloneshopping.com/r/5G2HF1D',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'coupert',
|
|
58
|
+
match: /coupert.com/,
|
|
59
|
+
replace: {
|
|
60
|
+
href: 'https://www.coupert.com/invite/4yvqkp7da',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'honey',
|
|
65
|
+
match: /joinhoney.com/,
|
|
66
|
+
replace: {
|
|
67
|
+
href: 'https://www.joinhoney.com/ref/8dryc8u',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'lolli',
|
|
72
|
+
match: /lolli.com/,
|
|
73
|
+
replace: {
|
|
74
|
+
href: 'https://lolli.com/share/ydsPvyc23m',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'paypal',
|
|
79
|
+
match: /paypal.com/,
|
|
80
|
+
replace: {
|
|
81
|
+
href: 'https://py.pl/4gPBBJjLbbz',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'rakuten',
|
|
86
|
+
match: /rakuten.com/,
|
|
87
|
+
replace: {
|
|
88
|
+
href: 'https://www.rakuten.com/r/IANWIE8?eeid=28187',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'upside',
|
|
93
|
+
match: /upside.com/,
|
|
94
|
+
replace: {
|
|
95
|
+
href: 'https://upside.app.link/IAN4447',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// VPN
|
|
100
|
+
{
|
|
101
|
+
id: 'nordvpn',
|
|
102
|
+
match: /nordvpn.com/,
|
|
103
|
+
replace: {
|
|
104
|
+
href: 'https://ref.nordvpn.com/CHMkfrnoQtL',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
function Affiliatizer() {
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Affiliatizer.get = function () {
|
|
113
|
+
return map;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Affiliatizer.initialize = async function (parent) {
|
|
117
|
+
// Parse the URL
|
|
118
|
+
const url = new URL(window.location.href);
|
|
119
|
+
|
|
120
|
+
// Check if the URL has the resetAffiliatizer parameter
|
|
121
|
+
if (url.searchParams.get('resetAffiliatizer') === 'true') {
|
|
122
|
+
// Log
|
|
123
|
+
parent.log('Resetting affiliatizer data...');
|
|
124
|
+
|
|
125
|
+
// Reset the data
|
|
126
|
+
await storage.set({ affiliatizer: null })
|
|
127
|
+
url.searchParams.delete('resetAffiliatizer');
|
|
128
|
+
|
|
129
|
+
// Log
|
|
130
|
+
parent.log('Reset!');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Loop through the map
|
|
134
|
+
map.forEach((item, i) => {
|
|
135
|
+
// Get the item
|
|
136
|
+
const id = item.id;
|
|
137
|
+
|
|
138
|
+
// Log
|
|
139
|
+
// parent.log('Checking for', id, item.match, 'in', url.hostname, '...');
|
|
140
|
+
|
|
141
|
+
// Check if the item matches
|
|
142
|
+
if (!item.match.test(url.hostname)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Process
|
|
147
|
+
storage.get((data) => {
|
|
148
|
+
// Log
|
|
149
|
+
parent.log('Matched', data);
|
|
150
|
+
|
|
151
|
+
// Set the default data
|
|
152
|
+
const now = new Date();
|
|
153
|
+
const timestamp = new Date(data.affiliatizer && data.affiliatizer[id] ? data.affiliatizer[id].timestamp || 0 : 0);
|
|
154
|
+
const differenceInHours = (now - timestamp) / 1000 / 60 / 60;
|
|
155
|
+
|
|
156
|
+
// Check if the timestamp is older than 24 hours
|
|
157
|
+
if (differenceInHours < 24) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Build the new URL
|
|
162
|
+
const newURL = new URL(url.href);
|
|
163
|
+
|
|
164
|
+
// Query
|
|
165
|
+
if (item.replace.query) {
|
|
166
|
+
Object.keys(item.replace.query).forEach((key, i) => {
|
|
167
|
+
newURL.searchParams.set(key, item.replace.query[key]);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Path
|
|
172
|
+
if (item.replace.pathname) {
|
|
173
|
+
newURL.pathname = item.replace.pathname;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Href
|
|
177
|
+
if (item.replace.href) {
|
|
178
|
+
newURL.href = item.replace.href;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Log
|
|
182
|
+
parent.log('Redirecting...', newURL.toString());
|
|
183
|
+
|
|
184
|
+
// Save to storage
|
|
185
|
+
const newTimestamp = {
|
|
186
|
+
timestamp: now.toISOString(),
|
|
187
|
+
};
|
|
188
|
+
const updatedData = Object.assign({}, data.affiliatizer, { [id]: newTimestamp });
|
|
189
|
+
storage.set({ affiliatizer: updatedData });
|
|
190
|
+
|
|
191
|
+
// Redirect
|
|
192
|
+
window.location.href = newURL.toString();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Export
|
|
198
|
+
module.exports = Affiliatizer;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// APIs
|
|
2
|
+
const apis = [
|
|
3
|
+
'action',
|
|
4
|
+
'alarms',
|
|
5
|
+
'bookmarks',
|
|
6
|
+
'browsingData',
|
|
7
|
+
'browserAction',
|
|
8
|
+
'commands',
|
|
9
|
+
'contentSettings',
|
|
10
|
+
'contextMenus',
|
|
11
|
+
'cookies',
|
|
12
|
+
'downloads',
|
|
13
|
+
'events',
|
|
14
|
+
'extension',
|
|
15
|
+
'extensionTypes',
|
|
16
|
+
'history',
|
|
17
|
+
'i18n',
|
|
18
|
+
'identity',
|
|
19
|
+
'idle',
|
|
20
|
+
'management',
|
|
21
|
+
'notifications',
|
|
22
|
+
'pageAction',
|
|
23
|
+
'permissions',
|
|
24
|
+
'privacy',
|
|
25
|
+
'proxy',
|
|
26
|
+
'runtime',
|
|
27
|
+
'scripting',
|
|
28
|
+
'sidePanel',
|
|
29
|
+
'storage',
|
|
30
|
+
'tabs',
|
|
31
|
+
'topSites',
|
|
32
|
+
'tts',
|
|
33
|
+
'wallpaper',
|
|
34
|
+
'webNavigation',
|
|
35
|
+
'webRequest',
|
|
36
|
+
'windows'
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
// Class
|
|
40
|
+
function Extension () {
|
|
41
|
+
const self = this;
|
|
42
|
+
|
|
43
|
+
// Loop through the APIs and assign them to the object
|
|
44
|
+
apis.forEach(function (api) {
|
|
45
|
+
// Initialize the API to null
|
|
46
|
+
self[api] = null;
|
|
47
|
+
|
|
48
|
+
// Try chrome
|
|
49
|
+
try {
|
|
50
|
+
if (chrome[api]) {
|
|
51
|
+
self[api] = chrome[api];
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {}
|
|
54
|
+
|
|
55
|
+
// Try window
|
|
56
|
+
try {
|
|
57
|
+
if (window[api]) {
|
|
58
|
+
self[api] = window[api];
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// Try browser
|
|
64
|
+
try {
|
|
65
|
+
if (browser[api]) {
|
|
66
|
+
self[api] = browser[api];
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {}
|
|
69
|
+
|
|
70
|
+
// Try browser.extension
|
|
71
|
+
try {
|
|
72
|
+
self.api = browser.extension[api]
|
|
73
|
+
} catch (e) {}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Try to get the runtime
|
|
77
|
+
try {
|
|
78
|
+
if (browser && browser.runtime) {
|
|
79
|
+
self.runtime = browser.runtime
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
|
|
83
|
+
// Try to get the browserAction
|
|
84
|
+
try {
|
|
85
|
+
if (browser && browser.browserAction) {
|
|
86
|
+
self.browserAction = browser.browserAction
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {}
|
|
89
|
+
|
|
90
|
+
// Fix storage
|
|
91
|
+
if (self.storage) {
|
|
92
|
+
if (self.storage.sync) {
|
|
93
|
+
self.storage = self.storage.sync
|
|
94
|
+
} else if (self.storage.local) {
|
|
95
|
+
self.storage = self.storage.local
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Return the object
|
|
100
|
+
return self;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Export
|
|
104
|
+
module.exports = new Extension();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
|
|
4
|
+
// Logger class
|
|
5
|
+
function Logger(name) {
|
|
6
|
+
const self = this;
|
|
7
|
+
|
|
8
|
+
// Properties
|
|
9
|
+
self.name = name;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Loop through log, error, warn, and info and make methods that log to console with the name and time [xx:xx:xx] name: message
|
|
13
|
+
['log', 'error', 'warn', 'info'].forEach((method) => {
|
|
14
|
+
Logger.prototype[method] = function () {
|
|
15
|
+
// Get time
|
|
16
|
+
const time = new Date().toLocaleTimeString('en-US', {
|
|
17
|
+
hour12: false,
|
|
18
|
+
hour: '2-digit',
|
|
19
|
+
minute: '2-digit',
|
|
20
|
+
second: '2-digit'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Determine color based on method
|
|
24
|
+
let color;
|
|
25
|
+
switch (method) {
|
|
26
|
+
case 'warn':
|
|
27
|
+
color = chalk.yellow;
|
|
28
|
+
break;
|
|
29
|
+
case 'error':
|
|
30
|
+
color = chalk.red;
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
color = (text) => text; // No color
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Convert arguments to array and prepend time and name
|
|
37
|
+
const args = [`[${chalk.magenta(time)}] '${chalk.cyan(this.name)}':`, ...Array.from(arguments).map(arg => {
|
|
38
|
+
return typeof arg === 'string'
|
|
39
|
+
? color(arg)
|
|
40
|
+
: (
|
|
41
|
+
arg instanceof Error
|
|
42
|
+
? color(arg.stack)
|
|
43
|
+
: arg
|
|
44
|
+
);
|
|
45
|
+
})];
|
|
46
|
+
|
|
47
|
+
// Log
|
|
48
|
+
console[method].apply(console, args);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Export chalk as color
|
|
53
|
+
Logger.prototype.format = chalk;
|
|
54
|
+
|
|
55
|
+
// Export
|
|
56
|
+
module.exports = Logger;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
// import ext from './ext';
|
|
3
|
+
const ext = require('./extension.js');
|
|
4
|
+
|
|
5
|
+
// Messaging
|
|
6
|
+
function Messaging(init) {
|
|
7
|
+
const self = this;
|
|
8
|
+
|
|
9
|
+
// Check init
|
|
10
|
+
if (!init || !init) {
|
|
11
|
+
throw new Error('No init and/or init.sender')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Setup
|
|
15
|
+
self.onMessage = function () {}
|
|
16
|
+
self.sender = init.sender;
|
|
17
|
+
ext.runtime.onMessage.addListener(
|
|
18
|
+
function(request, sender, sendResponse) {
|
|
19
|
+
self.onMessage(request, sender, sendResponse)
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Send
|
|
25
|
+
Messaging.prototype.send = function (request) {
|
|
26
|
+
const self = this;
|
|
27
|
+
|
|
28
|
+
// Check request
|
|
29
|
+
if (!request) {
|
|
30
|
+
throw new Error('No request')
|
|
31
|
+
} else if (!request.destination) {
|
|
32
|
+
throw new Error('No request.destination')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Check sender
|
|
36
|
+
ext.runtime.sendMessage({
|
|
37
|
+
sender: self.sender,
|
|
38
|
+
destination: request.destination,
|
|
39
|
+
command: request.command,
|
|
40
|
+
payload: request.payload,
|
|
41
|
+
})
|
|
42
|
+
.catch(e => {
|
|
43
|
+
console.warn(`Failed to send message ${self.sender} => ${request.destination}`, request.command, request.payload);
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Export
|
|
48
|
+
module.exports = Messaging;
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "browser-extension-manager",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Browser Extension Manager dependency manager",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/index.js",
|
|
8
|
+
"./build": "./dist/build.js",
|
|
9
|
+
"./background": "./dist/background.js",
|
|
10
|
+
"./content": "./dist/content.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepare": "node -e \"require('prepare-package')()\"",
|
|
14
|
+
"prepare:watch": "nodemon -w ./src -e '*' --exec 'npm run prepare'"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"ext": "bin/browser-extension-manager",
|
|
18
|
+
"bxm": "bin/browser-extension-manager",
|
|
19
|
+
"browser-extension-manager": "bin/browser-extension-manager"
|
|
20
|
+
},
|
|
21
|
+
"preparePackage": {
|
|
22
|
+
"input": "./src",
|
|
23
|
+
"output": "./dist",
|
|
24
|
+
"replace": {}
|
|
25
|
+
},
|
|
26
|
+
"projectScripts": {
|
|
27
|
+
"start": "npx bxm clean && npx bxm setup && npm run gulp --",
|
|
28
|
+
"gulp": "gulp --cwd ./ --gulpfile ./node_modules/browser-extension-manager/dist/gulp/main.js",
|
|
29
|
+
"build": "BXM_BUILD_MODE=true npm run gulp -- build"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": "22"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/itw-creative-works/browser-extension-manager.git"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"Autoprefixer",
|
|
40
|
+
"Browsersync",
|
|
41
|
+
"gulp",
|
|
42
|
+
"imagemin",
|
|
43
|
+
"Jekyll",
|
|
44
|
+
"PostCSS",
|
|
45
|
+
"Sass",
|
|
46
|
+
"Webpack"
|
|
47
|
+
],
|
|
48
|
+
"author": "ITW Creative Works",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/itw-creative-works/browser-extension-manager/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://template.itwcreativeworks.com",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@babel/core": "^7.26.10",
|
|
56
|
+
"@babel/preset-env": "^7.26.9",
|
|
57
|
+
"@fortawesome/fontawesome-free": "^6.7.2",
|
|
58
|
+
"babel-loader": "^9.2.1",
|
|
59
|
+
"browser-sync": "^3.0.3",
|
|
60
|
+
"chalk": "^4.1.2",
|
|
61
|
+
"fs-jetpack": "^5.1.0",
|
|
62
|
+
"glob": "^11.0.1",
|
|
63
|
+
"gulp-clean-css": "^4.3.0",
|
|
64
|
+
"gulp-rename": "^2.0.0",
|
|
65
|
+
"gulp-responsive-modern": "^1.0.0",
|
|
66
|
+
"gulp-sass": "^6.0.1",
|
|
67
|
+
"itwcw-package-analytics": "^1.0.6",
|
|
68
|
+
"json5": "^2.2.3",
|
|
69
|
+
"lodash": "^4.17.21",
|
|
70
|
+
"minimatch": "^10.0.1",
|
|
71
|
+
"node-powertools": "^2.1.5",
|
|
72
|
+
"npm-api": "^1.0.1",
|
|
73
|
+
"sass": "^1.86.0",
|
|
74
|
+
"through2": "^4.0.2",
|
|
75
|
+
"web-manager": "^3.2.73",
|
|
76
|
+
"webpack": "^5.98.0",
|
|
77
|
+
"wonderful-fetch": "^1.3.3",
|
|
78
|
+
"wonderful-version": "^1.3.2",
|
|
79
|
+
"yargs": "^17.7.2"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"gulp": "^5.0.0"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"prepare-package": "^1.1.14"
|
|
86
|
+
}
|
|
87
|
+
}
|