[feat] regex flags, fix display
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { language } from "src/lang";
|
||||
import { alertConfirm } from "src/ts/alert";
|
||||
import type { customscript } from "src/ts/storage/database";
|
||||
import Check from "../Others/Check.svelte";
|
||||
|
||||
export let value:customscript
|
||||
export let onRemove: () => void = () => {}
|
||||
@@ -26,10 +27,10 @@
|
||||
</button>
|
||||
</div>
|
||||
{#if open}
|
||||
<div class="seperator">
|
||||
<div class="seperator p-2">
|
||||
<span class="text-neutral-200 mt-6">{language.name}</span>
|
||||
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.comment}>
|
||||
<span class="text-neutral-200 mt-4">Type</span>
|
||||
<span class="text-neutral-200 mt-4">Modification Type</span>
|
||||
<select class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.type}>
|
||||
<option value="editinput">{language.editInput}</option>
|
||||
<option value="editoutput">{language.editOutput}</option>
|
||||
@@ -40,6 +41,18 @@
|
||||
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.in}>
|
||||
<span class="text-neutral-200 mt-6">OUT:</span>
|
||||
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.out}>
|
||||
{#if value.ableFlag}
|
||||
<span class="text-neutral-200 mt-6">FLAG:</span>
|
||||
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.flag}>
|
||||
{/if}
|
||||
<div class="flex items-center mt-4">
|
||||
<Check bind:check={value.ableFlag} onChange={() => {
|
||||
if(!value.flag){
|
||||
value.flag = 'g'
|
||||
}
|
||||
}}/>
|
||||
<span>Custom Flag</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -35,9 +35,6 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
|
||||
export async function ParseMarkdown(data:string, char:(character | groupChat) = null, mode:'normal'|'back' = 'normal') {
|
||||
if(char && char.type !== 'group'){
|
||||
if(char.customscript){
|
||||
data = processScript(char, data, 'editdisplay')
|
||||
}
|
||||
if(char.additionalAssets){
|
||||
for(const asset of char.additionalAssets){
|
||||
const assetPath = await getFileSrc(asset[1])
|
||||
@@ -51,6 +48,9 @@ export async function ParseMarkdown(data:string, char:(character | groupChat) =
|
||||
}
|
||||
}
|
||||
}
|
||||
if(char){
|
||||
data = processScript(char, data, 'editdisplay')
|
||||
}
|
||||
return DOMPurify.sanitize(convertor.makeHtml(data), {
|
||||
ADD_TAGS: ["iframe"],
|
||||
ADD_ATTR: ["allow", "allowfullscreen", "frameborder", "scrolling"],
|
||||
|
||||
@@ -63,7 +63,6 @@ export function groupOrder(chars:GroupOrder[], input:string):GroupOrder[] {
|
||||
for (const word of words) {
|
||||
for (let char of chars) {
|
||||
const charNameChunks = getWords(findCharacterbyId(char.id).name)
|
||||
console.log(charNameChunks)
|
||||
|
||||
if (charNameChunks.includes(word)) {
|
||||
order.push(char);
|
||||
@@ -96,8 +95,11 @@ export function groupOrder(chars:GroupOrder[], input:string):GroupOrder[] {
|
||||
}
|
||||
|
||||
function getWords(data:string){
|
||||
const matches = data.match(/\b\w+\b/gmi)
|
||||
const matches = data.split(/\n| /g)
|
||||
let words:string[] = []
|
||||
if(!matches){
|
||||
return [data]
|
||||
}
|
||||
for(const match of matches){
|
||||
words.push(match.toLocaleLowerCase())
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript)
|
||||
for (const script of scripts){
|
||||
if(script.type === mode){
|
||||
const reg = new RegExp(script.in,'g')
|
||||
const reg = new RegExp(script.in, script.ableFlag ? script.flag : 'g')
|
||||
const outScript = script.out
|
||||
if(outScript.startsWith('@@') && reg.test(data)){
|
||||
if(outScript.startsWith('@@emo ')){
|
||||
|
||||
@@ -267,10 +267,12 @@ export function setDatabase(data:Database){
|
||||
|
||||
|
||||
export interface customscript{
|
||||
comment: string;
|
||||
in:string
|
||||
out:string
|
||||
type:string
|
||||
comment: string;
|
||||
in:string
|
||||
out:string
|
||||
type:string
|
||||
flag?:string
|
||||
ableFlag?:boolean
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user