Skip to content

Commit 400650a

Browse files
Merge pull request #6 from MrBlankCoding/Ai-Assistant
Ai assistant
2 parents f90d490 + 162e925 commit 400650a

File tree

9 files changed

+1209
-255
lines changed

9 files changed

+1209
-255
lines changed

src/GM/gm_api_registry.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,28 @@
243243

244244
_registerResources(enabled) {
245245
if (enabled.gmGetResourceText) {
246-
const fn = (name) => new Promise(resolve => {
246+
const fn = async (name) => {
247+
if (typeof name !== 'string' || name === '') {
248+
console.warn('GM_getResourceText: resource name must be a non-empty string');
249+
return '';
250+
}
247251
const text = this.resourceManager.getText(name);
248-
resolve(String(text || ''));
249-
});
252+
// Ensure we always return a string, never null or undefined
253+
return (text != null) ? String(text) : '';
254+
};
250255
window.GM_getResourceText = window.GM.getResourceText = fn;
251256
}
252257

253258
if (enabled.gmGetResourceURL) {
254-
const fn = (name) => new Promise(resolve => {
259+
const fn = async (name) => {
260+
if (typeof name !== 'string' || name === '') {
261+
console.warn('GM_getResourceURL: resource name must be a non-empty string');
262+
return '';
263+
}
255264
const url = this.resourceManager.getURL(name);
256-
resolve(String(url || ''));
257-
});
265+
// Ensure we always return a string, never null or undefined
266+
return (url != null) ? String(url) : '';
267+
};
258268
window.GM_getResourceURL = window.GM.getResourceURL = fn;
259269
}
260270
}
@@ -365,7 +375,7 @@
365375

366376
try {
367377
new URL(details.url);
368-
} catch (e) {
378+
} catch {
369379
console.error(`CodeTweak: GM_xmlhttpRequest failed due to an invalid URL: "${details.url}"`);
370380
if (details.onerror) {
371381
details.onerror(new TypeError(`Invalid URL: ${details.url}`));

0 commit comments

Comments
 (0)