diff --git a/html/search.ejs b/html/search.ejs index f70e5a66..21b51fe5 100644 --- a/html/search.ejs +++ b/html/search.ejs @@ -510,7 +510,70 @@ Web - + <% +function isMathExpression(query) { + return /^[0-9\s\+\-\*\/\.\x]+$/.test(query); +} + +function evaluateMathExpression(expression) { + try { + return eval(expression); + } catch (error) { + return 'Invalid Expression'; + } +} + +function getCurrentDate() { + const now = new Date(); + return now.toLocaleDateString(); +} + +function getCurrentYear() { + return new Date().getFullYear(); +} + +function getTimeInTimezone(timezone) { + const now = new Date(); + const options = { timeZone: timezone, timeStyle: 'medium', hour12: false }; + return now.toLocaleTimeString('en-US', options); +} + +const query = q.toLowerCase().trim(); +let answer = ''; + +if (isMathExpression(query)) { + answer = evaluateMathExpression(query); +} else if (query.includes('date') || query.includes('what date is it')) { + answer = getCurrentDate(); +} else if (query.includes('year') || query.includes('what year is it')) { + answer = getCurrentYear(); +} else if (query.includes('what time is it in')) { + const timezone = query.split('what time is it in')[1].trim(); + try { + answer = getTimeInTimezone(timezone); + } catch (error) { + answer = 'Invalid Timezone'; + } +} else if (query.includes('what time is it')) { + answer = new Date().toLocaleTimeString(); +} else if (query.includes('day') || query.includes('what day is it')) { + const now = new Date(); + const options = { weekday: 'long' }; + answer = now.toLocaleDateString(undefined, options); +} +%> + +<% if (answer) { %> +
+

+ Answer to ur question +

+ + <%= answer %> + +
+<% } %> + <% const searchStrings = [ "suicide", "self harm", "self-harm", "support", "murder", "how to murder", "kill myself",