using the exclusion list when getting tags from the AI. see #183
This commit is contained in:
parent
ae475cc99a
commit
b02dae5748
4 changed files with 57 additions and 7 deletions
|
|
@ -778,5 +778,13 @@
|
||||||
"prompt_add_tags_maxnum": {
|
"prompt_add_tags_maxnum": {
|
||||||
"message": "Limit the number of tags to",
|
"message": "Limit the number of tags to",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
},
|
||||||
|
"prefs_OptionText_add_tags_hide_exclusions": {
|
||||||
|
"message": "Hide excluded tags",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"prefs_OptionText_add_tags_hide_exclusions_Info": {
|
||||||
|
"message": "If checked, the tags that are present in the exclusion list will be hidden in the dialog.",
|
||||||
|
"description": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -220,6 +220,10 @@ switch (message.command) {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tag_excluded{
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
:root {
|
:root {
|
||||||
--dialog-bg-color: #2e2e2e;
|
--dialog-bg-color: #2e2e2e;
|
||||||
|
|
@ -229,7 +233,7 @@ switch (message.command) {
|
||||||
`;
|
`;
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
function createDialog(inputString, onSubmit) {
|
async function createDialog(inputString, onSubmit) {
|
||||||
// Create the dialog
|
// Create the dialog
|
||||||
const tags_dialog = document.createElement('dialog');
|
const tags_dialog = document.createElement('dialog');
|
||||||
tags_dialog.className = 'mzta_dialog';
|
tags_dialog.className = 'mzta_dialog';
|
||||||
|
|
@ -241,19 +245,47 @@ switch (message.command) {
|
||||||
// Parse the input string into labels
|
// Parse the input string into labels
|
||||||
const words = inputString.split(',').map(word => word.trim());
|
const words = inputString.split(',').map(word => word.trim());
|
||||||
|
|
||||||
|
console.log(" >>>>>>>>>>>>> words: " + JSON.stringify(words));
|
||||||
|
|
||||||
|
let prefs_tags = await browser.storage.sync.get({add_tags_hide_exclusions: false});
|
||||||
|
let prefs_excluded_tags = await browser.storage.local.get({add_tags_exclusions: []});
|
||||||
|
|
||||||
|
console.log(" >>>>>>>>>>>>> prefs_excluded_tags: " + JSON.stringify(prefs_excluded_tags));
|
||||||
|
|
||||||
|
// prefs_excluded_tags.add_tags_exclusions = ['recipient','test'];
|
||||||
|
|
||||||
|
const words_final = words.map(word => {
|
||||||
|
const isExcluded = prefs_excluded_tags.add_tags_exclusions.some(exclusion =>
|
||||||
|
word.includes(exclusion)
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
tag: word,
|
||||||
|
excluded: isExcluded ? 1 : 0
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(" >>>>>>>>>>>>> words_final: " + JSON.stringify(words_final));
|
||||||
|
|
||||||
// Create the form
|
// Create the form
|
||||||
const form = document.createElement('form');
|
const form = document.createElement('form');
|
||||||
|
|
||||||
words.forEach(word => {
|
words_final.forEach(word => {
|
||||||
const label = document.createElement('label');
|
const label = document.createElement('label');
|
||||||
label.style.display = 'block';
|
label.style.display = 'block';
|
||||||
const checkbox = document.createElement('input');
|
const checkbox = document.createElement('input');
|
||||||
checkbox.type = 'checkbox';
|
checkbox.type = 'checkbox';
|
||||||
checkbox.checked = true; // Checked by default
|
checkbox.checked = true; // Checked by default
|
||||||
checkbox.value = word;
|
checkbox.value = word.tag;
|
||||||
label.appendChild(checkbox);
|
label.appendChild(checkbox);
|
||||||
label.appendChild(document.createTextNode(` ${word}`));
|
label.appendChild(document.createTextNode(` ${word.tag}`));
|
||||||
form.appendChild(label);
|
if(!word.excluded || (word.excluded && !prefs_tags.add_tags_hide_exclusions)){
|
||||||
|
form.appendChild(label);
|
||||||
|
}
|
||||||
|
if(word.excluded){
|
||||||
|
label.className = 'tag_excluded';
|
||||||
|
checkbox.checked = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a div for buttons
|
// Add a div for buttons
|
||||||
|
|
@ -311,14 +343,14 @@ switch (message.command) {
|
||||||
|
|
||||||
tags_dialog.style.transform = 'translate(0, 0)';
|
tags_dialog.style.transform = 'translate(0, 0)';
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example usage
|
// Example usage
|
||||||
createDialog(message.tags, (selected) => {
|
return createDialog(message.tags, (selected) => {
|
||||||
console.log('Selected:', selected);
|
console.log('Selected:', selected);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.resolve(true);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -39,4 +39,5 @@ export const prefs_default = {
|
||||||
max_prompt_length: 30000, // max string length for prompt
|
max_prompt_length: 30000, // max string length for prompt
|
||||||
add_tags: false,
|
add_tags: false,
|
||||||
add_tags_maxnum: 3,
|
add_tags_maxnum: 3,
|
||||||
|
add_tags_hide_exclusions: false,
|
||||||
}
|
}
|
||||||
|
|
@ -284,6 +284,15 @@
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="add_tags_tr">
|
||||||
|
<td><span>__MSG_prefs_OptionText_add_tags_hide_exclusions__</span></td>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="add_tags_hide_exclusions" name="add_tags_hide_exclusions" class="option-input" />
|
||||||
|
__MSG_prefs_OptionText_add_tags_hide_exclusions_Info__
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:20em"><label>
|
<td style="width:20em"><label>
|
||||||
<span>__MSG_Debug__</span>
|
<span>__MSG_Debug__</span>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue