kone
ainovel
ainovel

ciweimao 긁어오는 템퍼몽키

정보
4,477 views · 6 points

치웨이마오에서 무료공개된 에피소드들을 긁어오는 템퍼몽키에요..

로그인해서 결제해놓으면 아마도 결제해놓은곳까지 갈 겁니다… 아마도요.

요 밑에 보면 ‘여기서부터 자동 수집’ 버튼 누르면 2초에 한번씩 페이지가 넘어가면서 텍스트로 긁어옵니다. 복사방지 코드같은것도 있는데 이건 안 긁어오더라구요.

1

일단 요렇게 extension 설정에서 사용자 스크립트 허용, 개발자 모드가 기본으로 되어있어야 합니다.

1

당연히 제가 만든게 아니라 구글놈이 만든거기 때문에… 잘 안되면 저도 뭐가 문젠지 잘 모르겠습니다.

일단 코드 올리니까 -템퍼몽키 - 새 스크립트 만들기 - 코드 입력하는 부분에 싹 다 지우고 밑에 보이는 코드 그대로 붙여넣기 하면 될겁니다. 아마도요…?

안되면 알려주세요. 글 내릴게용...

// UserScript

// @name Ciweimao 무료 회차 클린 수집기

// @namespace http://tampermonkey.net/

// @version 1.1

// @description 츠웨이마오 무료 본문에서 3QQhIw 등 워터마크/댓글 숫자를 완벽 제거하고 TXT로 저장합니다.

// @author Custom

// @match ://.ciweimao.com/chapter/*

// @run-at document-end

// @grant none

// /UserScript

