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

  1. // ==UserScript==
  2. // @name bachngocsach vip chapter content copy
  3. // @name:en bachngocsach vip chapter content copy
  4. // @namespace Violentmonkey Scripts
  5. // @match https://bachngocsach.net.vn/*
  6. // @grant GM.setClipboard
  7. // @version 1.0.1
  8. // @author Me
  9. // @run-at document-idle
  10. // @description This script let you save the content of the reading chapter on bachngocsach.vip (vip.bachngocsach.com) from clipboard
  11. // @description:en This script let you save the content of the reading chapter on bachngocsach.vip (vip.bachngocsach.com) from clipboard
  12. // ==/UserScript==
  13.  
  14. let observeTimes = 1;
  15. let oldURL = '';
  16.  
  17. (async function () {
  18. let observer = new MutationObserver(async (mList) => {
  19. mList.forEach(async (m) => {
  20. if (m.target.className?.includes('published-content') && window.location.href != oldURL) {
  21. oldURL = window.location.href; ///?? xac định ddee ơ dau.
  22. await getChapterContent();
  23. }
  24. });
  25. });
  26. observer.observe(document.querySelector('body'), { childList: true, subtree: true });
  27. })();
  28.  
  29. async function getChapterContent() {
  30. let arrEl = document.querySelectorAll('div.published-content');
  31. let goodText = arrEl[0].previousElementSibling?.innerText;
  32. let bad = arrEl[0];
  33. let badPara = Array(bad.children.length);
  34. let style = {};
  35.  
  36. for (const eights of bad.children) {
  37. let className = eights.className.toLowerCase();
  38. style[className] = parseInt(getComputedStyle(eights).order);
  39. let badLine = Array(eights.children.length);
  40. for (const sixes of eights.children) {
  41. let tagName = sixes.tagName.toLowerCase();
  42. if (!style[tagName]) style[tagName] = parseInt(getComputedStyle(sixes).order);
  43. badLine[style[tagName]] = sixes.textContent;
  44. }
  45. badPara[style[className]] = badLine.join('');
  46. }
  47. let txt = (goodText.trim() + badPara.join('\n\n')).replaceAll(/\n{3,}/g, '\n\n');
  48. GM.setClipboard(txt);
  49. console.log(txt);
  50. return txt;
  51. }
  52.  
  53. async function startDownload() {
  54. GM.setValue('downloading', true);
  55. if (/^https:\/\/bachngocsach\.net\.vn\/truyen\/[a-z\-\d]+\/?$/.test(window.location.href)) window.location.assign(window.location.href + '/chuong-1');
  56. else window.location.reload();
  57. }
  58.  
  59. function sleep(ms = 10) { return new Promise(rs => setTimeout(rs, ms)) }
  60.  
  61. function waitForKeyElement(sel = 'body', ms = 2000) {
  62. const delay = 100;
  63. const tries = Math.floor(ms / delay) + 1;
  64. return new Promise(async (rs, rj) => {
  65. let start = (new Date()).getTime();
  66. for await (const i of Array(tries)) {
  67. let result = document.querySelectorAll(sel);
  68. if (result.length > 0) rs(result);
  69. await sleep(delay);
  70. }
  71. rj('Khong có element');
  72. });
  73. }