bachngocsach vip chapter content copy

This script let you save the content of the reading chapter on bachngocsach.vip (vip.bachngocsach.com) from clipboard

目前為 2024-06-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        bachngocsach vip chapter content copy
// @name:en     bachngocsach vip chapter content copy
// @namespace   Violentmonkey Scripts
// @match       https://bachngocsach.net.vn/*
// @grant       GM.setClipboard
// @version     1.0.1
// @author      Me
// @run-at       document-idle
// @description This script let you save the content of the reading chapter on bachngocsach.vip (vip.bachngocsach.com) from clipboard
// @description:en This script let you save the content of the reading chapter on bachngocsach.vip (vip.bachngocsach.com) from clipboard
// ==/UserScript==
let observeTimes = 1;
let oldURL='';

(async function () {
    let observer = new MutationObserver(async (mList)=>{
      mList.forEach(async (m)=>{
        if (m.target.className?.includes('published-content')&& window.location.href!=oldURL) {
            scrollTo(0,800);
            oldURL=window.location.href; ///?? xac định ddee ơ dau.
            await getChapterContent();
        }
      });
    });
    observer.observe(document.querySelector('body'), { childList: true, subtree:true });
})();

async function getChapterContent() {
  let arrEl=document.querySelectorAll('div.published-content');
  let goodText = arrEl[0].previousElementSibling?.innerText;
  let bad = arrEl[0];
  let badPara = Array(bad.children.length);
  let style = {};

  for (const eights of bad.children) {
    let className = eights.className.toLowerCase();
    style[className] = parseInt(getComputedStyle(eights).order);
    let badLine = Array(eights.children.length);
    for (const sixes of eights.children) {
      let tagName = sixes.tagName.toLowerCase();
      if (!style[tagName]) style[tagName] = parseInt(getComputedStyle(sixes).order);
      badLine[style[tagName]] = sixes.textContent;
    }
    badPara[style[className]] = badLine.join('');
  }
  let txt = (goodText.trim() + badPara.join('\n\n')).replaceAll(/\n{3,}/g, '\n\n').replaceAll('·','');
  await GM.setClipboard(txt);
  console.log(txt);
  return txt;
}

async function startDownload() {
  await GM.setValue('downloading',true);
  if(/^https:\/\/bachngocsach\.net\.vn\/truyen\/[a-z\-\d]+\/?$/.test(window.location.href)) window.location.assign(window.location.href+'/chuong-1');
  else window.location.reload();
}

function sleep(ms = 10) { return new Promise(rs => setTimeout(rs, ms)) };

function waitForKeyElement(sel = 'body', ms = 2000) {
  const delay = 100;
  const tries = Math.floor(ms / delay) + 1;
  return new Promise(async (rs, rj) => {
    let start = (new Date()).getTime();
    for await (const i of Array(tries)) {
      let result = document.querySelectorAll(sel);
      if (result.length > 0) rs(result);
      await sleep(delay);
    }
    rj('Khong có element');
  });
}