-- {"id":1784,"ver":"1.0.5","libVer":"1.0.0","author":"Xanvial"} local json = Require("dkjson") --- Identification number of the extension. --- Should be unique. Should be consistent in all references. --- --- Required. --- --- @type int local id = 1784 --- Name of extension to display to the user. --- Should match index. --- --- Required. --- --- @type string local name = "Read Light Novel.app" --- Base URL of the extension. Used to open web view in Shosetsu. --- --- Required. --- --- @type string local baseURL = "https://readlightnovel.app/" -- --- URL of the logo. --- --- Optional, Default is empty. --- --- @type string local imageURL = "https://readlightnovel.online/assets/new/images/lnrlogo.png" --- Shosetsu tries to handle cloudflare protection if this is set to true. --- --- Optional, Default is false. --- --- @type boolean local hasCloudFlare = false --- If the website has search. --- --- Optional, Default is true. --- --- @type boolean local hasSearch = true --- If the websites search increments or not. --- --- Optional, Default is true. --- --- @type boolean local isSearchIncrementing = false --- Filters to display via the filter fab in Shosetsu. --- --- Optional, Default is none. --- --- @type Filter[] | Array local searchFilters = {} -- TODO --- Internal settings store. --- --- Completely optional. --- But required if you want to save results from [updateSetting]. --- --- Notice, each key is surrounded by "[]" and the value is on the right side. --- @type table local settings = {} -- TODO --- Settings model for Shosetsu to render. --- --- Optional, Default is empty. --- --- @type Filter[] | Array local settingsModel = {} -- TODO --- ChapterType provided by the extension. --- --- Optional, Default is STRING. But please do HTML. --- --- @type ChapterType local chapterType = ChapterType.HTML --- Index that pages start with. For example, the first page of search is index 1. --- --- Optional, Default is 1. --- --- @type number local startIndex = 1 --- Called to get list of novels from a page. --- --- @param url string address of the page --- @return Novel[] | Array local function parseList(url) return map(GETDocument(url):select("div.cm-list > ul > li"), function(v) local novel = Novel() local categoryData = v:selectFirst("div.category-name") local data = categoryData:selectFirst("a") novel:setTitle(data:text()) novel:setLink(data:attr("href")) local categoryImage = v:selectFirst("div.category-img") novel:setImageURL(categoryImage:selectFirst("img"):attr("src")) return novel end) end --- Listings that users can navigate in Shosetsu. --- --- Required, 1 value at minimum. --- --- @type Listing[] | Array local listings = { Listing("Top Rated", true, function(data) --- @type int local page = data[PAGE] local url = baseURL .. "ranking/top-rated/" .. page return parseList(url) end), Listing("New", true, function(data) -- Many sites use the baseURL + some path, you can perform the URL construction here. -- You can also extract query data from [data]. But do perform a null check, for safety. --- @type int local page = data[PAGE] local url = baseURL .. "ranking/new/" .. page return parseList(url) end), Listing("Most Viewed", true, function(data) --- @type int local page = data[PAGE] local url = baseURL .. "ranking/most-viewed/" .. page return parseList(url) end) } --- Shrink the website url down. This is for space saving purposes. --- --- Required. --- --- @param url string Full URL to shrink. --- @param type int Either KEY_CHAPTER_URL or KEY_NOVEL_URL. --- @return string Shrunk URL. local function shrinkURL(url, type) return url:gsub(baseURL, "") end --- Expand a given URL. --- --- Required. --- --- @param url string Shrunk URL to expand. --- @param type int Either KEY_CHAPTER_URL or KEY_NOVEL_URL. --- @return string Full URL. local function expandURL(url, type) return baseURL .. url end --- Get a chapter passage based on its chapterURL. --- --- Required. --- --- @param chapterURL string The chapters shrunken URL. --- @return string Strings in lua are byte arrays. If you are not outputting strings/html you can return a binary stream. local function getPassage(chapterURL) local url = expandURL(chapterURL, KEY_CHAPTER_URL) --- Chapter page, extract info from it. local doc = GETDocument(url) local htmlElement = doc:selectFirst("#chapterText") local title = doc:selectFirst(".section-header-title > span"):text() htmlElement:child(0):before("