function urltitle(description, id) { // Trim the description to 30 characters let title = description.substring(0, 30); // Replace specific characters with a hyphen title = title.replace(/['"&]/g, ''); title = title.replace(/[^A-Za-z0-9\-_]/g, '-'); // Remove consecutive hyphens title = title.replace(/--+/g, '-'); // Remove leading and trailing hyphens title = title.replace(/^-+|-+$/g, ''); // Convert ID to hexadecimal let hexString = parseInt(id).toString(16); // Combine title and hexString return title + '-' + hexString; } function doSearch() { var term = $('#apa-search-text').val(); if (term.length < 1) return; sessionStorage.setItem("search_word", term); $.ajax({ url: `https://51ce-74-80-248-93.ngrok-free.app/example/${escape(term)}`, dataType: 'json', headers: { 'ngrok-skip-browser-warning': 'true' }, success: function (data) { //debugger; var $parent = $('#apa-search div.results'); if ($parent.is(':visible')) { $parent.html(''); $parent.hide(); } $parent.append('

Search results for ' + term + '

'); var $ul = $(''); for (var i in data) { var link = 'https://www.marks4antiques.com/apa/' + data[i].link; var $l = $('
  • '); // linode var pid = btoa(data[i].id + ',max'); var phoid = data[i].image_key ? data[i].image_key : data[i].photo; $l.append('' + data[i].description.substring(0, 30) + ''); $l.append('' + (data[i].description.substring(0, 30)) + ''); $l.append(''); $l.append('[more like this]'); $l.appendTo($ul); } $parent.append($ul); $parent.slideDown('fast'); }, error: function (err) { alert("An error occurred. Please try again."); } }); } $('#apa-search input').on('keyup', function (e) { if (e.keyCode == 13) doSearch(); }); $('#apa-search button').on('click', function () { doSearch(); });