correctly loading the special menus. see #183
This commit is contained in:
parent
205bd788d1
commit
f820a7c317
1 changed files with 27 additions and 7 deletions
|
|
@ -81,7 +81,7 @@ async function searchPrompt(allPrompts, tabId, tabType){
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Filter data based on the query
|
// Filter data based on the query
|
||||||
const filteredData = allPrompts.filter(item =>
|
let filteredData = allPrompts.filter(item =>
|
||||||
item.label.toLowerCase().includes(query)
|
item.label.toLowerCase().includes(query)
|
||||||
);
|
);
|
||||||
taLog.log("filteredData: " + JSON.stringify(filteredData));
|
taLog.log("filteredData: " + JSON.stringify(filteredData));
|
||||||
|
|
@ -96,10 +96,15 @@ async function searchPrompt(allPrompts, tabId, tabType){
|
||||||
// Prepend numbers to the first 10 items
|
// Prepend numbers to the first 10 items
|
||||||
// If add_tags is true and connection_type is not 'chatgpt_web' reserve 0 position for prompt_add_tags
|
// If add_tags is true and connection_type is not 'chatgpt_web' reserve 0 position for prompt_add_tags
|
||||||
let max_num_el = 10
|
let max_num_el = 10
|
||||||
|
let first_num_el = 0;
|
||||||
if(checkDoAddTags()){
|
if(checkDoAddTags()){
|
||||||
max_num_el = 9;
|
max_num_el = 9;
|
||||||
|
first_num_el = 1;
|
||||||
|
filteredData = ensurePromptAddTagsFirst(filteredData);
|
||||||
|
filteredData[0].numberPrepended = 'true';
|
||||||
|
filteredData[0].label = '0. ' + filteredData[0].label;
|
||||||
}
|
}
|
||||||
Array.from(filteredData).slice(0, max_num_el).forEach((item, index) => {
|
Array.from(filteredData).slice(first_num_el, max_num_el).forEach((item, index) => {
|
||||||
let number = (index < 9) ? (index + 1).toString() : '0';
|
let number = (index < 9) ? (index + 1).toString() : '0';
|
||||||
// Check if the number is already prepended to avoid duplication
|
// Check if the number is already prepended to avoid duplication
|
||||||
if (!item.numberPrepended) {
|
if (!item.numberPrepended) {
|
||||||
|
|
@ -111,11 +116,11 @@ async function searchPrompt(allPrompts, tabId, tabType){
|
||||||
// console.log(">>>>>>>>>>>>> filteredData: " + JSON.stringify(filteredData));
|
// console.log(">>>>>>>>>>>>> filteredData: " + JSON.stringify(filteredData));
|
||||||
|
|
||||||
// add the prompt_add_tags if add_tags is true and connection_type is not 'chatgpt_web'
|
// add the prompt_add_tags if add_tags is true and connection_type is not 'chatgpt_web'
|
||||||
if(checkDoAddTags()){
|
// if(checkDoAddTags()){
|
||||||
let number = '0';
|
// let number = '0';
|
||||||
let item = {label: `${number}. ${browser.i18n.getMessage('prompt_add_tags')}`, id: 'prompt_add_tags', numberPrepended: 'true'};
|
// let item = {label: `${number}. ${browser.i18n.getMessage('prompt_add_tags')}`, id: 'prompt_add_tags', numberPrepended: 'true'};
|
||||||
filteredData.unshift(item);
|
// filteredData.unshift(item);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Create a div for each filtered result
|
// Create a div for each filtered result
|
||||||
filteredData.forEach(item => {
|
filteredData.forEach(item => {
|
||||||
|
|
@ -280,4 +285,19 @@ function filterPromptsForTab(prompts_data, filtering){
|
||||||
|
|
||||||
function checkDoAddTags(){
|
function checkDoAddTags(){
|
||||||
return add_tags && (connection_type !== "chatgpt_web");
|
return add_tags && (connection_type !== "chatgpt_web");
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensurePromptAddTagsFirst(arr) {
|
||||||
|
// Find the index of the object with id "prompt_add_tags"
|
||||||
|
const index = arr.findIndex(item => item.id === "prompt_add_tags");
|
||||||
|
|
||||||
|
// If found and not already the first element
|
||||||
|
if (index !== -1 && index !== 0) {
|
||||||
|
// Remove it from its current position
|
||||||
|
const [promptAddTags] = arr.splice(index, 1);
|
||||||
|
// Add it to the beginning of the array
|
||||||
|
arr.unshift(promptAddTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue