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 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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');
  });
}