53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
$(window).on("load", function() {
|
|
var queryString = window.location.search;
|
|
var urlParams = new URLSearchParams(queryString);
|
|
var qValue = urlParams.get('q');
|
|
|
|
var myElement = $('#searchinput');
|
|
myElement.val(qValue);
|
|
|
|
var strongElement = $('#searchtextstrong');
|
|
strongElement.text(qValue);
|
|
|
|
$.ajax({
|
|
url: 'http://192.168.1.219:6431/api/v1/search', // The URL to send the request to
|
|
type: 'GET', // HTTP method (GET, POST, etc.)
|
|
dataType: 'json', // Expected data format from the server
|
|
success: function(response) {
|
|
// This function is called if the request is successful
|
|
console.log('Data received:', response);
|
|
|
|
$.each(response['activities'], function(key, value) {
|
|
console.error(key, value);
|
|
|
|
var resultHTML = `
|
|
<div class="result">
|
|
<div class="resulttop">
|
|
<div class="userdata">
|
|
<a href="#" title="User Avatar" target="_blank" class="useravatar"><img src="` + value['actor']['icon']['url'] + `" /></a>
|
|
<a href="#" title="User Label" target="_blank" class="userlabel">` + value['actor']['name'] + `</a>
|
|
<a href="` + value['actor']['url'] + `" title="User ID" target="_blank" class="userident">@` + value['actor']['preferredUsername'] + `@` + value['instance'] + `</a>
|
|
</div>
|
|
<div class="actions">
|
|
<ul>
|
|
<li><a href="` + value['id'] +`" title="Post URL"><img src="images/icon-link.png" /></a></li>
|
|
<li><a href="#" title="Expand post"><img src="images/icon-expand.png" /></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="resultbody">
|
|
` + value['content'] + `
|
|
</div>
|
|
<div class="resultbody">` + value['published'] +`</div>
|
|
</div>
|
|
`;
|
|
$(resultHTML).appendTo('#result_container');
|
|
});
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// This function is called if the request fails
|
|
console.error('Error:', error);
|
|
}
|
|
});
|
|
});
|