Files
webgui/emhttp/plugins/dynamix/MyFavorites.page
Zack Spear 922df132b9 refactor: enhance MyFavorites.page functionality and error handling
- Added validation for the page parameter in the delPage function to prevent invalid inputs.
- Improved error handling in the AJAX call for deleting favorites, logging errors to the console.
- Streamlined the process of appending the trash icon for removing favorites, ensuring better handling of invalid page names.

[COMPLETE] Should I continue to the next item?
2025-05-27 16:34:59 -07:00

58 lines
1.4 KiB
Plaintext

Menu="Favorites"
Type="menu"
Title="My Favorites"
Tag="heart"
---
<script>
function delPage(page) {
if (!page || typeof page !== 'string') {
console.error('Invalid page parameter');
return;
}
$.post('/webGui/include/MyFavorites.php', {
action: 'del',
page: page,
})
.done(function() {
refresh();
})
.fail(function(xhr, status, error) {
console.error('Failed to remove favorite:', error);
});
}
$(function(){
const $panels = $('.Panel');
if ($panels.length === 0) {
$('#nofavs').show();
return;
}
$panels.each(function(){
const href = $(this).find('a').prop('href');
const urlParts = href.split('/');
const page = urlParts[urlParts.length - 1];
if (!page || page.includes('..') || page.includes('/')) {
console.warn('Invalid page extracted from href:', href);
return;
}
const trashIcon = $('<i class="fa fa-trash-o favo" title="_(Remove from favorites)_"></i>');
trashIcon.on('click', function(e) {
e.preventDefault();
delPage(page);
return false;
});
$(this).find('span').append(trashIcon);
$(this).hover(function() {
$(this).find('i.favo').toggle();
});
});
});
</script>
<h3 id="nofavs" class="text-center" style="display: none">
_(No favorites available)_
</h3>