‘ + finalResponse); // javascript ajax typewriter
}
}
function generateUUID() {
return ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx’.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0, v = c === ‘x’ ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
// Function to get or generate a session-based UUID
// Function to get or generate a session-based UUID with a prefix
var uuid = ‘tbdx’;
function getSessionUUID(appName) {
// alert(‘getSessionUUID’);
const uuidKey = ‘session_uuid_’ + encodeURIComponent(appName);
// Check if the UUID is already in session storage
uuid = sessionStorage.getItem(uuidKey);
if (!uuid) {
// Generate a new UUID if not found in session storage
uuid = generateUUID();
sessionStorage.setItem(uuidKey, uuid);
}
return uuid;
}
function getLastFourQueriesString(appName) {
const key = ‘queries_’ + encodeURIComponent(appName);
let queries = sessionStorage.getItem(key);
if (queries) {
try {
// Parse stored JSON string into an array
queries = JSON.parse(queries);
} catch (e) {
console.error(‘Error parsing queries from session storage:’, e);
queries = [null, null, null, null];
}
} else {
queries = [null, null, null, null]; // Default if no queries are found
}
// Convert array to a string with elements separated by ‘*’
return queries.filter(q => q !== null).join(‘*’);
}
// Function to add a new query and maintain only the last 4 queries
function addQuery(appName, newQuery) {
const key = ‘queries_’ + encodeURIComponent(appName);
let queries = getLastFourQueriesString(appName).split(‘*’);
// Add new query and ensure only the last 4 queries are kept
queries.unshift(newQuery);
queries = queries.slice(0, 4);
// Store updated queries back in session storage
sessionStorage.setItem(key, JSON.stringify(queries));
}
function createChatEnvironment(question){
// alert(‘createChatEnvironment’);
// debugger;
question = blpQS(“q”);
// alert(‘BLP_URL:nnhttp://www.islamicity.org/106871/yemen-strike-gaza-aid-dispute-and-iran-us-escalation-lead-global-headlines/’);
question = blpReplace(question,’delivery=frontend’,”);
const element = document.getElementById(‘results’);
doSomething(question);
html = ‘CHATILMÂ Â (IslamiCity AI) Results
Please wait while Chat ILM processing your question…
‘;
element.innerHTML = html;
}
var lastQuestion = ”;
var lastAnswer = ”;
function doSomething(question){
// alert(‘Hello from doSometihng function. I was called by createChatEnvironment to handle this question:nn’ + question);
// $(‘#results’).html(‘Please wait while Chat ILM processing your question…

‘);
const appName = ‘/hadith/search’; // Pass your application name as a prefix
uuid = getSessionUUID(appName);
if ( lastQuestion ){
addQuery(appName, lastQuestion + ‘@@@’ + lastAnswer);
}
const lastFourQueriesString = getLastFourQueriesString(appName);
getChatILMResults_STEP2(appName,question,uuid,lastFourQueriesString);
}
function getChatILMResults_STEP2(appName,question,uuid,lastFourQueriesString) {
url = ‘https://www.islamicity.org/quransearch/getChatILM.php’;
// debugger;
// alert(‘url:’ + url);
// set POST DATA
if ( !lastFourQueriesString) {
lastFourQueriesString = [];
}
postData = {
question:question,
uuid:uuid,
lastFourQueriesString:lastFourQueriesString,
file:”index.php”,
appName:appName,
}
// alert(‘posting this question: ‘ + question);
$.post(url, postData)
.done(function(response){
// alert(‘RESPONSE:nn’+response);
// // // debugger;
// debugger;
if ( blpContains(response,'[error]’)) {
chatIlMResponse = blpGetInBetween(response,'[error]’,'[/error]’);
//alert(‘ERROR:nn’+msg);
} else {
chatIlMResponse = blpGetInBetween(response,'[success]’,'[/success]’);
// alert(‘SUCCESS:nn’+msg);
}
lastQuestion = question;
lastAnswer = blpLeftOf(chatIlMResponse,'[debug]’);
let finalResponse = chatIlMResponse;
finalResponse = blpReplace(finalResponse,'[debug]’);
finalResponse = ” + finalResponse + ”;
//finalResponse += ‘Disclaimer:This reply was delivered by CHAT ILM (IslamiCity AI Engine) which may occasionally generate incorrect information. Please verify!.
‘;
finalResponse += ‘
Disclaimer:The above response generated by ChatILM ( an AI Engine developed by IslamiCity). This response utilizes only the Quran and Hadith sources. For a more comprehensive coverage that is beyond Quran And Hadith context, please visit Islamicity’s ChatILM Home Page!
‘;
if ( false ) {
// type writer
const element = document.getElementById(‘results’);
const speed = 10; // Adjust typing speed (in milliseconds)
typeWriter(element, finalResponse, speed);
} else {
//$(‘#results’).html(finalResponse); // javascript ajax typewriter
$(‘#results’).html(‘
CHAT ILM RESPONSE
‘ + finalResponse); // javascript ajax typewriter
}
if ( blpContains(appName,’Hadith’)) {
} else {
const baseUrl = ‘https://www.islamicity.org/quransearch/’;
const newUrl = `${baseUrl}index.php?q=`+encodeURIComponent(window.document.getElementById(“q”).value);
window.history.replaceState({}, ”, newUrl);
}
}
);
}
loading…
Advanced options

