browser-extension-manager 1.0.6 → 1.0.8

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.
@@ -9,6 +9,7 @@ function Manager() {
9
9
 
10
10
  // Properties
11
11
  self.extension = null;
12
+ self.logger = null;
12
13
 
13
14
  // Defaults
14
15
  self.config = {};
@@ -40,6 +41,7 @@ Manager.prototype.initialize = function () {
40
41
  return new Promise(function(resolve, reject) {
41
42
  // Properties
42
43
  self.extension = require('./lib/extension');
44
+ self.logger = new (require('./lib/logger-lite'))('background');
43
45
 
44
46
  // Parse config file
45
47
  parseConfiguration(self);
@@ -54,32 +56,13 @@ Manager.prototype.initialize = function () {
54
56
  setupLiveReload(self);
55
57
 
56
58
  // Log
57
- self.log('Initialized!', self.version, self.cache.name, self);
59
+ self.logger.log('Initialized!', self.version, self.cache.name, self);
58
60
 
59
61
  // Return
60
62
  return resolve(self);
61
63
  });
62
64
  };
63
65
 
64
- // Setup logger
65
- ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
66
- Manager.prototype[method] = function() {
67
- // Get arguments
68
- const time = new Date().toLocaleTimeString('en-US', {
69
- hour12: false,
70
- hour: '2-digit',
71
- minute: '2-digit',
72
- second: '2-digit'
73
- });
74
-
75
- // Add prefix
76
- const args = [`[${time}] background:`, ...Array.from(arguments)];
77
-
78
- // Call the original console method
79
- console[method].apply(console, args);
80
- };
81
- });
82
-
83
66
  // Parse configuration
84
67
  function parseConfiguration(self) {
85
68
  try {
@@ -87,9 +70,9 @@ function parseConfiguration(self) {
87
70
  self.cache.breaker = new Date().getTime();
88
71
  self.cache.name = `${self.app}-${self.cache.breaker}`;
89
72
 
90
- self.log('Parsed configuration', self.config);
73
+ self.logger.log('Parsed configuration', self.config);
91
74
  } catch (e) {
92
- self.error('Error parsing configuration', e);
75
+ self.logger.error('Error parsing configuration', e);
93
76
  }
94
77
  }
95
78
 
@@ -118,10 +101,10 @@ function setupListeners(self) {
118
101
  const clickAction = payload.click_action || data.click_action || '/';
119
102
 
120
103
  // Log
121
- self.log('Event: notificationclick event', event);
122
- self.log('Event: notificationclick data', data);
123
- self.log('Event: notificationclick payload', payload);
124
- self.log('Event: notificationclick clickAction', clickAction);
104
+ self.logger.log('Event: notificationclick event', event);
105
+ self.logger.log('Event: notificationclick data', data);
106
+ self.logger.log('Event: notificationclick payload', payload);
107
+ self.logger.log('Event: notificationclick clickAction', clickAction);
125
108
 
126
109
  // Handle the click
127
110
  event.waitUntil(
@@ -153,14 +136,14 @@ function setupListeners(self) {
153
136
  if (data.command === '') { return };
154
137
 
155
138
  // Log
156
- self.log('Event: postMessage', data);
139
+ self.logger.log('Event: postMessage', data);
157
140
 
158
141
  // Handle the command
159
142
  if (data.command === 'function') {
160
143
  data.args.function = data.args.function || function() {};
161
144
  data.args.function();
162
145
  } else if (data.command === 'debug') {
163
- self.log('Debug data =', data);
146
+ self.logger.log('Debug data =', data);
164
147
  event.ports[0].postMessage(response);
165
148
  } else if (data.command === 'skipWaiting') {
166
149
  self.skipWaiting();
@@ -190,13 +173,13 @@ function setupListeners(self) {
190
173
  pagesToCache
191
174
  )
192
175
  .then(() => {
193
- self.log('Cached resources.');
176
+ self.logger.log('Cached resources.');
194
177
  event.ports[0].postMessage(response);
195
178
  })
196
179
  .catch(() => {
197
180
  response.status = 'fail';
198
181
  event.ports[0].postMessage(response);
199
- self.log('Failed to cache resources.')
182
+ self.logger.log('Failed to cache resources.')
200
183
  });
201
184
  })
202
185
  }
@@ -210,12 +193,12 @@ function setupListeners(self) {
210
193
  try { event.ports[0].postMessage(response) } catch (e) {}
211
194
 
212
195
  // Log
213
- self.log('Failed to receive message:', data, e);
196
+ self.logger.log('Failed to receive message:', data, e);
214
197
  }
215
198
  });
216
199
 
217
200
  // Log
218
- self.log('Set up listeners');
201
+ self.logger.log('Set up listeners');
219
202
  }
220
203
 
221
204
  // Import Firebase
@@ -258,16 +241,16 @@ function setupLiveReload(self) {
258
241
  connection = new WebSocket(address);
259
242
 
260
243
  // Log connection
261
- self.log(`Reload connecting to ${address}...`);
244
+ self.logger.log(`Reload connecting to ${address}...`);
262
245
 
263
246
  // Log connection errors
264
247
  connection.onerror = (e) => {
265
- self.error('Reload connection got error:', e);
248
+ self.logger.error('Reload connection got error:', e);
266
249
  };
267
250
 
268
251
  // Log when set up correctly
269
252
  connection.onopen = () => {
270
- self.log('Reload connection set up!');
253
+ self.logger.log('Reload connection set up!');
271
254
 
272
255
  // Reload the extension only on reconnections
273
256
  if (isReconnecting) {
@@ -284,7 +267,7 @@ function setupLiveReload(self) {
284
267
  const seconds = 1;
285
268
 
286
269
  // Log
287
- self.log(`Reload connection closed. Attempting to reconnect in ${seconds} second(s)...`);
270
+ self.logger.log(`Reload connection closed. Attempting to reconnect in ${seconds} second(s)...`);
288
271
 
289
272
  // Set the reconnection flag
290
273
  isReconnecting = true;
@@ -303,7 +286,7 @@ function setupLiveReload(self) {
303
286
  const data = JSON.parse(event.data);
304
287
 
305
288
  // Log
306
- self.log('Reload connection got message:', data);
289
+ self.logger.log('Reload connection got message:', data);
307
290
 
308
291
  // Handle reload command
309
292
  if (data && data.command === 'reload') {
@@ -313,7 +296,7 @@ function setupLiveReload(self) {
313
296
  }
314
297
 
315
298
  function reload() {
316
- self.log('Reloading extension...');
299
+ self.logger.log('Reloading extension...');
317
300
  setTimeout(() => {
318
301
  self.extension.runtime.reload();
319
302
  }, 1000);
package/dist/build.js CHANGED
@@ -96,7 +96,7 @@ Manager.getLiveReloadPort = function () {
96
96
  process.env.BXM_LIVERELOAD_PORT = process.env.BXM_LIVERELOAD_PORT || 35729;
97
97
 
98
98
  // Return the port
99
- return process.env.BXM_LIVERELOAD_PORT;
99
+ return parseInt(process.env.BXM_LIVERELOAD_PORT);
100
100
  }
101
101
  Manager.prototype.getLiveReloadPort = Manager.getLiveReloadPort;
102
102
 
package/dist/content.js CHANGED
@@ -5,8 +5,9 @@ function Manager() {
5
5
  const self = this;
6
6
 
7
7
  // Properties
8
- self.affiliatizer = null;
9
8
  self.extension = null;
9
+ self.logger = null;
10
+ self.affiliatizer = null;
10
11
 
11
12
  // Return
12
13
  return self;
@@ -18,35 +19,17 @@ Manager.prototype.initialize = function () {
18
19
 
19
20
  return new Promise(function(resolve, reject) {
20
21
  // Properties
21
- self.affiliatizer = require('./lib/affiliatizer').initialize(self);
22
22
  self.extension = require('./lib/extension');
23
+ self.logger = new (require('./lib/logger-lite'))('content');
24
+ self.affiliatizer = require('./lib/affiliatizer').initialize(self);
23
25
 
24
26
  // Log
25
- self.log('Initialized!', self);
27
+ self.logger.log('Initialized!', self);
26
28
 
27
29
  // Return
28
30
  return resolve(self);
29
31
  });
30
32
  };
31
33
 
32
- // Setup logger
33
- ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
34
- Manager.prototype[method] = function() {
35
- // Get arguments
36
- const time = new Date().toLocaleTimeString('en-US', {
37
- hour12: false,
38
- hour: '2-digit',
39
- minute: '2-digit',
40
- second: '2-digit'
41
- });
42
-
43
- // Add prefix
44
- const args = [`[${time}] content:`, ...Array.from(arguments)];
45
-
46
- // Call the original console method
47
- console[method].apply(console, args);
48
- };
49
- });
50
-
51
34
  // Export
52
35
  module.exports = Manager;
@@ -7,9 +7,12 @@ const Manager = new (require('browser-extension-manager/background'));
7
7
  // Initialize
8
8
  Manager.initialize()
9
9
  .then(() => {
10
+ // Shortcuts
11
+ const { extension, logger } = Manager;
12
+
10
13
  // Do other initialization tasks here
11
14
  // ...
12
15
 
13
16
  // Log the initialization
14
- Manager.log('Initialized!');
17
+ logger.log('Initialized!');
15
18
  });
@@ -4,9 +4,12 @@ const Manager = new (require('browser-extension-manager/content'));
4
4
  // Initialize
5
5
  Manager.initialize()
6
6
  .then(() => {
7
+ // Shortcuts
8
+ const { extension, logger, affiliatizer } = Manager;
9
+
7
10
  // Do other initialization tasks here
8
11
  // ...
9
12
 
10
13
  // Log the initialization
11
- Manager.log('Initialized!');
14
+ logger.log('Initialized!');
12
15
  });
@@ -2,13 +2,16 @@
2
2
  const Manager = new (require('browser-extension-manager'));
3
3
 
4
4
  // Import themes
5
- const bootstrap = require('/node_modules/browser-extension-manager/dist/assets/themes/bootstrap/5.3.3/js/bootstrap.bundle.js');
5
+ window.bootstrap = require('/node_modules/browser-extension-manager/dist/assets/themes/bootstrap/5.3.3/js/bootstrap.bundle.js');
6
6
 
7
7
  // Initialize
8
8
  Manager.initialize(() => {
9
+ // Shortcuts
10
+ const { extension, logger } = Manager;
11
+
9
12
  // Do other initialization tasks here
10
13
  // ...
11
14
 
12
15
  // Log the initialization
13
- Manager.log('Initialized!');
16
+ logger.log('Initialized!');
14
17
  })
@@ -2,13 +2,16 @@
2
2
  const Manager = new (require('browser-extension-manager'));
3
3
 
4
4
  // Import themes
5
- const bootstrap = require('/node_modules/browser-extension-manager/dist/assets/themes/bootstrap/5.3.3/js/bootstrap.bundle.js');
5
+ window.bootstrap = require('/node_modules/browser-extension-manager/dist/assets/themes/bootstrap/5.3.3/js/bootstrap.bundle.js');
6
6
 
7
7
  // Initialize
8
8
  Manager.initialize(() => {
9
+ // Shortcuts
10
+ const { extension, logger } = Manager;
11
+
9
12
  // Do other initialization tasks here
10
13
  // ...
11
14
 
12
15
  // Log the initialization
13
- Manager.log('Initialized!');
16
+ logger.log('Initialized!');
14
17
  })
@@ -15,19 +15,29 @@ module.exports = function serve(complete) {
15
15
  // Log
16
16
  logger.log('Starting...');
17
17
 
18
- // Get the local URL
19
- const server = new WebSocket.Server({ port: Manager.getLiveReloadPort() })
18
+ try {
19
+ // Get the local URL
20
+ const server = new WebSocket.Server({ port: Manager.getLiveReloadPort() })
20
21
 
21
- // Log
22
- logger.log(`LiveReload server started on port ${Manager.getLiveReloadPort()}`);
22
+ // Log
23
+ logger.log(`LiveReload server started on port ${Manager.getLiveReloadPort()}`);
24
+
25
+ // Log connection
26
+ server.on('connection', (socket, request) => {
27
+ logger.log(`LiveReload client connected from local IP: ${request.socket.localAddress}`);
28
+ });
23
29
 
24
- // Log connection
25
- server.on('connection', (socket, request) => {
26
- logger.log(`LiveReload client connected from local IP: ${request.socket.localAddress}`);
27
- });
30
+ // Handle errors
31
+ server.on('error', (error) => {
32
+ logger.error('WebSocket error:', error);
33
+ });
28
34
 
29
- // Set server
30
- global.websocket = server;
35
+ // Set server
36
+ global.websocket = server;
37
+ } catch (error) {
38
+ // Log error
39
+ logger.error('Error starting LiveReload server:', error);
40
+ }
31
41
 
32
42
  // Complete
33
43
  return complete();
@@ -204,6 +204,12 @@ function getReplaceOptions() {
204
204
  extension: {},
205
205
  validRedirectHosts: ['itwcreativeworks.com'],
206
206
  settings: {
207
+ refreshNewVersion: {
208
+ enabled: false,
209
+ },
210
+ exitPopup: {
211
+ enabled: false,
212
+ },
207
213
  libraries: {
208
214
  firebase_app: {
209
215
  enabled: !!options.firebaseConfig.apiKey,
package/dist/index.js CHANGED
@@ -5,6 +5,11 @@ const WebManager = require('web-manager');
5
5
  function Manager() {
6
6
  const self = this;
7
7
 
8
+ // Properties
9
+ self.webManager = null;
10
+ self.extension = null;
11
+ self.logger = null;
12
+
8
13
  // Return
9
14
  return self;
10
15
  }
@@ -16,34 +21,16 @@ Manager.prototype.initialize = function (callback) {
16
21
  const configuration = JSON.parse('%%% webManagerConfiguration %%%');
17
22
 
18
23
  // Initiate the web manager
19
- self.manager = new WebManager();
24
+ self.webManager = new WebManager();
20
25
  self.extension = require('./lib/extension');
26
+ self.logger = new (require('./lib/logger-lite'))('popup');
21
27
 
22
28
  // Initialize
23
- self.manager.init(configuration, callback);
29
+ self.webManager.init(configuration, callback);
24
30
 
25
31
  // Return
26
- return self.manager;
32
+ return self.webManager;
27
33
  };
28
34
 
29
- // Setup logger
30
- ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
31
- Manager.prototype[method] = function() {
32
- // Get arguments
33
- const time = new Date().toLocaleTimeString('en-US', {
34
- hour12: false,
35
- hour: '2-digit',
36
- minute: '2-digit',
37
- second: '2-digit'
38
- });
39
-
40
- // Add prefix
41
- const args = [`[${time}] content:`, ...Array.from(arguments)];
42
-
43
- // Call the original console method
44
- console[method].apply(console, args);
45
- };
46
- });
47
-
48
35
  // Export
49
36
  module.exports = Manager;
@@ -1,7 +1,3 @@
1
- // Libraries
2
- const ext = require('./extension.js');
3
- const storage = ext.storage;
4
-
5
1
  // Suppported affiliates
6
2
  const map = [
7
3
  // Amazon
@@ -113,7 +109,11 @@ Affiliatizer.get = function () {
113
109
  return map;
114
110
  };
115
111
 
116
- Affiliatizer.initialize = async function (parent) {
112
+ Affiliatizer.initialize = async function (Manager) {
113
+ // Shortcuts
114
+ const { extension, logger } = Manager;
115
+ const { storage } = extension;
116
+
117
117
  // Parse the URL
118
118
  const url = new URL(window.location.href);
119
119
  const query = url.searchParams;
@@ -124,23 +124,23 @@ Affiliatizer.initialize = async function (parent) {
124
124
  // Check if the URL has the affiliatizerStatus parameter
125
125
  if (qsStatus === 'reset') {
126
126
  // Log
127
- parent.log('Resetting affiliatizer data...');
127
+ logger.log('Resetting affiliatizer data...');
128
128
 
129
129
  // Reset the data
130
130
  await storage.set({ affiliatizer: null });
131
131
  query.delete('affiliatizerStatus');
132
132
 
133
133
  // Log
134
- parent.log('Reset!');
134
+ logger.log('Reset!');
135
135
  } else if (qsStatus === 'block') {
136
136
  // Log
137
- parent.log('Affiliatizer is blocked.');
137
+ logger.log('Affiliatizer is blocked.');
138
138
 
139
139
  // Set affiliatizer to 'block' in storage
140
140
  await storage.set({ affiliatizer: 'block' });
141
141
  } else if (qsStatus === 'allow') {
142
142
  // Log
143
- parent.log('Affiliatizer is allowed.');
143
+ logger.log('Affiliatizer is allowed.');
144
144
 
145
145
  // Set affiliatizer to 'allow' in storage
146
146
  await storage.set({ affiliatizer: 'allow' });
@@ -152,7 +152,7 @@ Affiliatizer.initialize = async function (parent) {
152
152
 
153
153
  // Check if it's blocked
154
154
  if (status === 'block') {
155
- parent.log('Affiliatizer is blocked.');
155
+ logger.log('Affiliatizer is blocked.');
156
156
  return;
157
157
  }
158
158
 
@@ -162,7 +162,7 @@ Affiliatizer.initialize = async function (parent) {
162
162
  const id = item.id;
163
163
 
164
164
  // Log
165
- // parent.log('Checking for', id, item.match, 'in', url.hostname, '...');
165
+ // logger.log('Checking for', id, item.match, 'in', url.hostname, '...');
166
166
 
167
167
  // Check if the item matches
168
168
  if (!item.match.test(url.hostname)) {
@@ -172,7 +172,7 @@ Affiliatizer.initialize = async function (parent) {
172
172
  // Process
173
173
  storage.get((data) => {
174
174
  // Log
175
- parent.log('Matched', data);
175
+ logger.log('Matched', data);
176
176
 
177
177
  // Set the default data
178
178
  const now = new Date();
@@ -205,7 +205,7 @@ Affiliatizer.initialize = async function (parent) {
205
205
  }
206
206
 
207
207
  // Log
208
- parent.log('Redirecting...', newURL.toString());
208
+ logger.log('Redirecting...', newURL.toString());
209
209
 
210
210
  // Save to storage
211
211
  const newTimestamp = {
@@ -0,0 +1,34 @@
1
+ // Libraries
2
+
3
+ // Logger class
4
+ function Logger(name) {
5
+ const self = this;
6
+
7
+ // Properties
8
+ self.name = name;
9
+ }
10
+
11
+ // Loop through log, error, warn, and info and make methods that log to console with the name and time [xx:xx:xx] name: message
12
+ // Setup logger
13
+ ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
14
+ Logger.prototype[method] = function () {
15
+ const self = this;
16
+
17
+ // Get arguments
18
+ const time = new Date().toLocaleTimeString('en-US', {
19
+ hour12: false,
20
+ hour: '2-digit',
21
+ minute: '2-digit',
22
+ second: '2-digit'
23
+ });
24
+
25
+ // Add prefix
26
+ const args = [`[${time}] ${self.name}:`, ...Array.from(arguments)];
27
+
28
+ // Call the original console method
29
+ console[method].apply(console, args);
30
+ };
31
+ });
32
+
33
+ // Export
34
+ module.exports = Logger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-manager",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Browser Extension Manager dependency manager",
5
5
  "main": "dist/index.js",
6
6
  "exports": {