|
| 1 | +import logger from '../utils/logger.js'; |
1 | 2 | (function () { |
2 | 3 | 'use strict'; |
3 | 4 |
|
|
26 | 27 | try { |
27 | 28 | listener(name, oldValue, newValue, remote); |
28 | 29 | } catch (e) { |
29 | | - console.error('Error in value change listener:', e); |
| 30 | + logger.error('Error in value change listener:', e); |
30 | 31 | } |
31 | 32 | } |
32 | 33 | } |
|
36 | 37 |
|
37 | 38 | async setValue(name, value) { |
38 | 39 | if (typeof name !== 'string') { |
39 | | - console.warn('GM_setValue: name must be a string'); |
| 40 | + logger.warn('GM_setValue: name must be a string'); |
40 | 41 | return; |
41 | 42 | } |
42 | 43 | const resolvedValue = value instanceof Promise ? await value : value; |
|
46 | 47 |
|
47 | 48 | getValue(name, defaultValue) { |
48 | 49 | if (typeof name !== 'string') { |
49 | | - console.warn('GM_getValue: name must be a string'); |
| 50 | + logger.warn('GM_getValue: name must be a string'); |
50 | 51 | return defaultValue; |
51 | 52 | } |
52 | 53 | if (this.cache.has(name)) { |
|
64 | 65 |
|
65 | 66 | async getValueAsync(name, defaultValue) { |
66 | 67 | if (typeof name !== 'string') { |
67 | | - console.warn('GM.getValue: name must be a string'); |
| 68 | + logger.warn('GM.getValue: name must be a string'); |
68 | 69 | return defaultValue; |
69 | 70 | } |
70 | 71 | if (this.cache.has(name)) { |
|
84 | 85 |
|
85 | 86 | async deleteValue(name) { |
86 | 87 | if (typeof name !== 'string') { |
87 | | - console.warn('GM_deleteValue: name must be a string'); |
| 88 | + logger.warn('GM_deleteValue: name must be a string'); |
88 | 89 | return; |
89 | 90 | } |
90 | 91 | this.cache.delete(name); |
|
227 | 228 | const details = normalizeDetails(textOrDetails, titleOrOnDone, image); |
228 | 229 | this.bridge.call('notification', { details }).catch(() => {}); |
229 | 230 | } catch (e) { |
230 | | - console.warn(e.message); |
| 231 | + logger.warn(e.message); |
231 | 232 | } |
232 | 233 | }; |
233 | 234 | window.GM.notification = (textOrDetails, titleOrOnDone, image) => { |
|
244 | 245 | if (enabled.gmRegisterMenuCommand) { |
245 | 246 | const fn = (caption, onClick, accessKey) => { |
246 | 247 | if (typeof caption !== 'string' || typeof onClick !== 'function') { |
247 | | - console.warn( |
| 248 | + logger.warn( |
248 | 249 | 'GM_registerMenuCommand: Expected (string caption, function onClick, [string accessKey])' |
249 | 250 | ); |
250 | 251 | return null; |
|
266 | 267 | if (enabled.gmUnregisterMenuCommand) { |
267 | 268 | const fn = (commandId) => { |
268 | 269 | if (typeof commandId !== 'string') { |
269 | | - console.warn('GM_unregisterMenuCommand: Expected string commandId'); |
| 270 | + logger.warn('GM_unregisterMenuCommand: Expected string commandId'); |
270 | 271 | return; |
271 | 272 | } |
272 | 273 |
|
|
285 | 286 | if (enabled.gmGetResourceText) { |
286 | 287 | const syncFn = (name) => { |
287 | 288 | if (typeof name !== 'string' || name === '') { |
288 | | - console.warn('GM_getResourceText: resource name must be a string'); |
| 289 | + logger.warn('GM_getResourceText: resource name must be a string'); |
289 | 290 | return null; |
290 | 291 | } |
291 | 292 | const text = this.resourceManager.getText(name); |
|
298 | 299 | if (enabled.gmGetResourceURL) { |
299 | 300 | const syncFn = (name) => { |
300 | 301 | if (typeof name !== 'string' || name === '') { |
301 | | - console.warn('GM_getResourceURL: resource name must be a string'); |
| 302 | + logger.warn('GM_getResourceURL: resource name must be a string'); |
302 | 303 | return null; |
303 | 304 | } |
304 | 305 | const url = this.resourceManager.getURL(name); |
|
314 | 315 | if (enabled.gmAddStyle) { |
315 | 316 | const fn = (css) => { |
316 | 317 | if (css == null) { |
317 | | - console.warn('GM_addStyle: css must be a string'); |
| 318 | + logger.warn('GM_addStyle: css must be a string'); |
318 | 319 | return null; |
319 | 320 | } |
320 | 321 | const style = document.createElement('style'); |
|
353 | 354 | } |
354 | 355 |
|
355 | 356 | if (!parent || typeof parent.appendChild !== 'function' || typeof tag !== 'string') { |
356 | | - console.warn( |
| 357 | + logger.warn( |
357 | 358 | 'GM_addElement: parent must be a valid DOM node and tag must be a string' |
358 | 359 | ); |
359 | 360 | return null; |
|
385 | 386 | parent.appendChild(el); |
386 | 387 | return el; |
387 | 388 | } catch (err) { |
388 | | - console.error('GM_addElement: Failed to create or append element:', err); |
| 389 | + logger.error('GM_addElement: Failed to create or append element:', err); |
389 | 390 | return null; |
390 | 391 | } |
391 | 392 | }; |
|
428 | 429 |
|
429 | 430 | const supportedMethods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']; |
430 | 431 | if (!supportedMethods.includes(normalizedDetails.method)) { |
431 | | - console.warn(`GM_xmlhttpRequest: Unknown method "${normalizedDetails.method}"`); |
| 432 | + logger.warn(`GM_xmlhttpRequest: Unknown method "${normalizedDetails.method}"`); |
432 | 433 | } |
433 | 434 |
|
434 | 435 | // Always use cross-origin handler (via background script) to bypass CORS reliably |
435 | 436 | return this._handleCrossOriginXmlhttpRequest(normalizedDetails); |
436 | 437 | } catch (error) { |
437 | | - console.error( |
| 438 | + logger.error( |
438 | 439 | `CodeTweak: GM_xmlhttpRequest failed due to an invalid URL: "${details.url}"`, |
439 | 440 | error |
440 | 441 | ); |
|
501 | 502 | try { |
502 | 503 | callback(payload); |
503 | 504 | } catch (error) { |
504 | | - console.error(`GM_xmlhttpRequest ${callbackName} callback failed:`, error); |
| 505 | + logger.error(`GM_xmlhttpRequest ${callbackName} callback failed:`, error); |
505 | 506 | } |
506 | 507 | } |
507 | 508 |
|
|
540 | 541 | normalized.response = new TextEncoder().encode(serialized).buffer; |
541 | 542 | } |
542 | 543 | } catch (error) { |
543 | | - console.error('CodeTweak: Failed to normalize arraybuffer response.', error); |
| 544 | + logger.error('CodeTweak: Failed to normalize arraybuffer response.', error); |
544 | 545 | } |
545 | 546 | } |
546 | 547 |
|
|
559 | 560 | }); |
560 | 561 | } |
561 | 562 | } catch (error) { |
562 | | - console.error('CodeTweak: Failed to normalize blob response.', error); |
| 563 | + logger.error('CodeTweak: Failed to normalize blob response.', error); |
563 | 564 | } |
564 | 565 | } |
565 | 566 |
|
|
736 | 737 | } |
737 | 738 |
|
738 | 739 | if (enabled.gmLog) { |
739 | | - const fn = (...args) => console.log(...args); |
| 740 | + const fn = (...args) => logger.info(...args); |
740 | 741 | window.GM_log = window.GM.log = fn; |
741 | 742 | } |
742 | 743 | } |
|
0 commit comments