You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							49 lines
						
					
					
						
							1.2 KiB
						
					
					
				
			
		
		
	
	
							49 lines
						
					
					
						
							1.2 KiB
						
					
					
				const anchor_regex = /<a\s+([^>]*)href=['"]([^'"]+)['"]([^>]*)>/gi; | 
						|
 | 
						|
export function api(rel_path){ | 
						|
    return `${location.protocol}//${location.host.replace('5173','8080')}/api/${rel_path}`; | 
						|
} | 
						|
 | 
						|
export function get(url){ | 
						|
    return fetch(url,{ credentials:'include' }); | 
						|
} | 
						|
 | 
						|
export function drop(url){ | 
						|
    return fetch(url,{ | 
						|
        credentials:'include', | 
						|
        method:'DELETE' | 
						|
    }); | 
						|
} | 
						|
 | 
						|
export function patch(url,data){ | 
						|
    return fetch(url,{ | 
						|
        credentials : 'include', | 
						|
        method      : 'PATCH', | 
						|
        body        : JSON.stringify(data) | 
						|
    }); | 
						|
} | 
						|
 | 
						|
export function post(url,data){ | 
						|
    return fetch(url,{ | 
						|
        credentials : 'include', | 
						|
        method      : 'POST', | 
						|
        body        : JSON.stringify(data) | 
						|
    }); | 
						|
} | 
						|
 | 
						|
export function target(code){ | 
						|
    if (!code) return null; | 
						|
    let altered = code; | 
						|
 | 
						|
    let match; | 
						|
    while(match = anchor_regex.exec(code)) { | 
						|
        const orig = match[0]; | 
						|
        const href = match[2]; | 
						|
        if (orig.includes('target=')) continue; // if there is already a target: skip | 
						|
        if (!href.includes('://')) continue; // if this is a relative path: skip | 
						|
        const anchor = '<a target="_blank" '+orig.substring(3); | 
						|
        altered = altered.replaceAll(orig,anchor); | 
						|
    } | 
						|
 | 
						|
    return altered; | 
						|
} |