mirror of
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git
synced 2026-01-27 03:29:55 +00:00
Makes going back to edit or switch out stuff easier since you don't need to erase the prefix anymore
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const HYP_REGEX = /<(?!e:|l:)[^,> ]*>?/g;
|
|
const HYP_TRIGGER = () => CFG.useHypernetworks && tagword.match(HYP_REGEX);
|
|
|
|
class HypernetParser extends BaseTagParser {
|
|
parse() {
|
|
// Show hypernetworks
|
|
let tempResults = [];
|
|
if (tagword !== "<" && tagword !== "<h:" && tagword !== "<hypernet:") {
|
|
let searchTerm = tagword.replace("<hypernet:", "").replace("<h:", "").replace("<", "");
|
|
tempResults = hypernetworks.filter(x => x.toLowerCase().includes(searchTerm)); // Filter by tagword
|
|
} else {
|
|
tempResults = hypernetworks;
|
|
}
|
|
|
|
// Add final results
|
|
let finalResults = [];
|
|
tempResults.forEach(t => {
|
|
let result = new AutocompleteResult(t.trim(), ResultType.hypernetwork)
|
|
result.meta = "Hypernetwork";
|
|
finalResults.push(result);
|
|
});
|
|
|
|
return finalResults;
|
|
}
|
|
}
|
|
|
|
async function load() {
|
|
if (hypernetworks.length === 0) {
|
|
try {
|
|
hypernetworks = (await readFile(`${tagBasePath}/temp/hyp.txt`)).split("\n")
|
|
.filter(x => x.trim().length > 0) //Remove empty lines
|
|
.map(x => x.trim()); // Remove carriage returns and padding if it exists
|
|
} catch (e) {
|
|
console.error("Error loading hypernetworks.txt: " + e);
|
|
}
|
|
}
|
|
}
|
|
|
|
function sanitize(tagType, text) {
|
|
if (tagType === ResultType.hypernetwork) {
|
|
return `<hypernet:${text}:${CFG.extraNetworksDefaultMultiplier}>`;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
PARSERS.push(new HypernetParser(HYP_TRIGGER));
|
|
|
|
// Add our utility functions to their respective queues
|
|
QUEUE_FILE_LOAD.push(load);
|
|
QUEUE_SANITIZE.push(sanitize); |