This commit is contained in:
2025-10-13 18:57:22 +09:00
parent 197d704e27
commit e9b287cf81
4 changed files with 207 additions and 48 deletions
@@ -420,32 +420,66 @@ var time2 = null
var time1 = null
function gotoNext() {
clearTimeout(time1)
try{
console.log("targetUrl :: " + targetUrl);
if (document.querySelector('[class="btn-group"]')) {
time2 = setTimeout(function () {
clearTimeout(time2)
var targetElement = null
document.querySelector('[class="btn-group"]').querySelectorAll('a').forEach(function(e){
if(e.hasAttribute("href") &&
(
(e.getAttribute("href").search("page=2") > -1 && location.href.search("page") < 0) ||
(e.getAttribute("href").search("page=3") > -1 && location.href.search("page=2") > 0) ||
(e.getAttribute("href").search("page=4") > -1 && location.href.search("page=3") > 0)
)) {
targetElement = e
try {
let attempts = 0; // 시도 횟수를 기록할 변수
const maxAttempts = 8; // 최대 15초 동안 시도
let currentPage = 1; // 기본 페이지
}
})
if(targetElement !== null) {
targetElement.click()
} else {
// location.href = "https://naver.com"
// 1초마다 실행될 로직을 담는 변수
const findAndClickInterval = setInterval(function () {
attempts++; // 시도 횟수 증가
// 현재 페이지 번호 가져오기 (이 로직은 한 번만 실행해도 되지만, 페이지가 동적으로 바뀔 경우를 대비해 내부에 둡니다)
var pageMatch = location.href.match(/page=(\d+)/);
if (pageMatch && pageMatch[1]) {
currentPage = parseInt(pageMatch[1], 10);
toast(`[${0}초] ⏳ 다음 페이지 링크를 찾는 중... (현재: page=${currentPage})`)
}
var nextPage = currentPage + 1;
var targetElement = null;
document.querySelectorAll('.btn-group')?.forEach((el) => {
var pageLinks =el?.querySelectorAll('a');
if (pageLinks) {
pageLinks.forEach(function(link) {
toast(`[${attempts}초] ✅ 다음 페이지 링크를 찾는 중 ${link.getAttribute('href')}`);
if (link.getAttribute('href')?.includes(`page=${nextPage}`)) {
targetElement = link;
toast(`[${attempts}초] ✅ 다음 페이지 링크를 찾았습니다.`);
}
});
}
}, 15000);
}
} catch (e) {
})
// 1. 다음 페이지 링크를 찾았을 경우
if (attempts > 3 && targetElement) {
console.log(`[${attempts}초] ✅ 다음 페이지 링크를 찾았습니다. 클릭합니다.`);
toast(`[${attempts}초] ✅ 다음 페이지 링크를 찾았습니다. 클릭합니다.`)
clearInterval(findAndClickInterval); // 반복을 중단
targetElement.click(); // 링크 클릭
}
// 2. 시간(15초)이 초과되었을 경우
else if (attempts >= maxAttempts) {
console.log(`[${attempts}초] ❌ 시간 초과. 다음 페이지 링크를 찾지 못했습니다.`);
toast(`[${attempts}초] ❌ 시간 초과. 다음 페이지 링크를 찾지 못했습니다.`)
clearInterval(findAndClickInterval); // 반복을 중단
// 필요하다면 이곳에 다른 페이지로 이동하는 로직을 추가하세요.
// location.href = "https://naver.com";
}
// 3. 아직 링크를 찾지 못했고, 시간도 남았을 경우
else {
toast(`[${attempts}초] ⏳ 다음 페이지 링크를 찾는 중... (대상: page=${nextPage})`)
console.log(`[${attempts}초] ⏳ 다음 페이지 링크를 찾는 중... (대상: page=${nextPage})`);
}
}, 1500); // 1000ms = 1초마다 함수 실행
} catch (e) {
console.error("스크립트 실행 중 오류 발생:", e);
}
}
@@ -663,32 +697,83 @@ async function handleCommon() {
}
);
console.log(`Found TEST`);
const imageSelector = 'img[class*="mw-100"][src*="images"]';
const images = Array.from(document.querySelectorAll(imageSelector));
console.log(`Found ${images}`);
if (images.length > 0) {
const validImageUrls = images.map(img => img.src)
.filter(src => src && src.startsWith('http'));
const uniqueUrls = [...new Set(validImageUrls)];
let scrollInterval;
console.log(`Found ${'$'}{uniqueUrls.length} unique images to cache.`);
async function getImg() {
console.log(`Found TEST`);
const imageSelector = 'img[class*="mw-100"][src*="images"]';
const images = Array.from(document.querySelectorAll(imageSelector));
console.log(`Found ${images}`);
if (images.length > 0) {
const validImageUrls = images.map(img => img.src)
.filter(src => src && src.startsWith('http'));
const uniqueUrls = [...new Set(validImageUrls)];
console.log(`Found ${'$'}{uniqueUrls.length} unique images to cache.`);
for (const image of uniqueUrls) {
// 3. 각 URL을 순회하며 Base64로 변환하고 즉시 네이티브로 전송
// (모든 작업을 병렬로 처리하지 않고 순차적(또는 하나씩)으로 보내 메모리 부담을 줄임)
for (const url of uniqueUrls) {
const base64Data = await getBase64FromUrl(url);
if (base64Data) {
// 이미지 하나를 성공할 때마다 네이티브로 즉시 전송
sendMessage({
type: "SINGLE_IMAGE_DATA",
imgSrc: url,
base64Data: base64Data
});
}
// 3. 각 URL을 순회하며 Base64로 변환하고 즉시 네이티브로 전송
// (모든 작업을 병렬로 처리하지 않고 순차적(또는 하나씩)으로 보내 메모리 부담을 줄임)
var idx = 0
for (const url of uniqueUrls) {
try {
const base64Data = await getBase64FromUrl(url);
if (base64Data) {
// 이미지 하나를 성공할 때마다 네이티브로 즉시 전송
sendMessage({
type: "SINGLE_IMAGE_DATA",
imgSrc: url,
base64Data: base64Data
});
}
} catch (e) {
}
toast(`${idx + 1} / ${uniqueUrls.length} unique images to cache.`);
idx += 1;
}
gotoNext()
}
gotoNext()
}
// 스크롤 함수 정의
function smoothScrollDown() {
// 1. 전체 페이지의 높이를 가져옵니다.
const totalHeight = document.body.scrollHeight;
// 2. 한 번에 스크롤할 거리를 계산합니다 (전체 높이의 20분의 1).
const scrollIncrement = totalHeight / 25;
// 3. 1초(1000ms) 간격으로 스크롤을 반복 실행합니다.
scrollInterval = setInterval(() => {
// 현재 스크롤 위치 + 화면에 보이는 높이가 전체 페이지 높이보다 크거나 같으면
// 페이지의 끝에 도달한 것입니다.
if (Math.ceil(window.scrollY) + Math.ceil(window.innerHeight) >= (totalHeight * 0.9)) {
console.log("✅ 페이지 끝에 도달했습니다. 스크롤을 중지합니다.");
toast("✅ 페이지 끝에 도달했습니다. 스크롤을 중지합니다.")
clearInterval(scrollInterval); // 반복 실행을 멈춥니다.
getImg()
} else {
// 계산된 거리만큼 부드럽게 아래로 스크롤합니다.
window.scrollBy({
top: scrollIncrement,
left: 0,
behavior: 'smooth' // 부드럽게 스크롤하는 옵션
});
toast(`smooth scrollBy ${scrollIncrement}, ${window.scrollY}, ${window.innerHeight}, ${totalHeight}`)
}
}, 2000); // 1000밀리초 = 1초
}
// 스크롤 함수 실행
smoothScrollDown();
}
else if(location.href.search("javt")) {
console.log(`Found TEST`);