(function() {

'use strict';

const STORAGE_KEY_TEXT = 'cwm_scraped_novel_text';

const STORAGE_KEY_COUNT = 'cwm_scraped_chapter_count';

const STORAGE_KEY_RUNNING = 'cwm_scraper_is_running';

// 1. 우측 하단 컨트롤 패널 UI 생성 (중복 생성 방지)

function createPanel() {

if (document.getElementById('cwm-scraper-panel')) return;

const panel = document.createElement('div');

panel.id = 'cwm-scraper-panel';

panel.style.cssText = `

position: fixed !important; bottom: 30px !important; right: 30px !important;

z-index: 2147483647 !important; background: #1e1e2e !important;

color: #cdd6f4 !important; padding: 16px !important;

border-radius: 10px !important; box-shadow: 0 8px 24px rgba(0,0,0,0.8) !important;

font-family: 'Malgun Gothic', sans-serif !important; font-size: 13px !important;

width: 240px !important; border: 2px solid #89b4fa !important;

`;

const isRunning = localStorage.getItem(STORAGE_KEY_RUNNING) === 'true';

const count = parseInt(localStorage.getItem(STORAGE_KEY_COUNT) || '0', 10);

panel.innerHTML = `

<div style="font-weight: bold; font-size: 14px; margin-bottom: 10px; color: #89b4fa; display:flex; justify-content:space-between;">

<span>📚 츠웨이마오 수집기</span>

<span id="cwm-count" style="color:#f9e2af;">${count}화 누적</span>

</div>

<div id="cwm-status" style="margin-bottom: 12px; color: #a6adc8; font-size: 12px; line-height: 1.4;">

상태: <b style="color:${isRunning ? '#a6e3a1' : '#f38ba8'};">${isRunning ? '자동 수집 중...' : '대기 중'}</b>

</div>

<div style="display: flex; flex-direction: column; gap: 6px;">

<button id="cwm-btn-toggle" style="padding: 8px; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; background: ${isRunning ? '#f38ba8' : '#a6e3a1'}; color: #11111b;">

${isRunning ? '⏹ 수집 일시정지' : '▶ 여기서부터 자동 수집'}

</button>

<button id="cwm-btn-download" style="padding: 8px; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; background: #89b4fa; color: #11111b;">

💾 누적 본문 TXT 다운로드

</button>

<button id="cwm-btn-clear" style="padding: 6px; border: none; border-radius: 5px; cursor: pointer; background: #45475a; color: #cdd6f4; font-size: 11px; margin-top: 4px;">

🗑️ 저장된 데이터 초기화

</button>

</div>

`;

document.body.appendChild(panel);

document.getElementById('cwm-btn-toggle').addEventListener('click', toggleScraping);

document.getElementById('cwm-btn-download').addEventListener('click', downloadTxt);

document.getElementById('cwm-btn-clear').addEventListener('click', clearData);

}

function updateStatus(msg) {

const el = document.getElementById('cwm-status');

if (el) el.innerHTML = msg;

}

// 2. 워터마크(3QQhIw 등) 및 댓글 숫자 완벽 세탁

function extractCleanChapter() {

const readBox = document.querySelector('#J_BookRead') || document.querySelector('.read-bd') || document.querySelector('#J_BookCnt');

if (!readBox) return null;

// 유료(VIP) 결제창 확인

const isVipLocked = document.querySelector('.J_BuyChapter, .vip-notice, .lock-chapter-box, #J_VipReadBox');

const rawParagraphs = readBox.querySelectorAll('p.chapter, p');

if (isVipLocked && rawParagraphs.length < 3) {

return { isVip: true };

}

// 제목 추출 (스크린샷의 '第一章 雨夜' 구조 대응)

const titleEl = document.querySelector('h1.chapter, .chapter-title, #J_BookReadTitle, .read-hd h3, h3.chapter');

const title = titleEl ? titleEl.innerText.trim() : document.title.split('-')[0].trim();

const cleanLines = [];

rawParagraphs.forEach(p => {

if (p.closest('.author-say, .vip-notice, .read-Args')) return;

const clone = p.cloneNode(true);

// [1단계] 자식 요소(<span>, <i> 등)로 들어간 워터마크 및 우측 댓글 버블 숫자 통째로 제거

// 츠웨이마오 본문은 순수 텍스트 노드로 되어있고, 워터마크(3QQhIw)와 댓글 숫자는 자식 태그에 들어갑니다.

clone.querySelectorAll('span, i, a, button, script, style, sup, sub, canvas, img, font, em, b, strong').forEach(el => {

el.remove();

});

let text = clone.innerText || clone.textContent || '';

// [2단계] 텍스트 노드에 직접 박혀있을 경우를 대비한 정규식 필터링

text = text

.replace(/[\u200B-\u200D\uFEFF\u00AD]/g, '') // 제로폭 공백 제거

.replace(/\s*[a-zA-Z0-9]{5,8}\s*$/g, '') // 문단 끝에 붙은 3QQhIw 같은 영숫자 난수 워터마크 제거

.replace(/\s+/g, ' ') // 다중 공백 압축

.trim();

if (text.length > 0) {

cleanLines.push(text);

}

});

if (cleanLines.length === 0) return null;

return {

isVip: false,

title: title,

content: cleanLines.join('\n\n')

};

}

// 3. 다음 화 이동 버튼 탐색

function findNextChapterUrl() {

const links = Array.from(document.querySelectorAll('a'));

const nextBtn = links.find(a =>

a.innerText.includes('下一章') ||

a.id === 'J_BtnPageNext' ||

a.classList.contains('next-chapter')

);

if (!nextBtn) return null;

const href = nextBtn.getAttribute('href');

if (!href || href.startsWith('javascript:') || href === '#') return null;

return href.startsWith('http') ? href : new URL(href, window.location.origin).href;

}

// 4. 자동 수집 메인 루프

function processCurrentPage() {

if (localStorage.getItem(STORAGE_KEY_RUNNING) !== 'true') return;

updateStatus('⏳ 본문 렌더링 대기 중...');

let attempts = 0;

const timer = setInterval(() => {

attempts++;

const result = extractCleanChapter();

if (result) {

clearInterval(timer);

if (result.isVip) {

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

updateStatus('🔒 <b>유료(VIP) 회차 도달!</b><br>자동 수집을 완료했습니다.');

downloadTxt();

return;

}

const prevText = localStorage.getItem(STORAGE_KEY_TEXT) || '';

const count = parseInt(localStorage.getItem(STORAGE_KEY_COUNT) || '0', 10) + 1;

const formattedChapter = ## ${result.title}\n\n${result.content}\n\n========================================\n\n;

try {

localStorage.setItem(STORAGE_KEY_TEXT, prevText + formattedChapter);

localStorage.setItem(STORAGE_KEY_COUNT, count.toString());

const countEl = document.getElementById('cwm-count');

if (countEl) countEl.innerText = ${count}화 누적;

} catch (e) {

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

alert('브라우저 임시 저장소 용량(약 5MB)이 꽉 찼습니다! 지금까지 수집한 분량을 먼저 다운로드합니다.');

downloadTxt();

return;

}

const nextUrl = findNextChapterUrl();

if (nextUrl && nextUrl.includes('/chapter/')) {

updateStatus(✅ <b>수집 완료!</b><br>2초 후 다음 화로 이동...);

setTimeout(() => {

window.location.href = nextUrl;

}, 2000);

} else {

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

updateStatus('🎉 <b>마지막 화 도달!</b><br>자동 수집을 완료했습니다.');

downloadTxt();

}

} else if (attempts >= 20) {

clearInterval(timer);

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

updateStatus('⚠️ <b>본문 감지 실패 또는 VIP 잠금.</b>');

}

}, 500);

}

function toggleScraping() {

const isRunning = localStorage.getItem(STORAGE_KEY_RUNNING) === 'true';

if (isRunning) {

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

location.reload();

} else {

localStorage.setItem(STORAGE_KEY_RUNNING, 'true');

processCurrentPage();

const btn = document.getElementById('cwm-btn-toggle');

btn.innerText = '⏹ 수집 일시정지';

btn.style.background = '#f38ba8';

}

}

function downloadTxt() {

const text = localStorage.getItem(STORAGE_KEY_TEXT);

if (!text) {

alert('아직 저장된 본문 데이터가 없습니다.');

return;

}

const count = localStorage.getItem(STORAGE_KEY_COUNT) || '0';

const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });

const url = URL.createObjectURL(blob);

const a = document.createElement('a');

a.href = url;

a.download = ciweimao_novel_${count}chapters.txt;

document.body.appendChild(a);

a.click();

document.body.appendChild(a);

URL.revokeObjectURL(url);

}

function clearData() {

if (confirm('지금까지 누적된 텍스트 데이터를 모두 지우시겠습니까?')) {

localStorage.removeItem(STORAGE_KEY_TEXT);

localStorage.removeItem(STORAGE_KEY_COUNT);

localStorage.setItem(STORAGE_KEY_RUNNING, 'false');

location.reload();

}

}

// 페이지 상태와 무관하게 즉시 실행 보장

function init() {

createPanel();

if (localStorage.getItem(STORAGE_KEY_RUNNING) === 'true') {

processCurrentPage();

}

}

if (document.readyState === 'loading') {

document.addEventListener('DOMContentLoaded', init);

} else {

init();

}

setTimeout(createPanel, 1000); // 혹시나 DOM이 덮어써질 경우를 대비한 1초 뒤 재확인

})();

6
5 comments
정보탭으로 변경함
(edited )
무료분은 모르겠지만 ciweimao는 유료분의 경우 웹에선 아예 이미지로 올라오기 때문에 안 될겁니다
이럴수가...
All
Title
Body