HummingBirdAnimeClient/public/js/scripts.min.js
Timothy J. Warren 5346ce7d89
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit
Drastically simplify setup for bundling js files
2021-04-23 18:58:51 -04:00

1 line
14 KiB
JavaScript

function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable;}));}ownKeys.forEach(function(key){_defineProperty(target,key,source[key]);});}return target;}if('serviceWorker' in navigator)navigator.serviceWorker.register('/sw.js').then(function(reg){console.log('Service worker registered',reg.scope);})["catch"](function(error){console.error('Failed to register service worker',error);});var matches=function(elm,selector){var m=(elm.document||elm.ownerDocument).querySelectorAll(selector);var i=matches.length;while((--i)>=0&&m.item(i)!==elm);return i>-1;};var AnimeClient={noop:function(){},$:function(selector,param){var context=param=== void 0?null:param;if(typeof selector!=='string')return selector;context=context!==null&&context.nodeType===1?context:document;var elements=[];if(selector.match(/^#([\w]+$)/))elements.push(document.getElementById(selector.split('#')[1]));else elements=[].slice.apply(context.querySelectorAll(selector));return elements;},hasElement:function(selector){return AnimeClient["$"](selector).length>0;},scrollToTop:function(){var el=AnimeClient["$"]('header')[0];el.scrollIntoView(true);},hide:function(sel){if(typeof sel==='string')sel=AnimeClient["$"](sel);if(Array.isArray(sel))sel.forEach(function(el){return el.setAttribute('hidden','hidden');});else sel.setAttribute('hidden','hidden');},show:function(sel){if(typeof sel==='string')sel=AnimeClient["$"](sel);if(Array.isArray(sel))sel.forEach(function(el){return el.removeAttribute('hidden');});else sel.removeAttribute('hidden');},showMessage:function(type,message){var template="<div class='message ".concat(type,"'>\n\t\t\t\t<span class='icon'></span>\n\t\t\t\t").concat(message,"\n\t\t\t\t<span class='close'></span>\n\t\t\t</div>");var sel=AnimeClient["$"]('.message');if(sel[0]!==undefined)sel[0].remove();AnimeClient["$"]('header')[0].insertAdjacentHTML('beforeend',template);},closestParent:function(current,parentSelector){if(Element.prototype.closest!==undefined)return current.closest(parentSelector);while(current!==document.documentElement){if(matches(current,parentSelector))return current;current=current.parentElement;}return null;},url:function(path){var uri="//".concat(document.location.host);uri+=path.charAt(0)==='/'?path:"/".concat(path);return uri;},throttle:function(interval,fn,scope){var wait=false;return function(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}var context=scope||this;if(!wait){fn.apply(context,args);wait=true;setTimeout(function(){wait=false;},interval);}};}};function addEvent(sel,event,listener){if(!event.match(/^([\w\-]+)$/))event.split(' ').forEach(function(evt){addEvent(sel,evt,listener);});sel.addEventListener(event,listener,false);}function delegateEvent(sel,target,event,listener){addEvent(sel,event,function(e){AnimeClient["$"](target,sel).forEach(function(element){if(e.target==element){listener.call(element,e);e.stopPropagation();}});});}AnimeClient.on=function(sel,event,target,listener){if(listener===undefined){listener=target;AnimeClient["$"](sel).forEach(function(el){addEvent(el,event,listener);});}else AnimeClient["$"](sel).forEach(function(el){delegateEvent(el,target,event,listener);});};function ajaxSerialize(data){var pairs=[];Object.keys(data).forEach(function(name){var value=data[name].toString();name=encodeURIComponent(name);value=encodeURIComponent(value);pairs.push("".concat(name,"=").concat(value));});return pairs.join('&');}AnimeClient.ajax=function(url,config){var defaultConfig={data:{},type:'GET',dataType:'',success:AnimeClient.noop,mimeType:'application/x-www-form-urlencoded',error:AnimeClient.noop};config=_objectSpread({},defaultConfig,config);var request=new XMLHttpRequest();var method=String(config.type).toUpperCase();if(method==='GET')url+=url.match(/\?/)?ajaxSerialize(config.data):"?".concat(ajaxSerialize(config.data));request.open(method,url);request.onreadystatechange=function(){if(request.readyState===4){var responseText='';if(request.responseType==='json')responseText=JSON.parse(request.responseText);else responseText=request.responseText;if(request.status>299)config.error.call(null,request.status,responseText,request.response);else config.success.call(null,responseText,request.status);}};if(config.dataType==='json'){config.data=JSON.stringify(config.data);config.mimeType='application/json';}else config.data=ajaxSerialize(config.data);request.setRequestHeader('Content-Type',config.mimeType);if(method==='GET')request.send(null);else request.send(config.data);return request;};AnimeClient.get=function(url,data,param){var callback=param=== void 0?null:param;if(callback===null){callback=data;data={};}return AnimeClient.ajax(url,{data:data,success:callback});};AnimeClient.on('header','click','.message',hide);AnimeClient.on('form.js-delete','submit',confirmDelete);AnimeClient.on('.js-clear-cache','click',clearAPICache);AnimeClient.on('.vertical-tabs input','change',scrollToSection);AnimeClient.on('.media-filter','input',filterMedia);function hide(event){AnimeClient.hide(event.target);}function confirmDelete(event){var proceed=confirm('Are you ABSOLUTELY SURE you want to delete this item?');if(proceed===false){event.preventDefault();event.stopPropagation();}}function clearAPICache(){AnimeClient.get('/cache_purge',function(){AnimeClient.showMessage('success','Successfully purged api cache');});}function scrollToSection(event){var el=event.currentTarget.parentElement;var rect=el.getBoundingClientRect();var top=rect.top+window.pageYOffset;window.scrollTo({top:top,behavior:'smooth'});}function filterMedia(event){var rawFilter=event.target.value;var filter=new RegExp(rawFilter,'i');if(rawFilter!==''){AnimeClient["$"]('article.media').forEach(function(article){var titleLink=AnimeClient["$"]('.name a',article)[0];var title=String(titleLink.textContent).trim();if(!filter.test(title))AnimeClient.hide(article);else AnimeClient.show(article);});AnimeClient["$"]('table.media-wrap tbody tr').forEach(function(tr){var titleCell=AnimeClient["$"]('td.align-left',tr)[0];var titleLink=AnimeClient["$"]('a',titleCell)[0];var linkTitle=String(titleLink.textContent).trim();var textTitle=String(titleCell.textContent).trim();if(!(filter.test(linkTitle)||filter.test(textTitle)))AnimeClient.hide(tr);else AnimeClient.show(tr);});}else{AnimeClient.show('article.media');AnimeClient.show('table.media-wrap tbody tr');}}(function(){var hidden=null;var visibilityChange=null;if(typeof document.hidden!=="undefined"){hidden="hidden";visibilityChange="visibilitychange";}else if(typeof document.msHidden!=="undefined"){hidden="msHidden";visibilityChange="msvisibilitychange";}else if(typeof document.webkitHidden!=="undefined"){hidden="webkitHidden";visibilityChange="webkitvisibilitychange";}function handleVisibilityChange(){if(!document[hidden])AnimeClient.get('/heartbeat',function(beat){var status=JSON.parse(beat);if(status.hasAuth!==true){document.removeEventListener(visibilityChange,handleVisibilityChange,false);location.reload();}});}if(hidden===null)console.info('Page visibility API not supported, JS session check will not work');else document.addEventListener(visibilityChange,handleVisibilityChange,false);})();AnimeClient.on('main','change','.big-check',function(e){var id=e.target.id;document.getElementById("mal_".concat(id)).checked=true;});function renderAnimeSearchResults(data){return data.map(function(item){var titles=item.titles.join('<br />');return "\n\t\t\t<article class=\"media search\">\n\t\t\t\t<div class=\"name\">\n\t\t\t\t\t<input type=\"radio\" class=\"mal-check\" id=\"mal_".concat(item.slug,"\" name=\"mal_id\" value=\"").concat(item.mal_id,"\" />\n\t\t\t\t\t<input type=\"radio\" class=\"big-check\" id=\"").concat(item.slug,"\" name=\"id\" value=\"").concat(item.id,"\" />\n\t\t\t\t\t<label for=\"").concat(item.slug,"\">\n\t\t\t\t\t\t<picture width=\"220\">\n\t\t\t\t\t\t\t<source srcset=\"/public/images/anime/").concat(item.id,".webp\" type=\"image/webp\" />\n\t\t\t\t\t\t\t<source srcset=\"/public/images/anime/").concat(item.id,".jpg\" type=\"image/jpeg\" />\n\t\t\t\t\t\t\t<img src=\"/public/images/anime/").concat(item.id,".jpg\" alt=\"\" width=\"220\" />\n\t\t\t\t\t\t</picture>\n\t\t\t\t\t\t<span class=\"name\">\n\t\t\t\t\t\t\t").concat(item.canonicalTitle,"<br />\n\t\t\t\t\t\t\t<small>").concat(titles,"</small>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</label>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"table\">\n\t\t\t\t\t<div class=\"row\">\n\t\t\t\t\t\t<span class=\"edit\">\n\t\t\t\t\t\t\t<a class=\"bracketed\" href=\"/anime/details/").concat(item.slug,"\">Info Page</a>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</article>\n\t\t");}).join('');}function renderMangaSearchResults(data){return data.map(function(item){var titles=item.titles.join('<br />');return "\n\t\t\t<article class=\"media search\">\n\t\t\t\t<div class=\"name\">\n\t\t\t\t\t<input type=\"radio\" id=\"mal_".concat(item.slug,"\" name=\"mal_id\" value=\"").concat(item.mal_id,"\" />\n\t\t\t\t\t<input type=\"radio\" class=\"big-check\" id=\"").concat(item.slug,"\" name=\"id\" value=\"").concat(item.id,"\" />\n\t\t\t\t\t<label for=\"").concat(item.slug,"\">\n\t\t\t\t\t\t<picture width=\"220\">\n\t\t\t\t\t\t\t<source srcset=\"/public/images/manga/").concat(item.id,".webp\" type=\"image/webp\" />\n\t\t\t\t\t\t\t<source srcset=\"/public/images/manga/").concat(item.id,".jpg\" type=\"image/jpeg\" />\n\t\t\t\t\t\t\t<img src=\"/public/images/manga/").concat(item.id,".jpg\" alt=\"\" width=\"220\" />\n\t\t\t\t\t\t</picture>\n\t\t\t\t\t\t<span class=\"name\">\n\t\t\t\t\t\t\t").concat(item.canonicalTitle,"<br />\n\t\t\t\t\t\t\t<small>").concat(titles,"</small>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</label>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"table\">\n\t\t\t\t\t<div class=\"row\">\n\t\t\t\t\t\t<span class=\"edit\">\n\t\t\t\t\t\t\t<a class=\"bracketed\" href=\"/manga/details/").concat(item.slug,"\">Info Page</a>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</article>\n\t\t");}).join('');}var search=function(query){AnimeClient.show('.cssload-loader');return AnimeClient.get(AnimeClient.url('/anime-collection/search'),{query:query},function(searchResults,status){searchResults=JSON.parse(searchResults);AnimeClient.hide('.cssload-loader');AnimeClient["$"]('#series-list')[0].innerHTML=renderAnimeSearchResults(searchResults);});};if(AnimeClient.hasElement('.anime #search')){var prevRequest=null;AnimeClient.on('#search','input',AnimeClient.throttle(250,function(e){var query=encodeURIComponent(e.target.value);if(query==='')return;if(prevRequest!==null)prevRequest.abort();prevRequest=search(query);}));}AnimeClient.on('body.anime.list','click','.plus-one',function(e){var parentSel=AnimeClient.closestParent(e.target,'article');var watchedCount=parseInt(AnimeClient["$"]('.completed_number',parentSel)[0].textContent,10)||0;var totalCount=parseInt(AnimeClient["$"]('.total_number',parentSel)[0].textContent,10);var title=AnimeClient["$"]('.name a',parentSel)[0].textContent;var data={id:parentSel.dataset.kitsuId,mal_id:parentSel.dataset.malId,data:{progress:watchedCount+1}};if(isNaN(watchedCount)||watchedCount===0)data.data.status='CURRENT';if(!isNaN(watchedCount)&&watchedCount+1===totalCount)data.data.status='COMPLETED';AnimeClient.show('#loading-shadow');AnimeClient.ajax(AnimeClient.url('/anime/increment'),{data:data,dataType:'json',type:'POST',success:function(res){var resData=JSON.parse(res);if(resData.error){AnimeClient.hide('#loading-shadow');AnimeClient.showMessage('error',"Failed to update ".concat(title,". "));AnimeClient.scrollToTop();return;}if(resData.data.libraryEntry.update.libraryEntry.status==='COMPLETED')AnimeClient.hide(parentSel);AnimeClient.hide('#loading-shadow');AnimeClient.showMessage('success',"Successfully updated ".concat(title));AnimeClient["$"]('.completed_number',parentSel)[0].textContent=++watchedCount;AnimeClient.scrollToTop();},error:function(){AnimeClient.hide('#loading-shadow');AnimeClient.showMessage('error',"Failed to update ".concat(title,". "));AnimeClient.scrollToTop();}});});var search1=function(query){AnimeClient.show('.cssload-loader');return AnimeClient.get(AnimeClient.url('/manga/search'),{query:query},function(searchResults,status){searchResults=JSON.parse(searchResults);AnimeClient.hide('.cssload-loader');AnimeClient["$"]('#series-list')[0].innerHTML=renderMangaSearchResults(searchResults);});};if(AnimeClient.hasElement('.manga #search')){var prevRequest=null;AnimeClient.on('#search','input',AnimeClient.throttle(250,function(e){var query=encodeURIComponent(e.target.value);if(query==='')return;if(prevRequest!==null)prevRequest.abort();prevRequest=search1(query);}));}AnimeClient.on('.manga.list','click','.edit-buttons button',function(e){var thisSel=e.target;var parentSel=AnimeClient.closestParent(e.target,'article');var type=thisSel.classList.contains('plus-one-chapter')?'chapter':'volume';var completed=parseInt(AnimeClient["$"](".".concat(type,"s_read"),parentSel)[0].textContent,10)||0;var total=parseInt(AnimeClient["$"](".".concat(type,"_count"),parentSel)[0].textContent,10);var mangaName=AnimeClient["$"]('.name',parentSel)[0].textContent;if(isNaN(completed))completed=0;var data={id:parentSel.dataset.kitsuId,mal_id:parentSel.dataset.malId,data:{progress:completed}};if(isNaN(completed)||completed===0)data.data.status='CURRENT';if(!isNaN(completed)&&completed+1===total)data.data.status='COMPLETED';data.data.progress=++completed;AnimeClient.show('#loading-shadow');AnimeClient.ajax(AnimeClient.url('/manga/increment'),{data:data,dataType:'json',type:'POST',mimeType:'application/json',success:function(res){var resData=JSON.parse(res);if(resData.error){AnimeClient.hide('#loading-shadow');AnimeClient.showMessage('error',"Failed to update ".concat(mangaName,". "));AnimeClient.scrollToTop();return;}if(String(data.data.status).toUpperCase()==='COMPLETED')AnimeClient.hide(parentSel);AnimeClient.hide('#loading-shadow');AnimeClient["$"](".".concat(type,"s_read"),parentSel)[0].textContent=String(completed);AnimeClient.showMessage('success',"Successfully updated ".concat(mangaName));AnimeClient.scrollToTop();},error:function(){AnimeClient.hide('#loading-shadow');AnimeClient.showMessage('error',"Failed to update ".concat(mangaName));AnimeClient.scrollToTop();}});});