1// Function to get URL parameters 2function getUrlParameterOld(name) { 3 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 4 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 5 var results = regex.exec(location.search); 6 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); 7}; 8 9function ucwords(str) { 10 return str.toLowerCase().replace(/(^|\s)\S/g, function (firstLetter) { 11 return firstLetter.toUpperCase(); 12 }); 13} 14 15function getUrlParameter(name) { 16 17 // Get the URL 18 var currentUrl = window.location.href; 19 20 // Find the index of the question mark 21 var questionMarkIndex = currentUrl.indexOf('?'); 22 23 // Extract the URL before the question mark 24 var urlBeforeQuestionMark; 25 if (questionMarkIndex !== -1) { 26 urlBeforeQuestionMark = currentUrl.substring(0, questionMarkIndex); 27 if (name == "search") { 28 var queryString = currentUrl.substring(questionMarkIndex + 1); 29 var params = new URLSearchParams(queryString); 30 if (params.has('search')) { 31 searchParamValue = params.get('search'); 32 } else { 33 searchParamValue = ''; 34 } 35 return searchParamValue; 36 } 37 } else { 38 urlBeforeQuestionMark = currentUrl; 39 } 40 41 // Split the URL by '/' 42 var urlParts = urlBeforeQuestionMark.split('/'); 43 44 // If name is 'category', return the component at index 3 45 if (name === 'category') { 46 return ucwords(urlParts[3].replace('-', ' ')).replace('Vtubers','VTubers'); 47 } 48 49 // If name is 'page', return the component at index 4 50 if (name === 'pg') { 51 return urlParts[4]; 52 } 53 54 // If name is not 'category' or 'page', return null 55 return ""; 56} 57 58 59 60// Check if the 'category' parameter exists in the URL 61 62 63function loadCategories() { 64 $.ajax({
65 type: "GET", 66 url: '/api/chatterBot/crudMaster.php?action=getTags&appV=' + appV + '&platform=web', 67 success: function (data) { 68 var categoryOpts = ""; 69 // Iterate through the data and create HTML elements 70 categoryOpts += '<button type="button" class="btn btn-outline-dark categoryBtn mr-3 mb-3 btn-sm" data-id="99" style="display:none" id="searchCategoryBtn">Search Results</button>'; 71 for (var i = 0; i < data.data.length; i++) { 72 categoryOpts += '<button type="button" class="btn btn-outline-dark categoryBtn mr-3 mb-3 btn-sm" data-id="' + data.data[i].id + '">' + data.data[i].tag + '</button>'; 73 } 74 $('#categories').html(categoryOpts); 75 76 var categoryValue = getUrlParameter('category'); 77 var categoryBtn; 78 if (categoryValue !== '') { 79 //click the corresponding category btn 80 categoryBtn = $('#categories .categoryBtn').filter(function () { 81 return $(this).text().trim() === categoryValue; 82 }); 83 } else { 84 categoryBtn = $('#categories .categoryBtn[data-id="1"]'); 85 } 86 87 if (getUrlParameter("search") !== "") { 88 $("#searchQry").val(getUrlParameter("search")); 89 $("#searchQry").trigger("input"); 90 } else { 91 categoryBtn.click(); 92 } 93 94 95 } 96 97 }); 98} 99 100function changeUrlWithoutReload(newUrl) { 101 newUrl = newUrl.toLowerCase().replace(' ', '-'); 102 window.history.pushState({ path: newUrl }, '', newUrl); 103} 104 105function updatePaginationUI(totalPages, currentPage) { 106 var paginationContainer = $('#pagination-container'); 107 paginationContainer.empty(); 108 109 var paginationHTML = '<div class="d-flex flex-wrap mr-3">'; 110 111 112 var firstPage = Math.max(currentPage - 3, 1); 113 var lastPage = Math.min(currentPage + 3, totalPages); 114 115 116 // Add First Page icon 117 var disabled = ""; 118 119 var urlCategoryName = currentCategoryName.toLowerCase().replace(' ', '-'); 120 121 if (currentPage == 1) disabled = "disabled"; 122 var firstPageButton = '<a href="/' + urlCategoryName + '/1" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1 ' + disabled + '" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', 1)"><i class="ki ki-bold-double-arrow-back icon-xs"></i></a>'; 123 paginationHTML += firstPageButton; 124 125 // Add Previous Page icon 126 var previousPageButton = '<a href="/' + urlCategoryName + '/' + (currentPage - 1) + '" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1 ' + disabled + '" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', ' + (currentPage - 1) + ')"><i class="ki ki-bold-arrow-back icon-xs"></i></a>'; 127 paginationHTML += previousPageButton; 128 129 // Add -3, -2, -1 pages 130 for (var i = firstPage; i < currentPage; i++) { 131 var pageButton = '<a href="/' + urlCategoryName + '/' + i + '" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', ' + i + ')">' + i + '</a>'; 132 paginationHTML += pageButton; 133 } 134 135 // Add current page 136 var currentPageButton = '<a href="/' + urlCategoryName + '/' + currentPage + '" class="btn btn-icon btn-sm btn-light-primary active mr-2 my-1">' + currentPage + '</a>'; 137 paginationHTML += currentPageButton; 138 139 // Add +1, +2, +3 pages 140 for (var i = currentPage + 1; i <= lastPage; i++) { 141 var pageButton = '<a href="/' + urlCategoryName + '/' + i + '" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', ' + i + ')">' + i + '</a>'; 142 paginationHTML += pageButton; 143 } 144 145 // Add Next Page icon 146 disabled = ""; 147 if (currentPage == lastPage) disabled = "disabled"; 148 var nextPageButton = '<a href="/' + urlCategoryName + '/' + (currentPage + 1) + '" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1 ' + disabled + '" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', ' + (currentPage + 1) + ')"><i class="ki ki-bold-arrow-next icon-xs"></i></a>'; 149 paginationHTML += nextPageButton; 150 151 // Add Last Page icon 152 var lastPageButton = '<a href="/' + urlCategoryName + '/' + totalPages + '" class="btn btn-icon btn-sm btn-light-primary mr-2 my-1 ' + disabled + '" onclick="event.preventDefault();loadSearch(' + currentCategoryId + ', \'' + currentCategoryName + '\', ' + totalPages + ')"><i class="ki ki-bold-double-arrow-next icon-xs"></i></a>'; 153 paginationHTML += lastPageButton; 154 155 paginationHTML += "</div>"; 156 paginationContainer.append(paginationHTML); 157 158 159} 160 161 162var currentCategoryId; 163var currentCategoryName; 164function loadSearch(categoryId, categoryName, page = 0) { 165 //e.preventDefault(); 166 167 //console.log("loadSearchCalled"); 168 currentCategoryId = categoryId; 169 currentCategoryName = categoryName; 170 //if (page == 0 && pageUrl !== "") page = parseInt(pageUrl); 171 if (page == 0) { 172 var categoryValue = getUrlParameter('category'); 173 if (currentCategoryName != categoryValue) page = 1; 174 var pageUrl = getUrlParameter('pg'); 175 if (page == 0 && pageUrl !== "") page = parseInt(pageUrl); 176 if (page == 0) page = 1; 177 } 178 changeUrlWithoutReload('/' + categoryName + '/' + page); 179 $.ajax({
180 type: "GET", 181 url: '/api/chatterBot/crud.php?userId4Liked=S&pagination[perpage]=20&pagination[page]=' + page + '&appV=' + appV + '&platform=web&category=' + categoryId, 182 success: function (data) { 183 populateBotResults(data, page); 184 } 185 }); 186} 187 188function populateBotResults(data, page) { 189 // Clear existing content 190 $('#chatterBotList').empty(); 191 192 var dataHtml = '<div class="row">'; 193 //$('#chatterBotList').html('<div class="row">'); 194 // Get the template content 195 var agentCardTemplate = $('#agentCardTemplate').html(); 196 197 // Iterate through the data and create HTML elements 198 for (var i = 0; i < data.data.length; i++) { 199 var agent = data.data[i]; 200 201 var likedDisplay = 'none'; 202 var notLikedDisplay = ''; 203 if (agent.liked == 1) { 204 notLikedDisplay = 'none'; 205 likedDisplay = ''; 206 } 207 // Replace placeholders with actual values 208 var agentCardHtml = agentCardTemplate 209 .replace('${AGENT_NAME}', agent.agentName) 210 .replace('${TOTAL_LIKES}', agent.totalLikes) 211 .replace('${PROFILE_IMG}', baseUrl + 'api/chatterBot/' + agent.profileImg) 212 .replace('${notLiked}', notLikedDisplay) 213 .replace('${liked}', likedDisplay) 214 .split('${CHAT_URL}').join(agent.link); 215 216 // Append the agent card to the container 217 //$('#chatterBotList').append(agentCardHtml); 218 dataHtml += agentCardHtml; 219 220 // Check if we need to start a new row 221 if ((i + 1) % 4 === 0) { 222 //$('#chatterBotList').append('</div><div class="row">'); 223 dataHtml += '</div><div class="row">'; 224 } 225 } 226 dataHtml += '</div>'; 227 $('#chatterBotList').html(dataHtml); 228 //console.log(data.meta.pages); 229 var totalPages = data.meta.pages; 230 updatePaginationUI(totalPages, page); 231} 232 233var searchMode = 0; 234jQuery(document).ready(function () { 235 loadCategories(); 236 //loadSearch(1); 237 238 var previousButton = null; 239 240 $("#categories").on("click", ".categoryBtn", function (e) { 241 var clickedButton = $(e.target); 242 243 // Remove "active" class from the previous button, if any 244 if (previousButton !== null) { 245 previousButton.removeClass('active').addClass('btn-hover-bg-dark'); 246 } 247 248 // Set the new button as the previous button 249 previousButton = clickedButton; 250 251 // Toggle "active" class for the clicked button 252 clickedButton.toggleClass('btn-hover-bg-dark active'); 253 254 if (clickedButton.data("id") == 99) { 255 256 } else { 257 $("#searchQry").val(""); 258 // Load search for the clicked category 259 loadSearch(clickedButton.data("id"), clickedButton.text()); 260 $("#searchCategoryBtn").hide(); 261 $('#paginationCard').show(); 262 } 263 264 265 266 }); 267 268 269 $("#searchQry").on('input', function () { 270 271 var pageInUrl = getUrlParameter("pg"); 272 if (pageInUrl == "") pageInUrl = 1; 273 274 //if (currentCategoryId != 2) $('#categories .categoryBtn[data-id="2"]').click(); 275 var searchQuery = $(this).val(); 276 if (searchQuery.toString().length > 1) { 277 if (searchMode == 0) { 278 $("#searchCategoryBtn").show(); 279 $("#searchCategoryBtn").click(); 280 $('#paginationCard').hide(); 281 searchMode = 1; 282 } 283 284 var page = 1; 285 286 const searchParameters = searchQuery ? `?search=${searchQuery}` : ''; 287 288 changeUrlWithoutReload('/' + getUrlParameter("category") + '/' + pageInUrl + searchParameters); 289 290 $.ajax({
291 type: "GET", 292 url: '/api/chatterBot/crud.php?userId4Liked=S&pagination[perpage]=20&pagination[page]=1&platform=web&appV=' + appV + '&search=' + searchQuery, 293 success: function (data) { 294 populateBotResults(data, page); 295 } 296 }); 297 } else if (searchMode == 1) { 298 searchMode = 0; 299 //$("#searchQry").val(""); 300 //console.log("currentCategoryId:"+currentCategoryId); 301 var categoryValue = getUrlParameter('category'); 302 var categoryBtn; 303 if (categoryValue !== '') { 304 //click the corresponding category btn 305 categoryBtn = $('#categories .categoryBtn').filter(function () { 306 return $(this).text().trim() === categoryValue; 307 }); 308 } 309 changeUrlWithoutReload('/' + getUrlParameter("category") + '/' + pageInUrl); 310 //$('#categories .categoryBtn[data-id="' + currentCategoryId + '"]').click(); 311 categoryBtn.click(); 312 $("#searchCategoryBtn").hide(); 313 $('#paginationCard').show(); 314 } 315 }); 316 317});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.