async function fetchLatestChapter(manga, website) {
  const html = (await axios.get(website)).data.split("\n");
  const tagPrefix = '<a href="';

  for (const line of html) {
    if (line.includes(manga) && line.includes(tagPrefix)) {
      // Extract the chapter URL from the current line
      const urlStart = line.indexOf(tagPrefix);
      let url = line.slice(urlStart + tagPrefix.length);
      url = url.slice(0, url.indexOf('">'));

      const chapNumStart = url.lastIndexOf("-");
      if (chapNumStart === -1) {
        return {
          // Remove excess slashes from the URL
          url: (website + url).replace(/([^:]\/)\/+/g, "$1"),
        };
      }

      // Extract the chapter number from the current line
      let chapNum = url.slice(chapNumStart + 1);
      if (chapNum.charAt(chapNum.length) === "\\") {
        // Remove the slash at the end
        chapNum = chapNum.slice(0, -1);
      }

      return {
        chapter: chapNum,
        // Remove excess slashes from the URL
        url: (website + url).replace(/([^:]\/)\/+/g, "$1"),
      };
    }
  }

  // There is no entry for the given manga on TCB's homepage
  return { error: "NOT_FOUND" };
}
/**
 * Fetch the latest manga chapter from TCBScans asynchronously.
 *
 * Scrap the homepage of TCBScans and search for data matching the given manga name.
 * The data fetched from TCBScans are the URL to the chapter page as well as the chapter number.
 * Finally, the data is returned in a JSON object wrapped into a Promise.
 * If the data could not be fetch, an error will be returned.
 *
 * @since       1.0.0
 * @access      public
 *
 * @param {string} manga    The manga name in Title Case.
 * @param {string} website  The url of TCBScans homepage.
 *
 * @return {Object} A Promise object containing a JSON object.
 */
Fetch the latest manga chapter from TCBScans asynchronously.
Scrap the homepage of TCBScans and search for data matching the given manga name.
The data fetched from TCBScans are the URL to the chapter page as well as the chapter number.
Finally, the data is returned in a JSON object wrapped into a Promise.
If the data could not be fetch, an error will be returned.



@param {string} manga    The manga name in Title Case.
@param {string} website  The url of TCBScans homepage.

@return {Object} A Promise object containing a JSON object.
Fetch the latest manga chapter from TCBScans asynchronously . Scrap the homepage of TCBScans and search for data matching the given manga name . The data fetched from TCBScans are the URL to the chapter page as well as the chapter number . Finally the data is returned in a JSON object wrapped into a Promise . If the data could not be fetch an error will be returned . @param { string } manga The manga name in Title Case . @param { string } website The url of TCBScans homepage . @return { Object } A Promise object containing a JSON object .
async function fetchLatestChapter(manga, website) {
  const html = (await axios.get(website)).data.split("\n");
  const tagPrefix = '<a href="';
  for (const line of html) {
    if (line.includes(manga) && line.includes(tagPrefix)) {
      const urlStart = line.indexOf(tagPrefix);
      let url = line.slice(urlStart + tagPrefix.length);
      url = url.slice(0, url.indexOf('">'));
      const chapNumStart = url.lastIndexOf("-");
      if (chapNumStart === -1) {
        return {
          url: (website + url).replace(/([^:]\/)\/+/g, "$1"),
        };
      }
      let chapNum = url.slice(chapNumStart + 1);
      if (chapNum.charAt(chapNum.length) === "\\") {
        chapNum = chapNum.slice(0, -1);
      }
      return {
        chapter: chapNum,
        url: (website + url).replace(/([^:]\/)\/+/g, "$1"),
      };
    }
  }
  return { error: "NOT_FOUND" };
}
async function fetchLatestChapter ( manga , website ) { const html = ( await axios . get ( website ) ) . data . split ( "\n" ) ; const tagPrefix = '<a href="' ; for ( const line of html ) { if ( line . includes ( manga ) && line . includes ( tagPrefix ) ) { const urlStart = line . indexOf ( tagPrefix ) ; let url = line . slice ( urlStart + tagPrefix . length ) ; url = url . slice ( 0 , url . indexOf ( '">' ) ) ; const chapNumStart = url . lastIndexOf ( "-" ) ; if ( chapNumStart === - 1 ) { return { url : ( website + url ) . replace ( / ([^:]\/)\/+ / g , "$1" ) , } ; } let chapNum = url . slice ( chapNumStart + 1 ) ; if ( chapNum . charAt ( chapNum . length ) === "\\" ) { chapNum = chapNum . slice ( 0 , - 1 ) ; } return { chapter : chapNum , url : ( website + url ) . replace ( / ([^:]\/)\/+ / g , "$1" ) , } ; } } return { error : "NOT_FOUND" } ; }
Fetch the latest manga chapter from TCBScans asynchronously.
Fetch the latest manga chapter from TCBScans asynchronously .
// Extract the chapter URL from the current line // Remove excess slashes from the URL // Extract the chapter number from the current line // Remove the slash at the end // Remove excess slashes from the URL // There is no entry for the given manga on TCB's homepage