Files
lnreader-plugins/.js/src/plugins/english/NovelsKnight[lightnovelwp].js
T
2026-09-25 13:41:04 -03:00

1 line
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var e=this&&this.__awaiter||function(e,a,t,l){return new(t||(t=Promise))(function(i,n){function o(e){try{s(l.next(e))}catch(e){n(e)}}function r(e){try{s(l.throw(e))}catch(e){n(e)}}function s(e){var a;e.done?i(e.value):(a=e.value,a instanceof t?a:new t(function(e){e(a)})).then(o,r)}s((l=l.apply(e,a||[])).next())})},a=this&&this.__generator||function(e,a){var t,l,i,n={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=r(0),o.throw=r(1),o.return=r(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function r(r){return function(s){return function(r){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,r[0]&&(n=0)),n;)try{if(t=1,l&&(i=2&r[0]?l.return:r[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,r[1])).done)return i;switch(l=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return n.label++,{value:r[1],done:!1};case 5:n.label++,l=r[1],r=[0];continue;case 7:r=n.ops.pop(),n.trys.pop();continue;default:if(!(i=n.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){n=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){n.label=r[1];break}if(6===r[0]&&n.label<i[1]){n.label=i[1],i=r;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(r);break}i[2]&&n.ops.pop(),n.trys.pop();continue}r=a.call(e,n)}catch(e){r=[6,e],l=0}finally{t=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LightNovelWPPlugin=void 0;var t=require("cheerio"),l=require("htmlparser2"),i=require("@libs/fetch"),n=require("@libs/novelStatus"),o=require("@libs/defaultCover"),r=require("@libs/storage"),s=function(){function s(e){var a,t,l;this.hideLocked=r.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 i=(null===(a=e.options)||void 0===a?void 0:a.versionIncrements)||0;this.version="1.1.".concat(10+i),this.options=null!==(t=e.options)&&void 0!==t?t:{},this.filters=e.filters,(null===(l=this.options)||void 0===l?void 0:l.hasLocked)&&(this.pluginSettings={hideLocked:{value:"",label:"Hide locked chapters",type:"Switch"}})}return s.prototype.getHostname=function(e){var a=(e=e.split("/")[2]).split(".");return a.pop(),a.join(".")},s.prototype.safeFecth=function(t,l){return e(this,void 0,void 0,function(){var e,n,o,r,s,u,c,v;return a(this,function(a){switch(a.label){case 0:return e=t.split("://"),n=e.shift(),o=e[0].replace(/\/\//g,"/"),[4,(0,i.fetchApi)(n+"://"+o)];case 1:if(!(r=a.sent()).ok&&1!=l)throw new Error("Could not reach site ("+r.status+") try to open in webview.");return[4,r.text()];case 2:if(s=a.sent(),u=null===(v=null===(c=s.match(/<title>(.*?)<\/title>/))||void 0===c?void 0:c[1])||void 0===v?void 0:v.trim(),this.getHostname(t)!=this.getHostname(r.url)||u&&("Bot Verification"==u||"You are being redirected..."==u||"Un instant..."==u||"Just a moment..."==u||"Redirecting..."==u))throw new Error("Captcha error, please open in webview (or the website has changed url)");return[2,s]}})})},s.prototype.parseNovels=function(e){var a=this;e=(0,t.load)(e).html();var l=[];return(e.match(/<article([^]*?)<\/article>/g)||[]).forEach(function(e){var t=e.match(/<a href="([^"]*)".*? title="([^"]*)"/)||[],i=t[1],n=t[2];if(n&&i){var r=e.match(/<img [^>]*?src="([^"]*)"[^>]*?(?: data-src="([^"]*)")?[^>]*>/)||[],s=void 0;if(i.includes(a.site))s=i.replace(a.site,"");else{var u=i.split("/");u.shift(),u.shift(),u.shift(),s=u.join("/")}l.push({name:n,cover:r[2]||r[1]||o.defaultCover,path:s})}}),l},s.prototype.popularNovels=function(t,l){return e(this,arguments,void 0,function(e,t){var l,i,n,o,r,s,u,c,v,h=t.filters,p=t.showLatestNovels;return a(this,function(a){switch(a.label){case 0:for(n in l=null!==(v=null===(c=this.options)||void 0===c?void 0:c.seriesPath)&&void 0!==v?v:"/series/",i=this.site+l+"?page="+e,h||(h=this.filters||{}),p&&(i+="&order=latest"),h)if("object"==typeof h[n].value)for(o=0,r=h[n].value;o<r.length;o++)s=r[o],i+="&".concat(n,"=").concat(s);else h[n].value&&(i+="&".concat(n,"=").concat(h[n].value));return[4,this.safeFecth(i,!1)];case 1:return u=a.sent(),[2,this.parseNovels(u)]}})})},s.prototype.parseNovel=function(t){return e(this,void 0,void 0,function(){var e,i,r,s,c,v,h,p,f,b,d,m,g,y,w,k,q,N,x,S,C;return a(this,function(a){switch(a.label){case 0:return e=this.site,[4,this.safeFecth(e+t,!1)];case 1:return i=a.sent(),r={path:t,name:"",genres:"",summary:"",author:"",artist:"",status:"",chapters:[]},s=!1,c=!1,v=0,h=!1,p=!1,f=!1,b=!1,d=!1,m=!1,g=!1,y=0,w=!1,k=!1,q=[],N={},x=this.hideLocked,S=new l.Parser({onopentag:function(a,t){var l;!r.cover&&(null===(l=t.class)||void 0===l?void 0:l.includes("ts-post-image"))?(r.name=t.title,r.cover=t["data-src"]||t.src||o.defaultCover):"genxed"===t.class||"sertogenre"===t.class?s=!0:s&&"a"===a?c=!0:"div"!==a||"entry-content"!==t.class&&"description"!==t.itemprop?"spe"===t.class||"serl"===t.class?h=!0:h&&"span"===a?p=!0:"div"===a&&"sertostat"===t.class?(h=!0,p=!0,d=!0):t.class&&t.class.includes("eplister")?m=!0:m&&"li"===a?g=!0:g?"a"===a&&void 0===N.path?N.path=t.href.replace(e,"").trim():"epl-num"===t.class?y=1:"epl-title"===t.class?y=2:"epl-date"===t.class?y=3:"epl-price"===t.class&&(y=4):!v||"div"!==a&&"script"!==a||v++:v++},ontext:function(e){var a,t;if(s)c&&(r.genres+=e+", ");else if(1===v&&e.trim())r.summary+=e;else if(h){if(p){var l=e.toLowerCase().replace(":","").trim();if(f)r.author+=e||"Unknown";else if(b)r.artist+=e||"Unknown";else if(d)switch(l){case"مكتملة":case"completed":case"complété":case"completo":case"completado":case"tamamlandı":r.status=n.NovelStatus.Completed;break;case"مستمرة":case"ongoing":case"en cours":case"em andamento":case"en progreso":case"devam ediyor":r.status=n.NovelStatus.Ongoing;break;case"متوقفة":case"hiatus":case"en pause":case"hiato":case"pausa":case"pausado":case"duraklatıldı":r.status=n.NovelStatus.OnHiatus;break;default:r.status=n.NovelStatus.Unknown}switch(l){case"الكاتب":case"author":case"auteur":case"autor":case"yazar":f=!0;break;case"الحالة":case"status":case"statut":case"estado":case"durum":d=!0;break;case"الفنان":case"artist":case"artiste":case"artista":case"çizer":b=!0}}}else if(m&&g)if(1===y)e.includes("🔒")?(w=!0,k=!0):k&&(w=!1),u(e,N);else if(2===y)N.name=(null===(t=null===(a=e.match(RegExp("^".concat(r.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"\\s*(.+)"))))||void 0===a?void 0:a[1])||void 0===t?void 0:t.trim())||e.trim(),N.chapterNumber||u(e,N);else if(3===y)N.releaseTime=e;else if(4===y){switch(l=e.toLowerCase().trim()){case"free":case"gratuit":case"مجاني":case"livre":case"":w=!1;break;default:w=!0}}},onclosetag:function(e){var a,t,l;s?c?c=!1:(s=!1,r.genres=null===(a=r.genres)||void 0===a?void 0:a.slice(0,-2)):v?"p"===e?r.summary+="\n\n":"br"===e?r.summary+="\n":"div"!==e&&"script"!==e||v--:h?p?"span"===e&&(p=!1,f&&r.author?f=!1:b&&r.artist?b=!1:d&&""!==r.status&&(d=!1)):"div"===e&&(h=!1,r.author=null===(t=r.author)||void 0===t?void 0:t.trim(),r.artist=null===(l=r.artist)||void 0===l?void 0:l.trim()):m&&(g?1===y||2===y||3===y||4===y?y=0:"li"===e&&(g=!1,N.chapterNumber||(N.chapterNumber=0),w&&(N.name="🔒 "+N.name),x&&w||q.push(N),N={}):"ul"===e&&(m=!1))}}),S.write(i),S.end(),q.length&&((null===(C=this.options)||void 0===C?void 0:C.reverseChapters)&&q.reverse(),r.chapters=q),r.summary=r.summary.trim(),[2,r]}})})},s.prototype.parseChapter=function(l){return e(this,void 0,void 0,function(){var e,i,n,o,r;return a(this,function(a){switch(a.label){case 0:return[4,this.safeFecth(this.site+l,!1)];case 1:if(e=a.sent(),null===(n=this.options)||void 0===n?void 0:n.customJs)try{return(i=(0,t.load)(e))(".announ").remove(),[2,i(".epcontent").eq(-1).find("p").map(function(e,a){return"<p>"+i(this).text()+"</p>"}).toArray().join("\n")||""]}catch(e){throw console.error("Error executing customJs:",e),e}return[2,(null===(r=null===(o=e.match(/<div.*?class="epcontent ([^]*?)<div.*?class="?bottomnav/g))||void 0===o?void 0:o[0].match(/<p[^>]*>([^]*?)<\/p>/g))||void 0===r?void 0:r.join("\n"))||""]}})})},s.prototype.searchNovels=function(t,l){return e(this,void 0,void 0,function(){var e,i;return a(this,function(a){switch(a.label){case 0:return e=this.site+"page/"+l+"/?s="+encodeURIComponent(t),[4,this.safeFecth(e,!0)];case 1:return i=a.sent(),[2,this.parseNovels(i)]}})})},s}();function u(e,a){var t=e.match(/(\d+)$/);t&&t[0]&&(a.chapterNumber=parseInt(t[0]))}exports.LightNovelWPPlugin=s;var c=new s({id:"novelsknight",sourceSite:"https://novelsknight.punchmanga.online/",sourceName:"NovelsKnight",options:{lang:"English",reverseChapters:!0,versionIncrements:2,customJs:"$('.announ').remove(); return $('.epcontent').eq(-1).find('p').map(function (i, el) { return '<p>' + $(this).text() + '</p>'; }).toArray().join('\\n') || '';"},filters:{"genre[]":{type:"Checkbox",label:"Genre",value:[],options:[{label:"city",value:"city"},{label:"cultivation",value:"cultivation"},{label:"faloo",value:"faloo"},{label:"Fan fiction",value:"fan-fiction"},{label:"fanfiction",value:"fanfiction"},{label:"fanqie",value:"fanqie"},{label:"fanstay",value:"fanstay"},{label:"fantansy",value:"fantansy"},{label:"fantasy",value:"fantasy"},{label:"horror",value:"horror"},{label:"immortal",value:"immortal"},{label:"Infinite Heavens",value:"infinite-heavens"},{label:"Infinity",value:"infinity"},{label:"light novel",value:"light-novel"},{label:"martial arts",value:"martial-arts"},{label:"military history",value:"military-history"},{label:"novel",value:"novel"},{label:"qidian",value:"qidian"},{label:"rebirth",value:"rebirth"},{label:"romance",value:"romance"},{label:"sc-fi online game",value:"sc-fi-online-game"},{label:"Sci-fi online games",value:"sci-fi-online-games"},{label:"Science fiction online game",value:"science-fiction-online-game"},{label:"sport",value:"sport"},{label:"Sports",value:"sports"},{label:"system",value:"system"},{label:"time travel",value:"time-travel"},{label:"travel",value:"travel"},{label:"Unlimited Heavens",value:"unlimited-heavens"},{label:"urban",value:"urban"},{label:"urrban",value:"urrban"}]},"type[]":{type:"Checkbox",label:"Type",value:[],options:[{label:"Black Basket: Platinum Star",value:"black-basket-platinum-star"},{label:"chinesse",value:"chinesse"},{label:"ciweimao",value:"ciweimao"},{label:"Doomsday",value:"doomsday"},{label:"dragon ball",value:"dragon-ball"},{label:"Entertainment",value:"entertainment"},{label:"f",value:"f"},{label:"falo",value:"falo"},{label:"faloo",value:"faloo"},{label:"falooo",value:"falooo"},{label:"fan fiction",value:"fan-fiction"},{label:"fanqie",value:"fanqie"},{label:"fanqienovel",value:"fanqienovel"},{label:"Fantasy",value:"fantasy"},{label:"faoo",value:"faoo"},{label:"Football",value:"football"},{label:"Harry Potter",value:"harry-potter"},{label:"horror",value:"horror"},{label:"Hunter X Hunter",value:"hunter-x-hunter"},{label:"Infinite Evolution",value:"infinite-evolution"},{label:"jjwxc",value:"jjwxc"},{label:"Lords: Opens with a Bloody Nest",value:"lords-opens-with-a-bloody-nest"},{label:"martial arts",value:"martial-arts"},{label:"marvel",value:"marvel"},{label:"naruto",value:"naruto"},{label:"nba",value:"nba"},{label:"nove",value:"nove"},{label:"novel",value:"novel"},{label:"one piece",value:"one-piece"},{label:"online game",value:"online-game"},{label:"Please",value:"please"},{label:"qiamao",value:"qiamao"},{label:"qidian",value:"qidian"},{label:"qimao",value:"qimao"},{label:"qq",value:"qq"},{label:"romance",value:"romance"},{label:"Sci-Fi",value:"sci-fi"},{label:"Science-fiction",value:"science-fiction"},{label:"sfacg",value:"sfacg"},{label:"this is a world of horror",value:"this-is-a-world-of-horror"},{label:"Urban",value:"urban"},{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=c;