Refactor get_task and get_calendar_event handling to improve clarity and consistency; update _ok_sparks logic for better state management. see #333
This commit is contained in:
parent
8b7b0efc00
commit
ac98621d0c
2 changed files with 26 additions and 15 deletions
|
|
@ -45,6 +45,7 @@ var original_html = '';
|
|||
var modified_html = '';
|
||||
|
||||
let _process_incoming = false;
|
||||
let _sparks_presence = false;
|
||||
|
||||
let prefs_init = {};
|
||||
await reload_pref_init();
|
||||
|
|
@ -54,8 +55,8 @@ taWorkingStatus.taLog = taLog;
|
|||
|
||||
let special_prompts_ids = getActiveSpecialPromptsIDs({
|
||||
addtags: prefs_init.add_tags,
|
||||
get_calendar_event: await doGetSparkFeature(prefs_init.get_calendar_event),
|
||||
get_task: await doGetSparkFeature(prefs_init.get_task),
|
||||
get_calendar_event: doGetSparkFeature(prefs_init.get_calendar_event),
|
||||
get_task: doGetSparkFeature(prefs_init.get_task),
|
||||
is_chatgpt_web: (prefs_init.connection_type === "chatgpt_web")
|
||||
});
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ function preparePopupMenu(tab) {
|
|||
}
|
||||
|
||||
async function _reload_menus() {
|
||||
let prefs_reload = await browser.storage.sync.get({add_tags: prefs_default.add_tags, get_calendar_event: prefs_default.get_calendar_event, connection_type: prefs_default.connection_type});
|
||||
let prefs_reload = await browser.storage.sync.get({add_tags: prefs_default.add_tags, get_calendar_event: prefs_default.get_calendar_event, get_task: prefs_default.get_task, connection_type: prefs_default.connection_type});
|
||||
let getCalendarEvent = doGetSparkFeature(prefs_reload.get_calendar_event);
|
||||
let getTask = doGetSparkFeature(prefs_reload.get_task);
|
||||
const special_prompts_ids = getActiveSpecialPromptsIDs({
|
||||
|
|
@ -629,17 +630,18 @@ function checkScreenDimensions(prefs){
|
|||
return prefs;
|
||||
}
|
||||
|
||||
async function doGetSparkFeature(spark_feature_active) {
|
||||
function doGetSparkFeature(spark_feature_active) {
|
||||
if(spark_feature_active) {
|
||||
return (await checkSparksPresence() == 1);
|
||||
return (_sparks_presence == 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function reload_pref_init(){
|
||||
prefs_init = await browser.storage.sync.get({do_debug: prefs_default.do_debug, add_tags: prefs_default.add_tags, get_calendar_event: prefs_default.get_calendar_event, connection_type: prefs_default.connection_type, add_tags_auto: prefs_default.add_tags_auto, add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_auto_only_inbox: prefs_default.add_tags_auto_only_inbox, spamfilter: prefs_default.spamfilter, spamfilter_threshold: prefs_default.spamfilter_threshold, dynamic_menu_force_enter: prefs_default.dynamic_menu_force_enter, add_tags_context_menu: prefs_default.add_tags_context_menu, spamfilter_context_menu: prefs_default.spamfilter_context_menu});
|
||||
prefs_init = await browser.storage.sync.get({do_debug: prefs_default.do_debug, add_tags: prefs_default.add_tags, get_calendar_event: prefs_default.get_calendar_event, get_task: prefs_default.get_task, connection_type: prefs_default.connection_type, add_tags_auto: prefs_default.add_tags_auto, add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_auto_only_inbox: prefs_default.add_tags_auto_only_inbox, spamfilter: prefs_default.spamfilter, spamfilter_threshold: prefs_default.spamfilter_threshold, dynamic_menu_force_enter: prefs_default.dynamic_menu_force_enter, add_tags_context_menu: prefs_default.add_tags_context_menu, spamfilter_context_menu: prefs_default.spamfilter_context_menu});
|
||||
_process_incoming = prefs_init.add_tags_auto || prefs_init.spamfilter;
|
||||
_sparks_presence = await checkSparksPresence();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ let connection_type = 'chatgpt_web';
|
|||
let add_tags = false;
|
||||
let get_calendar_event = false;
|
||||
let get_task = false;
|
||||
let _ok_sparks = false;
|
||||
let tabType;
|
||||
let num_special_menu_items = 0;
|
||||
|
||||
|
|
@ -47,6 +48,11 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
add_tags = prefs.add_tags;
|
||||
get_calendar_event = prefs.get_calendar_event;
|
||||
get_task = prefs.get_task;
|
||||
_ok_sparks = await checkSparksPresence() == 1;
|
||||
console.log(">>>>>>>>>>>>>>>>> add_tags: " + add_tags);
|
||||
console.log(">>>>>>>>>>>>>>>>> get_calendar_event: " + get_calendar_event);
|
||||
console.log(">>>>>>>>>>>>>>>>> get_task: " + get_task);
|
||||
console.log(">>>>>>>>>>>>>>>>> _ok_sparks: " + _ok_sparks);
|
||||
searchPrompt(active_prompts, tabId, tabType);
|
||||
i18n.updateDocument();
|
||||
|
||||
|
|
@ -121,17 +127,18 @@ async function searchPrompt(allPrompts, tabId, tabType){
|
|||
let do_get_calendar_event = checkDoCalendarEvent();
|
||||
let do_get_task = checkDoTask();
|
||||
|
||||
// console.log(">>>>>>>>>>> do_add_tags: " + do_add_tags);
|
||||
// console.log(">>>>>>>>>>> do_get_calendar_event: " + do_get_calendar_event);
|
||||
// console.log(">>>>>>>>>>> filteredData: " + JSON.stringify(filteredData));
|
||||
console.log(">>>>>>>>>>> do_add_tags: " + do_add_tags);
|
||||
console.log(">>>>>>>>>>> do_get_calendar_event: " + do_get_calendar_event);
|
||||
console.log(">>>>>>>>>>> do_get_task: " + do_get_task);
|
||||
console.log(">>>>>>>>>>> filteredData: " + JSON.stringify(filteredData));
|
||||
|
||||
num_special_menu_items = (do_add_tags ? 1 : 0) + (do_get_calendar_event ? 1 : 0) + (do_get_task ? 1 : 0);
|
||||
// console.log(">>>>>>>>>>>> num_special_menu_items: " + num_special_menu_items);
|
||||
if(num_special_menu_items > 0){
|
||||
max_num_el -= num_special_menu_items;
|
||||
first_num_el = num_special_menu_items;
|
||||
// console.log(">>>>>>>>>>>>> max_num_el: " + max_num_el);
|
||||
// console.log(">>>>>>>>>>>>> first_num_el: " + first_num_el);
|
||||
console.log(">>>>>>>>>>>>> max_num_el: " + max_num_el);
|
||||
console.log(">>>>>>>>>>>>> first_num_el: " + first_num_el);
|
||||
if(do_add_tags){
|
||||
filteredData = ensurePromptAddTagsFirst(filteredData);
|
||||
if (!filteredData[0].numberPrepended) {
|
||||
|
|
@ -157,6 +164,8 @@ async function searchPrompt(allPrompts, tabId, tabType){
|
|||
}
|
||||
}
|
||||
|
||||
console.log(">>>>>>>>>>> filteredData after special items check: " + JSON.stringify(filteredData));
|
||||
|
||||
Array.from(filteredData).slice(first_num_el, max_num_el).forEach((item, index) => {
|
||||
let number = (index + first_num_el).toString();
|
||||
// Check if the number is already prepended to avoid duplication
|
||||
|
|
@ -337,11 +346,11 @@ function checkDoAddTags(){
|
|||
}
|
||||
|
||||
function checkDoCalendarEvent(){
|
||||
return get_calendar_event && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && (checkSparksPresence() == 1);
|
||||
return get_calendar_event && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && _ok_sparks;
|
||||
}
|
||||
|
||||
function checkDoTask(){
|
||||
return get_task && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && (checkSparksPresence() == 1);
|
||||
return get_task && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && _ok_sparks;
|
||||
}
|
||||
|
||||
function ensurePromptAddTagsFirst(arr) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue