1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
var e=this&&this.__awaiter||function(e,t,a,s){return new(a||(a=Promise))(function(l,r){function i(e){try{n(s.next(e))}catch(e){r(e)}}function o(e){try{n(s.throw(e))}catch(e){r(e)}}function n(e){var t;e.done?l(e.value):(t=e.value,t instanceof a?t:new a(function(e){e(t)})).then(i,o)}n((s=s.apply(e,t||[])).next())})},t=this&&this.__generator||function(e,t){var a,s,l,r={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=o(0),i.throw=o(1),i.return=o(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function o(o){return function(n){return function(o){if(a)throw new TypeError("Generator is already executing.");for(;i&&(i=0,o[0]&&(r=0)),r;)try{if(a=1,s&&(l=2&o[0]?s.return:o[0]?s.throw||((l=s.return)&&l.call(s),0):s.next)&&!(l=l.call(s,o[1])).done)return l;switch(s=0,l&&(o=[2&o[0],l.value]),o[0]){case 0:case 1:l=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,s=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(!(l=r.trys,(l=l.length>0&&l[l.length-1])||6!==o[0]&&2!==o[0])){r=0;continue}if(3===o[0]&&(!l||o[1]>l[0]&&o[1]<l[3])){r.label=o[1];break}if(6===o[0]&&r.label<l[1]){r.label=l[1],l=o;break}if(l&&r.label<l[2]){r.label=l[2],r.ops.push(o);break}l[2]&&r.ops.pop(),r.trys.pop();continue}o=t.call(e,r)}catch(e){o=[6,e],s=0}finally{a=l=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,n])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LightNovelWPPlugin=void 0;var a=require("cheerio"),s=require("htmlparser2"),l=require("@libs/fetch"),r=require("@libs/novelStatus"),i=require("@libs/defaultCover"),o=require("@libs/storage"),n=function(){function n(e){var t,a,s;this.hideLocked=o.storage.get("hideLocked"),this.id=e.id,this.name=e.sourceName,this.icon="multisrc/lightnovelwp/".concat(e.id.toLowerCase(),"/icon.png"),this.site=e.sourceSite;var l=(null===(t=e.options)||void 0===t?void 0:t.versionIncrements)||0;this.version="1.1.".concat(10+l),this.options=null!==(a=e.options)&&void 0!==a?a:{},this.filters=e.filters,(null===(s=this.options)||void 0===s?void 0:s.hasLocked)&&(this.pluginSettings={hideLocked:{value:"",label:"Hide locked chapters",type:"Switch"}})}return n.prototype.getHostname=function(e){var t=(e=e.split("/")[2]).split(".");return t.pop(),t.join(".")},n.prototype.safeFecth=function(a,s){return e(this,void 0,void 0,function(){var e,r,i,o,n,c,u,v;return t(this,function(t){switch(t.label){case 0:return e=a.split("://"),r=e.shift(),i=e[0].replace(/\/\//g,"/"),[4,(0,l.fetchApi)(r+"://"+i)];case 1:if(!(o=t.sent()).ok&&1!=s)throw new Error("Could not reach site ("+o.status+") try to open in webview.");return[4,o.text()];case 2:if(n=t.sent(),c=null===(v=null===(u=n.match(/<title>(.*?)<\/title>/))||void 0===u?void 0:u[1])||void 0===v?void 0:v.trim(),this.getHostname(a)!=this.getHostname(o.url)||c&&("Bot Verification"==c||"You are being redirected..."==c||"Un instant..."==c||"Just a moment..."==c||"Redirecting..."==c))throw new Error("Captcha error, please open in webview (or the website has changed url)");return[2,n]}})})},n.prototype.parseNovels=function(e){var t=this;e=(0,a.load)(e).html();var s=[];return(e.match(/<article([^]*?)<\/article>/g)||[]).forEach(function(e){var a=e.match(/<a href="([^"]*)".*? title="([^"]*)"/)||[],l=a[1],r=a[2];if(r&&l){var o=e.match(/<img [^>]*?src="([^"]*)"[^>]*?(?: data-src="([^"]*)")?[^>]*>/)||[],n=void 0;if(l.includes(t.site))n=l.replace(t.site,"");else{var c=l.split("/");c.shift(),c.shift(),c.shift(),n=c.join("/")}s.push({name:r,cover:o[2]||o[1]||i.defaultCover,path:n})}}),s},n.prototype.popularNovels=function(a,s){return e(this,arguments,void 0,function(e,a){var s,l,r,i,o,n,c,u,v,p=a.filters,h=a.showLatestNovels;return t(this,function(t){switch(t.label){case 0:for(r in s=null!==(v=null===(u=this.options)||void 0===u?void 0:u.seriesPath)&&void 0!==v?v:"/series/",l=this.site+s+"?page="+e,p||(p=this.filters||{}),h&&(l+="&order=latest"),p)if("object"==typeof p[r].value)for(i=0,o=p[r].value;i<o.length;i++)n=o[i],l+="&".concat(r,"=").concat(n);else p[r].value&&(l+="&".concat(r,"=").concat(p[r].value));return[4,this.safeFecth(l,!1)];case 1:return c=t.sent(),[2,this.parseNovels(c)]}})})},n.prototype.parseNovel=function(a){return e(this,void 0,void 0,function(){var e,l,o,n,u,v,p,h,d,f,b,m,g,y,w,k,N,C,S,x,L;return t(this,function(t){switch(t.label){case 0:return e=this.site,[4,this.safeFecth(e+a,!1)];case 1:return l=t.sent(),o={path:a,name:"",genres:"",summary:"",author:"",artist:"",status:"",chapters:[]},n=!1,u=!1,v=0,p=!1,h=!1,d=!1,f=!1,b=!1,m=!1,g=!1,y=0,w=!1,k=!1,N=[],C={},S=this.hideLocked,x=new s.Parser({onopentag:function(t,a){var s;!o.cover&&(null===(s=a.class)||void 0===s?void 0:s.includes("ts-post-image"))?(o.name=a.title,o.cover=a["data-src"]||a.src||i.defaultCover):"genxed"===a.class||"sertogenre"===a.class?n=!0:n&&"a"===t?u=!0:"div"!==t||"entry-content"!==a.class&&"description"!==a.itemprop?"spe"===a.class||"serl"===a.class?p=!0:p&&"span"===t?h=!0:"div"===t&&"sertostat"===a.class?(p=!0,h=!0,b=!0):a.class&&a.class.includes("eplister")?m=!0:m&&"li"===t?g=!0:g?"a"===t&&void 0===C.path?C.path=a.href.replace(e,"").trim():"epl-num"===a.class?y=1:"epl-title"===a.class?y=2:"epl-date"===a.class?y=3:"epl-price"===a.class&&(y=4):!v||"div"!==t&&"script"!==t||v++:v++},ontext:function(e){var t,a;if(n)u&&(o.genres+=e+", ");else if(1===v&&e.trim())o.summary+=e;else if(p){if(h){var s=e.toLowerCase().replace(":","").trim();if(d)o.author+=e||"Unknown";else if(f)o.artist+=e||"Unknown";else if(b)switch(s){case"مكتملة":case"completed":case"complété":case"completo":case"completado":case"tamamlandı":o.status=r.NovelStatus.Completed;break;case"مستمرة":case"ongoing":case"en cours":case"em andamento":case"en progreso":case"devam ediyor":o.status=r.NovelStatus.Ongoing;break;case"متوقفة":case"hiatus":case"en pause":case"hiato":case"pausa":case"pausado":case"duraklatıldı":o.status=r.NovelStatus.OnHiatus;break;default:o.status=r.NovelStatus.Unknown}switch(s){case"الكاتب":case"author":case"auteur":case"autor":case"yazar":d=!0;break;case"الحالة":case"status":case"statut":case"estado":case"durum":b=!0;break;case"الفنان":case"artist":case"artiste":case"artista":case"çizer":f=!0}}}else if(m&&g)if(1===y)e.includes("🔒")?(w=!0,k=!0):k&&(w=!1),c(e,C);else if(2===y)C.name=(null===(a=null===(t=e.match(RegExp("^".concat(o.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"\\s*(.+)"))))||void 0===t?void 0:t[1])||void 0===a?void 0:a.trim())||e.trim(),C.chapterNumber||c(e,C);else if(3===y)C.releaseTime=e;else if(4===y){switch(s=e.toLowerCase().trim()){case"free":case"gratuit":case"مجاني":case"livre":case"":w=!1;break;default:w=!0}}},onclosetag:function(e){var t,a,s;n?u?u=!1:(n=!1,o.genres=null===(t=o.genres)||void 0===t?void 0:t.slice(0,-2)):v?"p"===e?o.summary+="\n\n":"br"===e?o.summary+="\n":"div"!==e&&"script"!==e||v--:p?h?"span"===e&&(h=!1,d&&o.author?d=!1:f&&o.artist?f=!1:b&&""!==o.status&&(b=!1)):"div"===e&&(p=!1,o.author=null===(a=o.author)||void 0===a?void 0:a.trim(),o.artist=null===(s=o.artist)||void 0===s?void 0:s.trim()):m&&(g?1===y||2===y||3===y||4===y?y=0:"li"===e&&(g=!1,C.chapterNumber||(C.chapterNumber=0),w&&(C.name="🔒 "+C.name),S&&w||N.push(C),C={}):"ul"===e&&(m=!1))}}),x.write(l),x.end(),N.length&&((null===(L=this.options)||void 0===L?void 0:L.reverseChapters)&&N.reverse(),o.chapters=N),o.summary=o.summary.trim(),[2,o]}})})},n.prototype.parseChapter=function(s){return e(this,void 0,void 0,function(){var e,l,r,i,o;return t(this,function(t){switch(t.label){case 0:return[4,this.safeFecth(this.site+s,!1)];case 1:if(e=t.sent(),null===(r=this.options)||void 0===r?void 0:r.customJs)try{l=(0,a.load)(e),e=l.html()}catch(e){throw console.error("Error executing customJs:",e),e}return[2,(null===(o=null===(i=e.match(/<div.*?class="epcontent ([^]*?)<div.*?class="?bottomnav/g))||void 0===i?void 0:i[0].match(/<p[^>]*>([^]*?)<\/p>/g))||void 0===o?void 0:o.join("\n"))||""]}})})},n.prototype.searchNovels=function(a,s){return e(this,void 0,void 0,function(){var e,l;return t(this,function(t){switch(t.label){case 0:return e=this.site+"page/"+s+"/?s="+encodeURIComponent(a),[4,this.safeFecth(e,!0)];case 1:return l=t.sent(),[2,this.parseNovels(l)]}})})},n}();function c(e,t){var a=e.match(/(\d+)$/);a&&a[0]&&(t.chapterNumber=parseInt(a[0]))}exports.LightNovelWPPlugin=n;var u=new n({id:"arcane",sourceSite:"https://arcanetranslations.com/",sourceName:"Arcane Translations",options:{reverseChapters:!0,lang:"English",hasLocked:!0},filters:{"genre[]":{type:"Checkbox",label:"Genre",value:[],options:[{label:"Academy",value:"academy"},{label:"Action",value:"action"},{label:"Adventure",value:"adventure"},{label:"Apocalypse",value:"apocalypse"},{label:"Comedy",value:"comedy"},{label:"Cyberpunk",value:"cyberpunk"},{label:"Drama",value:"drama"},{label:"Ecchi",value:"ecchi"},{label:"Fantasy",value:"fantasy"},{label:"Fusion",value:"fusion"},{label:"Game World",value:"game-world"},{label:"Harem",value:"harem"},{label:"Martial Arts",value:"martial-arts"},{label:"Medieval",value:"medieval"},{label:"Misunderstandings",value:"misunderstandings"},{label:"Modern",value:"modern"},{label:"Mystery",value:"mystery"},{label:"Obsession",value:"obsession"},{label:"Possession",value:"possession"},{label:"Psychological",value:"psychological"},{label:"Regression",value:"regression"},{label:"Regret",value:"regret"},{label:"Reincarnation",value:"reincarnation"},{label:"Romance",value:"romance"},{label:"School Life",value:"school-life"},{label:"Sci-Fi",value:"sci-fi"},{label:"Seinen",value:"seinen"},{label:"Shounen",value:"shounen"},{label:"Slice of Life",value:"slice-of-life"},{label:"Smut",value:"smut"},{label:"Supernatural",value:"supernatural"},{label:"Tragedy",value:"tragedy"},{label:"Transmigration",value:"transmigration"},{label:"War",value:"war"},{label:"Wuxia",value:"wuxia"}]},"type[]":{type:"Checkbox",label:"Type",value:[],options:[{label:"Chinese Novel",value:"chinese-novel"},{label:"Japanese Novel",value:"japanese-novel"},{label:"Korean Novel",value:"korean-novel"},{label:"Web Novel",value:"web-novel"}]},status:{type:"Picker",label:"Status",value:"",options:[{label:"All",value:""},{label:"Ongoing",value:"ongoing"},{label:"Hiatus",value:"hiatus"},{label:"Completed",value:"completed"}]},order:{type:"Picker",label:"Order by",value:"",options:[{label:"Default",value:""},{label:"A-Z",value:"title"},{label:"Z-A",value:"titlereverse"},{label:"Latest Update",value:"update"},{label:"Latest Added",value:"latest"},{label:"Popular",value:"popular"},{label:"Rating",value:"rating"}]}}});exports.default=u; |