bachngocsach.vip chapter content copy

Đét cmn sờ cờ rip sân

目前為 2024-03-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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
// @namespace   Violentmonkey Scripts
// @match       https://bachngocsach.vip/*
// @match       https://vip.bachngocsach.com/*
// @grant       GM.setClipboard
// @version     1.0
// @author      -
// @run-at       document-end
// @description Đét cmn sờ cờ rip sân
// ==/UserScript==


function getStyle(style) {
  if (!style||typeof style!=='string') return false;
  console.log('Style: ',style);
  let result = {};
  style.split('}').forEach(e=>{
    let name= e.startsWith('.')?e.slice(1,e.indexOf('{')):e.slice(0,e.indexOf('{'));
    let order=parseInt(e.slice(e.indexOf(':')+1));
    result[name]=order;
  });
  return result;
}

async function sleep(ms=10){ return new Promise((res)=> setTimeout(res,ms)) }

async function waitForKeyElements(selector='#content',delayTime=300,tries=10 ) {
  return new Promise(async (res)=> {
   for(let i=0; i<tries; i++) {
      let result=document.querySelectorAll(selector);
      if (result.length>0) res(result);
      await sleep(delayTime); }
   res(false);
  })
}

let oldUrl='';
async function bnsVipChapter() {
  console.log('Then go to here');
  if (oldUrl==window.location.href) return false;
  //let content = await waitForKeyElements('#chapter-id');
  let content = await waitForKeyElements('#id_chap_content');
  if (!content) return false;

  document.querySelector('#id_chap_content p:nth-child(2)').scrollIntoView();
  let style = await waitForKeyElements('#box-chapter-content style'); //return HTMLCollection or false
  console.log(style);
  if (style) style = getStyle(style[0].textContent);

  let txt = '';

  if (content.length > 0) {
    let goodText = document.querySelector('#chapter-id>div>div:nth-child(1)').textContent;
    let badText = document.querySelector('#chapter-id>div>div:nth-child(2)');

    let way = 'new';
    if (style) way = 'old';  //old,new
    console.log(style);
    let badPara = Array(badText.children.length);

    switch (way) {
      case 'old':
        for (const eights of badText.children) {
          let className = eights.className.toLowerCase();
          let badLine = Array(eights.children.length);
          for (const sixes of eights.children) badLine[style[sixes.tagName.toLowerCase()]] = sixes.textContent;
          badPara[style[className]] = badLine.join('');
        }
        break;

      case 'new':
        style = {};
        for (let eights of badText.children) {
          let className = eights.className.toLowerCase();
          style[className] = parseInt(getComputedStyle(eights).order);
          let badLine = Array(eights.children.length);
          for (let sixes of eights.children) {
            let tagName = sixes.tagName.toLowerCase();
            if (!style[tagName]) style[tagName] = parseInt(getComputedStyle(sixes).order);
            badLine[style[tagName]] = sixes.textContent;
          }
          console.log(badLine);
          badPara[style[className]] = badLine.join('');
        }
        break;
    }//end switch
    console.log(style);

    badText = badPara.join('\n\n');
    txt = goodText.trim() + badText.trim();
  }
  GM.setClipboard(txt,'text/plain');
  console.log(txt);
  document.querySelector('#app').scrollIntoView();
}

let rootObserver;
let chapterObserver;

async function rootObserve() {
  if (!chapterObserver &&
      /(^http(s)?:\/\/vip.bachngocsach.com\/(dich|sang-tac)\/)|(^http(s)?:\/\/bachngocsach.vip\/(dich|sang-tac)\/)/i.test(window.location.href)) {
    chapterObserver= new MutationObserver(newChapterLoaded);
    //let target=document.querySelector('#box-chapter-content')??document.querySelector('#section-detail-story');
    let target=document.querySelector('#box-chapter-content');
    if (target) chapterObserver.observe(target, {childList: true, subtree: true });
  }

  if (chapterObserver &&
      !/(^http(s)?:\/\/vip.bachngocsach.com\/(dich|sang-tac)\/)|(^http(s)?:\/\/bachngocsach.vip\/(dich|sang-tac)\/)/i.test(window.location.href)) {
    chapterObserver.disconnect();
    chapterObserver=undefined;
  }
}

async function newChapterLoaded(e) {
  if (oldUrl==window.location.href) return false;
  await bnsVipChapter();
  oldurl=window.location.href;
  return true;
}

(async function () {
  await newChapterLoaded();
  rootObserver=new MutationObserver(rootObserve);
  rootObserver.observe(document.querySelector('#app:last-child'),{childList: true, subtree: true });

})();