From 7c510bee57a11a2386655b286e2f23235774eb50 Mon Sep 17 00:00:00 2001 From: Mic Date: Thu, 24 Apr 2025 01:47:00 +0200 Subject: [PATCH] Add sanitizeChatGPTWebCustomData function and update usage in options. see #277 and #168 --- js/mzta-utils.js | 5 +++++ options/mzta-options.js | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index f94060c5..c6f95900 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -415,6 +415,11 @@ export function validateChatGPTWebCustomData(data) { return data.startsWith('/g/') || data == ''; } +export function sanitizeChatGPTWebCustomData(input) { + // Removes all characters that are not letters, numbers, dashes, or slashes + return input.replace(/[^\p{L}\p{N}\/-]+/gu, ''); +} + // The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js const insertHtml = function (replyHtml, fullBody_string) { diff --git a/options/mzta-options.js b/options/mzta-options.js index 3e0b433a..9f8e36a0 100644 --- a/options/mzta-options.js +++ b/options/mzta-options.js @@ -22,7 +22,7 @@ import { OpenAI } from '../js/api/openai.js'; import { Ollama } from '../js/api/ollama.js'; import { OpenAIComp } from '../js/api/openai_comp.js' import { GoogleGemini } from '../js/api/google_gemini.js'; -import { checkSparksPresence, isThunderbird128OrGreater, openTab, validateChatGPTWebCustomData } from '../js/mzta-utils.js'; +import { checkSparksPresence, isThunderbird128OrGreater, openTab, validateChatGPTWebCustomData, sanitizeChatGPTWebCustomData } from '../js/mzta-utils.js'; let taLog = new taLogger("mzta-options",true); let _isThunderbird128OrGreater = true; @@ -682,12 +682,23 @@ document.addEventListener('DOMContentLoaded', async () => { const btnChatGPTWeb_Tab = document.getElementById('btnChatGPTWeb_Tab'); btnChatGPTWeb_Tab.addEventListener('click', async () => { - let prefs_mod = await browser.storage.sync.get({chatgpt_web_model: ''}); + let prefs_mod = await browser.storage.sync.get({chatgpt_web_model: prefs_default.chatgpt_web_model, chatgpt_web_project: prefs_default.chatgpt_web_project, chatgpt_web_custom_gpt: prefs_default.chatgpt_web_custom_gpt}); + + let base_url = 'https://chatgpt.com'; let model_opt = ''; + let webproject_set = false; + if((prefs_mod.chatgpt_web_model != '') && (prefs_mod.chatgpt_web_model != undefined)){ model_opt = '?model=' + encodeURIComponent(prefs_mod.chatgpt_web_model).toLowerCase(); } - browser.tabs.create({ url: 'https://chatgpt.com/' + model_opt }); + if((prefs_mod.chatgpt_web_project != '') && (prefs_mod.chatgpt_web_project != undefined)){ + base_url += sanitizeChatGPTWebCustomData(prefs_mod.chatgpt_web_project); + webproject_set = true; + } + if(!webproject_set && (prefs_mod.chatgpt_web_custom_gpt != '') && (prefs_mod.chatgpt_web_custom_gpt != undefined)){ + base_url += sanitizeChatGPTWebCustomData(prefs_mod.chatgpt_web_custom_gpt); + } + browser.tabs.create({ url: base_url + model_opt }); }); browser.runtime.getPlatformInfo().then(info => {