var all_plugins = undefined; var plugin_arr = []; var current_array = []; var current_plugin_requirePath = undefined; const language_selection = $('#language'); const plugin_search = $('#plugin'); const search_results = $('#search-results'); fetch('/all_plugins').then(res => res.json()).then(all => { all_plugins = all; for(let lang in all){ language_selection.append(``); plugin_arr = plugin_arr.concat(all[lang]); } }); const display_search = (arr) => { search_results.hide(); search_results.html(''); arr.slice(0, 15).forEach(plugin => { search_results.append(`
`) }); search_results.show(); } plugin_search.focus(e => { if(!all_plugins) return; if(language_selection.val()){ current_array = all_plugins[language_selection.val()]; }else{ current_array = plugin_arr; } display_search(current_array); }); plugin_search.keyup(e => { display_search(current_array.filter(plg => plg.name.toLowerCase().includes(plugin_search.val()))); }); $('#clear-search').click(e => { search_results.hide(); plugin_search.val(''); plugin_search.attr('data-require', ''); }) const test_plugin = (btn) => { const ele = $(btn); current_plugin_requirePath = ele.attr('data-require'); plugin_search.attr('data-require', current_plugin_requirePath); plugin_search.val(ele.text().split('/')[1]); search_results.hide(); } const popularNovels = () => { if(!current_plugin_requirePath) return; $('#popularNovels .spinner-border').show(); fetch(`/popularNovels/`,{ method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({"pluginRequirePath": current_plugin_requirePath}), }) .then(res => res.json()) .then(novels => { const novel_list = $('#popularNovels .novel-list'); novel_list.html(''); if(novels.error){ novel_list.html(novels.error); }else{ novels.forEach(novel => { novel_list.append(`
No cover found
name
${novel.name?.slice(0, 50)}
Copy
url
${novel.url?.slice(0, 50)}
Copy
cover
${novel.cover?.slice(0, 50)}
Copy
`); }) } $('#popularNovels .spinner-border').hide(); }); } const searchNovels = () => { const searchTerm = $('#searchNovels input').val(); if(!current_plugin_requirePath || !searchTerm) return; $('#searchNovels .spinner-border').show(); fetch(`/searchNovels/`,{ method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({"pluginRequirePath": current_plugin_requirePath, "searchTerm": searchTerm}), }) .then(res => res.json()) .then(novels => { const novel_list = $('#searchNovels .novel-list'); novel_list.html(''); if(novels.error){ novel_list.html(novels.error); }else{ novels.forEach(novel => { novel_list.append(`
No cover found
name
${novel.name?.slice(0, 50)}
Copy
url
${novel.url?.slice(0, 50)}
Copy
cover
${novel.cover?.slice(0, 50)}
Copy
`); }) } $('#searchNovels .spinner-border').hide(); }); } const parseNovelAndChapters = () => { const novelUrl = $('#parseNovelAndChapters input').val(); if(!current_plugin_requirePath || !novelUrl) return; $('#parseNovelAndChapters .spinner-border').show(); fetch(`/parseNovelAndChapters/`,{ method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({"pluginRequirePath": current_plugin_requirePath, "novelUrl": novelUrl}), }) .then(res => res.json()) .then(sourceNovel => { const novel_item = $('#parseNovelAndChapters .novel-list .novel-item'); novel_item.html(` No cover found
name
${sourceNovel.name?.slice(0, 50)}
Copy
url
${sourceNovel.url?.slice(0, 50)}
Copy
cover
${sourceNovel.cover?.slice(0, 50)}
Copy
summary
${sourceNovel.summary?.slice(0, 50)}
Copy
author
${sourceNovel.author}
Copy
artist
${sourceNovel.artist}
Copy
status
${sourceNovel.status}
Copy
genres
${sourceNovel.genres?.slice(0, 50)}
Copy
`); if(sourceNovel.error){ novel_item.html(sourceNovel.error); }else{ const chapter_list = $('#parseNovelAndChapters .chapter-list'); chapter_list.html(''); sourceNovel.chapters.forEach(chapter => { chapter_list.append(`
${chapter.name?.slice(0, 26)}
Copy url
`); }) } $('#parseNovelAndChapters .spinner-border').hide(); }); } const parseChapter = () => { const chapterUrl = $('#parseChapter input').val(); if(!current_plugin_requirePath || !chapterUrl) return; $('#parseChapter .spinner-border').show(); fetch(`/parseChapter/`,{ method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({"pluginRequirePath": current_plugin_requirePath, "chapterUrl": chapterUrl}), }) .then(res => res.json()) .then(chapterText => { $('#parseChapter textarea').text(chapterText); $('#parseChapter .spinner-border').hide(); }) } const fetchImage = () => { const url = $('#fetchImage input').val(); if(!current_plugin_requirePath || !url) return; $('#fetchImage .spinner-border').show(); fetch(`/fetchImage/`,{ method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({"pluginRequirePath": current_plugin_requirePath, "url": url}), }) .then(res => res.json()) .then(base64 => { $('#fetchImage img').attr("src", `data:image/jpg;base64,${base64}`); $('#fetchImage .spinner-border').hide(); }) }