// source --> https://mangasail.io/wp-content/themes/mangareader/assets/js/function.js?ver=2.2.2 
var Hooks=Hooks||{};function pickSelected(){jQuery("select#chapter option[data-id="+chapter_id+"]").attr("selected","selected"),jQuery("select#chapter option[value='']").attr("disabled","disabled")}function loadChList(){var t=new Date().toISOString().split("T")[0];if("object"==typeof localStorage){var e=localStorage.getItem("currentChapterList");if(null!==e){if((e=JSON.parse(e)).id==post_id&&e.time==t){$("select#chapter").append(e.html),pickSelected();return}localStorage.removeItem("currentChapterList")}}jQuery.ajax({url:ts_configs.get("general.ajaxUrl"),type:"post",data:{action:"get_chapters",id:post_id},success:function(e){if($("select#chapter").append(e),"object"==typeof localStorage){localStorage.setItem("currentChapterList",JSON.stringify({id:post_id,html:e,time:t})),pickSelected();return}}})}Hooks.actions=Hooks.actions||{},Hooks.filters=Hooks.filters||{},Hooks.add_action=function(t,e,o){void 0===o&&(o=10),Hooks.actions[t]=Hooks.actions[t]||[],Hooks.actions[t].push({priority:o,callback:e})},Hooks.add_filter=function(t,e,o){void 0===o&&(o=10),Hooks.filters[t]=Hooks.filters[t]||[],Hooks.filters[t].push({priority:o,callback:e})},Hooks.remove_action=function(t,e){Hooks.actions[t]=Hooks.actions[t]||[],Hooks.actions[t].forEach(function(o,a){o.callback===e&&Hooks.actions[t].splice(a,1)})},Hooks.remove_filter=function(t,e){Hooks.filters[t]=Hooks.filters[t]||[],Hooks.filters[t].forEach(function(o,a){o.callback===e&&Hooks.filters[t].splice(a,1)})},Hooks.do_action=function(t,e){var o=[];void 0!==Hooks.actions[t]&&Hooks.actions[t].length>0&&(Hooks.actions[t].forEach(function(t){o[t.priority]=o[t.priority]||[],o[t.priority].push(t.callback)}),o.forEach(function(t){t.forEach(function(t){t(e)})}))},Hooks.apply_filters=function(t,e,o){var a=[];return void 0!==Hooks.filters[t]&&Hooks.filters[t].length>0&&(Hooks.filters[t].forEach(function(t){a[t.priority]=a[t.priority]||[],a[t.priority].push(t.callback)}),a.forEach(function(t){t.forEach(function(t){e=t(e,o)})})),e};var ts_localStorage={};ts_localStorage.cachePrefix="tslsc_",ts_localStorage.isSupported=function(){try{return"localStorage"in window&&null!==window.localStorage}catch(t){return!1}},ts_localStorage.setLocalStorage=function(t,e){if(!this.isSupported())return!1;localStorage.setItem(t,JSON.stringify(e))},ts_localStorage.getLocalStorage=function(t){if(!this.isSupported())return null;var e=localStorage.getItem(t);return null===e?null:JSON.parse(e)},ts_localStorage.setLocalCache=function(t,e,o){var a={v:e,e:new Date().getTime()+1e3*o};this.setLocalStorage(this.cachePrefix+t,a)},ts_localStorage.getLocalCache=function(t){var e=this.getLocalStorage(ts_localStorage.cachePrefix+t);return e?"e"in e==!1||isNaN(e.e)||"v"in e==!1||new Date().getTime()>e.e?(this.removeLocalCache(t),null):e.v:null},ts_localStorage.removeLocalCache=function(t){localStorage.removeItem(this.cachePrefix+t)},ts_localStorage.removeAllCache=function(){for(var t in localStorage)0===t.indexOf(this.cachePrefix)&&localStorage.removeItem(t)};var ts_darkmode={};ts_darkmode.init=function(){!1!==ts_localStorage.isSupported()&&(null==localStorage.getItem("thememode")?"lightmode"==ts_configs.get("general.defaultTheme")?jQuery("body").addClass("lightmode"):jQuery("body").removeClass("lightmode"):"lightmode"==localStorage.getItem("thememode")?jQuery("body").addClass("lightmode"):jQuery("body").removeClass("lightmode"))},ts_darkmode.listen=function(){jQuery("#thememode input[type='checkbox']").on("change",function(){!1==jQuery("#thememode input[type='checkbox']").prop("checked")?(localStorage.setItem("thememode","lightmode"),jQuery("body").addClass("lightmode")):(localStorage.setItem("thememode","darkmode"),jQuery("body").removeClass("lightmode"))})};var ts_popular_widget={ranges:["monthly","weekly","alltime"],default:"weekly",range_selectors:{weekly:".wpop.wpop-weekly",monthly:".wpop.wpop-monthly",alltime:".wpop.wpop-alltime"},update_selector:"#wpop-items",currentTime:null,lstimename:"ts_cwpop",lswpopcont:"ts_cnwpop"};ts_popular_widget.is_valid_range=function(t){return -1!==this.ranges.indexOf(t)},ts_popular_widget.run=function(t){this.currentTime=t,this.updateWidget(),this.show_items(this.default),this.attach_events()},ts_popular_widget.show_items=function(t){if(ts_popular_widget.is_valid_range(t)){jQuery("#sidebar .wpop").hide();var e=jQuery("#sidebar "+this.range_selectors[t]);jQuery("#sidebar .ts-wpop-nav-tabs li").removeClass("active"),jQuery("#sidebar .ts-wpop-nav-tabs li span[data-range='"+t+"']").closest("li").addClass("active"),e.show()}},ts_popular_widget.getCurrent=function(){var t=jQuery(this.update_selector).html();return t.replace(/[\n\r]/g,"").replace(/\s\s+/g," ")},ts_popular_widget.updateWidget=function(){var t=ts_localStorage.getLocalStorage(this.lstimename);if(!isNaN(t)){if(t<this.currentTime)ts_localStorage.setLocalStorage(this.lstimename,this.currentTime),ts_localStorage.setLocalStorage(this.lswpopcont,this.getCurrent());else if(t>this.currentTime){var e=ts_localStorage.getLocalStorage(this.lswpopcont);if(!e)return;jQuery(this.update_selector).html(e)}return}ts_localStorage.setLocalStorage(this.lstimename,this.currentTime),ts_localStorage.setLocalStorage(this.lswpopcont,this.getCurrent)},ts_popular_widget.attach_events=function(){jQuery(".ts-wpop-tab").on("click",function(){var t=jQuery(this).attr("data-range");ts_popular_widget.is_valid_range(t)&&ts_popular_widget.show_items(t)})};var ts_ajax_cache_buster={param:{}};function ts_dynamic_ajax_view(t){return new Promise(function(e,o){jQuery(document).ready(function(){jQuery.ajax({url:ts_configs.get("general.ajaxUrl"),type:"post",data:{action:"dynamic_view_ajax",post_id:t},success:e,error:o})})})}function ts_escapeHTMLNode(t){if(null==t)return"";"string"!=typeof t&&(t=String(t));var e=document.createElement("div");return e.appendChild(document.createTextNode(t)),e.innerHTML}function ts_decodeHTMLNode(t){if(null==t)return"";"string"!=typeof t&&(t=String(t));var e=document.createElement("div");return e.innerHTML=t,e.textContent||e.innerText||""}function ts_escapeHTMLText(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ts_escapeHTMLAttr(t){return String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}ts_ajax_cache_buster.run=function(t){this.param=t,ts_ajax_cache_buster.get()},ts_ajax_cache_buster.get=function(){var t=new Date;jQuery.getJSON(this.param.url+"?time="+this.param.time+t.getDay()).done(function(t){"object"==typeof t&&"content"in t!=!1&&jQuery("span.ts-ajax-cache[data-id='"+t.self+"']").html(t.content).css("visibility","unset")}).fail(function(){})},(ts_zoom={increase_element:".fontSize .setSize[data-method='+']",decrease_element:".fontSize .setSize[data-method='-']",content_element:"#readerarea",max_size:22,min_size:14,default_size:14,ls_name:"ts_font_size"}).set_font_size=function(t){if(isNaN(t))return!1;jQuery(this.content_element).attr("data-size",t),jQuery(this.content_element).attr("style","font-size:"+t+"px !important"),ts_localStorage.setLocalStorage(this.ls_name,t)},ts_zoom.increase=function(){var t=parseInt(jQuery(this.content_element).attr("data-size"));(isNaN(t)||t<this.min_size||t>this.max_size)&&(t=this.default_size),(t+=1)>this.max_size&&(t=this.max_size),ts_zoom.set_font_size(t)},ts_zoom.decrease=function(){var t=parseInt(jQuery(this.content_element).attr("data-size"));(isNaN(t)||t<this.min_size||t>this.max_size)&&(t=this.default_size),(t-=1)<this.min_size&&(t=this.min_size),ts_zoom.set_font_size(t)},ts_zoom.init=function(){var t=ts_localStorage.getLocalStorage(this.ls_name);if(!isNaN(t)){if(t<this.min_size||t>this.max_size){this.set_font_size(this.default_size);return}this.set_font_size(t)}},ts_zoom.attach_events=function(){jQuery(document).on("click",this.increase_element,function(){return ts_zoom.increase(),!1}),jQuery(document).on("click",this.decrease_element,function(){return ts_zoom.decrease(),!1})};
// source --> https://mangasail.io/wp-content/themes/mangareader/assets/js/tsmedia.js?ver=2.2.2 
function tsMedia(x) {
  if (x.matches) {
    jQuery("#titlemove").appendTo(jQuery("#mobiletitle"));
  } else {
  	jQuery("#titlemove").prependTo(jQuery("#titledesktop"));
  }	
}
var tsmmedia = matchMedia("(max-width: 800px)");
if ("addEventListener" in tsmmedia){
  tsmmedia.addEventListener("change", tsMedia);
}else{
  tsmmedia.addListener(tsMedia);
};
// source --> https://mangasail.io/wp-content/themes/mangareader/assets/js/nsfw.js?ver=2.2.2 
var ts_restricted_warning={localStorageName:"ts_reswar",redirect_page:ts_configs.get("general.homeUrl","/"),series_id:null};ts_restricted_warning.init=function(){jQuery(document).ready(function(){if(!1===ts_restricted_warning.can_i_run()){ts_restricted_warning.getModal().hide();return}ts_restricted_warning.run()})},ts_restricted_warning.run=function(){ts_restricted_warning.attachEvents()},ts_restricted_warning.can_i_run=function(){return!1!==ts_localStorage.isSupported()&&!(ts_restricted_warning.getModal().length<=0)&&!1!==ts_restricted_warning.getSeriesId()&&!0!==ts_restricted_warning.isUserAgree()},ts_restricted_warning.quickHide=function(){!1==ts_restricted_warning.can_i_run()&&ts_restricted_warning.getModal().hide()},ts_restricted_warning.isUserAgree=function(){var t=ts_restricted_warning.getSeriesId(),r=ts_localStorage.getLocalStorage(ts_restricted_warning.localStorageName);return parseInt(t)===parseInt(r)},ts_restricted_warning.setLocalStorage=function(){var t=ts_restricted_warning.getSeriesId();if(isNaN(t))return!1;ts_localStorage.setLocalStorage(ts_restricted_warning.localStorageName,t)},ts_restricted_warning.getModal=function(){return jQuery(document).find(".restrictcontainer")},ts_restricted_warning.getSeriesId=function(){if(!isNaN(ts_restricted_warning.series_id)&&ts_restricted_warning.series_id)return ts_restricted_warning.series_id;var t=ts_restricted_warning.getModal().attr("data-id");return!isNaN(t)&&(ts_restricted_warning.series_id=t,t)},ts_restricted_warning.getEnterButton=function(){return ts_restricted_warning.getModal().find("div.rescb.enterx")},ts_restricted_warning.getExitButton=function(){return ts_restricted_warning.getModal().find("div.rescb.exitx")},ts_restricted_warning.attachEvents=function(){ts_restricted_warning.getEnterButton().on("click",function(){ts_restricted_warning.enterBtnOnClick()}),ts_restricted_warning.getExitButton().on("click",function(){window.location.replace(ts_restricted_warning.redirect_page)})},ts_restricted_warning.enterBtnOnClick=function(){ts_restricted_warning.getModal().hide(),ts_restricted_warning.setLocalStorage()},ts_restricted_warning.init();
// source --> https://mangasail.io/wp-content/themes/mangareader/assets/js/chapter-search.js?ver=2.2.2 
var series_chapters={chapters:[],minItemToShowSearch:10,currentSearchId:null,isSearching:!1,debounceTimeout:null,currentSearchQuery:""};series_chapters.getChapters=function(){if(series_chapters.chapters.length>0)return series_chapters.chapters;var e=jQuery(".eplister ul li");if(e.length<1)return[];var r=[];return e.each(function(e,t){t=jQuery(t);var s={};s.episode=t.attr("data-num"),s.link=t.find("a").get(0).href,s.first=t.hasClass("first-chapter"),r.push(s)}),series_chapters.chapters=r,r},series_chapters.setFirstChapterData=function(){var e=jQuery(".epcur.epcurfirst");if(!(e.length<1)){var r=series_chapters.getChapters();if(r.length<=5){jQuery(".lastend").hide();return}var t=r[r.length-1];t.first||(t=r[0]),e.parent().attr("href",t.link),e.html(e.html().replace("?",t.episode))}},series_chapters.controlSearchInput=function(){series_chapters.getChapters().length<this.minItemToShowSearch&&jQuery(".search-chapter").hide()},series_chapters.attachSearchEvent=function(){var e="#chapterlist li";jQuery("#searchchapter").on("input",function(){clearTimeout(series_chapters.debounceTimeout);var r=this.value;series_chapters.debounceTimeout=setTimeout(function(){if(r.length<1){series_chapters.batchShowItems(jQuery(e));return}series_chapters.startSearch(r,"#chapterlist ul",e,"li#lihide")},300)})},series_chapters.batchShowItems=function(e){e.show()},series_chapters.batchHideItems=function(e){e.hide()},series_chapters.startSearch=function(e,r,t,s){series_chapters.isSearching&&null!==series_chapters.currentSearchId&&clearTimeout(series_chapters.currentSearchId),series_chapters.isSearching=!0,series_chapters.currentSearchQuery=e,series_chapters.processSearch(e,r,t,s)},series_chapters.processSearch=async function(e,r,t,s){var a=jQuery(t).toArray(),h=a.length,c=0,i=0;if(0===e.length){series_chapters.batchShowItems(jQuery(t));return}for(;c<h;){for(var n=Math.min(c+50,h),p=c;p<n;p++){var u=a[p];-1!==u.getAttribute("data-num").indexOf(e)?(jQuery(u).show(),i++):jQuery(u).hide()}c=n,await new Promise(e=>setTimeout(e,5))}series_chapters.isSearching=!1,series_chapters.currentSearchId=null,i<1&&jQuery(r).prepend('<li id="lihide"><center>'+chapterSearchNotFound+"</center></li>")},jQuery(document).ready(function(){series_chapters.attachSearchEvent()});
// source --> https://mangasail.io/wp-content/themes/mangareader/assets/js/bookmark.js?ver=2.2.2 
var BOOKMARK={};BOOKMARK.checkLocalStorage=function(){return"function"==typeof Storage},BOOKMARK.storeLocalStorage=function(e,r){return!1!=BOOKMARK.checkLocalStorage()&&localStorage.setItem(e,JSON.stringify(r))},BOOKMARK.getLocalStorage=function(e){if(!1==BOOKMARK.checkLocalStorage()||e in localStorage==!1)return!1;try{return JSON.parse(localStorage[e])}catch(r){return[]}},BOOKMARK.getStored=function(){var e=BOOKMARK.getLocalStorage("bookmark");return!1==e?[]:"object"!=typeof e?[]:e},BOOKMARK.find=function(e){return!!BOOKMARK.checkLocalStorage()&&BOOKMARK.getStored().findIndex(r=>r===e||r===("number"==typeof e?String(e):Number(e)))},BOOKMARK.isManuallyPushed=function(e){if(isNaN(e)||!BOOKMARK.checkLocalStorage())return!1;var r=BOOKMARK.getLocalStorage("bookmark_manually_pushed");return!!Array.isArray(r)&&((r=r.filter(e=>!isNaN(e))).includes(e)||r.includes("number"==typeof e?String(e):Number(e)))},BOOKMARK.trackManuallyPushed=function(e){if(isNaN(e)||!BOOKMARK.checkLocalStorage())return!1;var r=BOOKMARK.getLocalStorage("bookmark_manually_pushed");return Array.isArray(r)||(r=[]),!!(r.includes(e)||r.includes("number"==typeof e?String(e):Number(e)))||(r.unshift(e),BOOKMARK.storeLocalStorage("bookmark_manually_pushed",r),!0)},BOOKMARK.removeManuallyPushed=function(e){if(isNaN(e)||!BOOKMARK.checkLocalStorage())return!1;var r=BOOKMARK.getLocalStorage("bookmark_manually_pushed");return Array.isArray(r)||(r=[]),r=r.filter(r=>r!==e&&r!==("number"==typeof e?String(e):Number(e))),BOOKMARK.storeLocalStorage("bookmark_manually_pushed",r),!0},BOOKMARK.remove=function(e){if(!BOOKMARK.checkLocalStorage())return!1;var r=BOOKMARK.getStored();return r=r.filter(r=>r!==e&&r!==("number"==typeof e?String(e):Number(e))),BOOKMARK.storeLocalStorage("bookmark",r),BOOKMARK.isManuallyPushed(e)&&jQuery.post(ts_configs.get("general.ajaxUrl"),{action:"bookmark_remove",id:e}),BOOKMARK.removeManuallyPushed(e),!0},BOOKMARK.push=function(e){if(!BOOKMARK.checkLocalStorage())return alert(ts_configs.get("lang.bookmark_not_supported")),!1;if(isNaN(e))return!1;var r=BOOKMARK.getStored();return r.length>=ts_configs.get("bookmark.max")?(r=r.slice(-ts_configs.get("bookmark.max")),BOOKMARK.storeLocalStorage("bookmark",r),alert(ts_configs.get("lang.bookmark_max_reached")),!1):!!(r.includes(e)||r.includes("number"==typeof e?String(e):Number(e)))||(r.unshift(e),BOOKMARK.storeLocalStorage("bookmark",r),BOOKMARK.trackManuallyPushed(e),jQuery.post(ts_configs.get("general.ajaxUrl"),{action:"bookmark_push",id:e}),!0)},BOOKMARK.check=function(){var e=jQuery("div.bookmark[data-id]");if(e.length<1)return!1;var r=e.get(0).getAttribute("data-id");if(isNaN(r))return!1;var o=BOOKMARK.find(r);return isNaN(o)||-1===o?(e.html('<i class="far fa-bookmark" aria-hidden="true"></i> '+ts_configs.get("lang.bookmark_label")),e.removeClass("marked"),!1):(e.html('<i class="fas fa-bookmark" aria-hidden="true"></i> '+ts_configs.get("lang.bookmarked_label")),e.addClass("marked"),!0)},BOOKMARK.listener=function(){var e=jQuery("div.bookmark[data-id]");if(e.length<1)return!1;e.on("click",function(){var e=this.getAttribute("data-id");return!isNaN(e)&&(-1===BOOKMARK.find(e)?BOOKMARK.push(e):BOOKMARK.remove(e),BOOKMARK.check(),!0)})},ts_configs.get("bookmark.isSeriesPage",!0)&&document.addEventListener("DOMContentLoaded",function(){BOOKMARK.listener(),BOOKMARK.check()});const TS_BookmarkLog={write:function(e,r){var o=document.querySelector("#imex-bm-notices");o.innerHTML=e,o.style.color=r,o.style.display="block"}},TS_BookmarkBackup={backup:function(){try{let e=BOOKMARK.getStored(),r=JSON.stringify(e);return r}catch(o){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_export_error")+": "+o,"red")}},download:function(){try{var e=this.backup(),r=JSON.parse(e);if(!e||0===r.length){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_export_error_empty"),"red");return}var o=`${window.location.hostname||"history-backup"}-bookmark-${new Date().toISOString().slice(0,10)}.json`,t=document.createElement("a");t.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(e)),t.setAttribute("download",o),t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t),TS_BookmarkLog.write(ts_configs.get("lang.bookmark_export_success"),"green")}catch(a){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_export_error")+": "+a,"red")}},init:function(){ts_configs&&ts_configs.exists("bookmark")&&ts_configs.exists("bookmark.enabled")&&ts_configs.exists("bookmark.page")&&ts_configs.exists("bookmark.page.allowImportExport")&&document.addEventListener("DOMContentLoaded",()=>{var e=document.querySelector("#export-bookmark");e&&e.addEventListener("click",()=>{confirm(ts_configs.get("lang.bookmark_export_confirm"))&&this.download()})})}};TS_BookmarkBackup.init();const TS_BookmarkImporter={readFile:function(e){return new Promise((r,o)=>{let t=new FileReader;t.onload=e=>{r(e.target.result)},t.onerror=e=>{o(e)},t.readAsText(e)})},handleFileUpload:async function(e){try{let r=await this.readFile(e),o=null;if(!r){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_error_empty"),"red");return}try{o=JSON.parse(r)}catch(t){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_error_empty"),"red");return}if(!o||0===o.length||0===o.length){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_error_empty"),"red");return}let a=window.confirm(ts_configs.get("lang.bookmark_import_confirm"));if(a){if(localStorage.removeItem("bookmark"),!Array.isArray(o)||o.some(isNaN)){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_error"),"red");return}BOOKMARK.storeLocalStorage("bookmark",o),TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_success"),"green"),setTimeout(function(){window.location.reload()},1e3)}else TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_cancelled"),"red")}catch(i){TS_BookmarkLog.write(ts_configs.get("lang.bookmark_import_error")+": "+i,"red")}},init:function(){ts_configs&&ts_configs.exists("bookmark")&&ts_configs.exists("bookmark.enabled")&&ts_configs.exists("bookmark.page")&&ts_configs.exists("bookmark.page.allowImportExport")&&document.addEventListener("DOMContentLoaded",()=>{var e=document.querySelector("#import-bookmark");e&&e.addEventListener("click",()=>{var e=document.querySelector("#bookmark-import-upload");"none"==e.style.display?e.style.display="block":e.style.display="none"});let r=document.getElementById("ts-bookmark-import-file");if(!r){console.error('File input element with ID "ts-bookmark-import-file" not found.');return}r.addEventListener("change",async e=>{let r=e.target.files[0];r&&await this.handleFileUpload(r)})})}};TS_BookmarkImporter.init();const TS_BookmarkPage={selectors:{bookmarkPool:"#bookmark-pool",delMark:".delmark",tsBookmarkPagination:"#ts-bookmark-pagination",importExportWrapper:"#ts-import-export-bookmark"},current_page:1,bookmark_data:[],cache:{},generateRating:function(){jQuery(document).find(".score").each(function(e,r){var o=jQuery(r);o.barrating({theme:"fontawesome-stars",readonly:!0,initialRating:o.attr("data-current-rating")})})},init:async function(){ts_configs&&ts_configs.exists("bookmark")&&ts_configs.exists("bookmark.page")&&ts_configs.exists("bookmark.enabled")&&(await this.initializeBookmarks(),this.bindEvents())},initializeBookmarks:async function(){if(BOOKMARK.getStored().length<1){this.displayNoBookmarks();return}await this.fetchOrder(),await this.fetchHtml(this.bookmark_data.slice(0,ts_configs.get("bookmark.page.perpage"))),this.pagination()},displayNoBookmarks:function(){jQuery(this.selectors.bookmarkPool).removeClass("ts-loading"),jQuery(this.selectors.bookmarkPool).html("<h4><center>"+ts_configs.get("lang.bookmark_no_item")+"</center></h4>")},bindEvents:function(){jQuery("#hapus").on("click",()=>{jQuery(document).find(this.selectors.delMark).length<=0?jQuery(document).find("div.bsx").prepend('<div class="delmark">'+ts_configs.get("lang.delete")+"</div>"):jQuery(document).find(this.selectors.delMark).remove()}),jQuery(document).on("click",this.selectors.delMark,e=>{var r=jQuery(e.target).parent().attr("data-id");BOOKMARK.remove(r),console.log("remove",r),this.cache={},this.bookmark_data=this.bookmark_data.filter(e=>e!=r),this.pagination()})},showLoading:function(){var e=jQuery(this.selectors.bookmarkPool);e.hasClass("ts-loading")||(e.addClass("ts-loading"),e.html('<div class="ts-loading-spinner"></div>'))},fetchOrder:async function(){var e=BOOKMARK.getStored();if(!e||!Array.isArray(e)||e.length<1||!(e=e.filter(e=>""!==e&&!isNaN(e)).filter((e,r,o)=>o.indexOf(e)===r))||!Array.isArray(e)||e.length<1){this.displayNoBookmarks();return}try{let r=await new Promise((r,o)=>{jQuery.post(ts_configs.get("general.ajaxUrl"),{action:"bookmark_get_order",ids:e}).done(e=>r(e)).fail(e=>o(e))});if(r.error)return this.displayNoBookmarks(),Promise.reject(r.error);if("error_ids"in r)for(var o in r.error_ids)BOOKMARK.remove(r.error_ids[o],!1);var t=e.filter(e=>!r.data.some(r=>r==e||String(r)==e));for(var o in t)BOOKMARK.remove(t[o],!1);return this.bookmark_data=r.data,Promise.resolve(r.data)}catch(a){return console.error(a),Promise.reject(a)}},fetchHtml:async function(e){if(!e||!Array.isArray(e)||e.length<1){this.displayNoBookmarks();return}if(this.current_page in this.cache){jQuery(this.selectors.bookmarkPool).removeClass("ts-loading"),jQuery(this.selectors.bookmarkPool).html(this.cache[this.current_page]),this.generateRating();return}if(!(e=e.filter(e=>""!==e&&!isNaN(e)).filter((e,r,o)=>o.indexOf(e)===r))||!Array.isArray(e)||e.length<1){this.displayNoBookmarks();return}this.showLoading();try{let r=await new Promise((r,o)=>{jQuery.post(ts_configs.get("general.ajaxUrl"),{action:"bookmark_get",ids:e}).done(e=>r(e)).fail(e=>o(e))});if(r.error)return this.displayNoBookmarks(),Promise.reject(r.error);if("error_ids"in r)for(var o in r.error_ids)BOOKMARK.remove(r.error_ids[o],!1);let t="";for(var o in r.data){var a=r.data[o];a=a.replace('class="bsx"',`data-index="${o}" class="bsx"`),t+=a}this.cache[this.current_page]=t,jQuery(this.selectors.bookmarkPool).removeClass("ts-loading"),jQuery(this.selectors.bookmarkPool).html(t),this.generateRating()}catch(i){return console.error(i),Promise.reject(i)}},scrollToTop:function(){var e=jQuery(this.selectors.importExportWrapper);e.length<1&&(e=jQuery(this.selectors.bookmarkPool)),!(e.length<1)&&e[0].scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})},pagination:function(){var e=ts_configs.get("bookmark.page.perpage"),r={pageNumber:this.current_page,dataSource:this.bookmark_data,pageSize:e,autoHidePrevious:!1,autoHideNext:!1,callback:(e,r)=>{this.current_page!=r.pageNumber&&this.scrollToTop(),this.current_page=r.pageNumber,this.fetchHtml(e)}};r=Hooks.apply_filters("TS_BookmarkPage>>pagination_config",r),jQuery(this.selectors.tsBookmarkPagination).pagination(r)}};document.addEventListener("DOMContentLoaded",()=>{TS_BookmarkPage.init()});