This commit is contained in:
2026-03-23 18:03:45 +09:00
parent 9aee32e42d
commit 112012ce0c
8 changed files with 383 additions and 104 deletions
@@ -55,22 +55,203 @@ port.onMessage.addListener(response => {
var type= response["type"];
switch (type) {
case "CLICK_PREV_CHAPTER" : {
const links = document.querySelectorAll("a");
let found = false;
for (let link of links) {
if (link.textContent.includes("이전화 보기")) {
link.click();
found = true;
break;
}
}
if (!found) {
port.postMessage({ type: "MSG", msg: "이전화 버튼을 찾을 수 없습니다." });
}
break;
case "SEEK_NEXT": // 5초 앞으로
{
let btn =
document.querySelector('button[aria-label="10초 빨리 감기"]') ||
document.querySelector('button[aria-label="뒤로 10초"]') ||
document.querySelector('.ytp-right-controls .ytp-button[aria-label*="뒤로"]');
if (btn) {
btn.click();
return;
}
case "CLICK_NEXT_CHAPTER" : {
}
break;
case "PLAY_PAUSE": // 5초 뒤로
{
if (document.location.href.search("youtube") > -1) {
let btn =
document.querySelector('button[aria-label="동영상 재생"]') ||
document.querySelector('button[aria-label="동영상 일시중지"]') ;
if (btn) {
btn.click();
return;
}
}
} break;
case "SEEK_PREV": // 5초 뒤로
{
if (document.location.href.search("youtube") > -1) {
let btn =
document.querySelector('button[aria-label="10초 되감기"]') ||
document.querySelector('button[aria-label="앞으로 10초"]') ||
document.querySelector('.ytp-right-controls .ytp-button[aria-label*="앞으로"]');
if (btn) {
btn.click();
return;
}
}
} break;
case "PREV_SHORTS": {
if (document.location.href.search("shorts") > -1) {
// 1. 유튜브 쇼츠의 스크롤 컨테이너들 후보 (버전에 따라 다름)
const container = document.getElementById('shorts-container') ||
document.querySelector('ytd-shorts') ||
document.querySelector('#items.ytd-vertical-list-renderer');
if (container) {
// 컨테이너 내부에서 현재 뷰포트 높이만큼 스크롤
container.scrollBy({
top: window.innerHeight * -1,
behavior: 'smooth'
});
} else {
// 컨테이너를 못 찾을 경우, 키보드 'J'나 'ArrowDown'을 시뮬레이션하는 게 가장 정확합니다.
const event = new KeyboardEvent('keydown', {
key: 'ArrowUp',
keyCode: 40,
code: 'ArrowUp',
which: 40,
bubbles: true
});
document.dispatchEvent(event);
}
}else {
let btn = document.querySelector('.ytp-prev-button');
if (!btn) {
btn = document.querySelector('button[aria-label="이전 동영상"], button[aria-label="이전"]');
}
if (!btn) {
btn = Array.from(document.querySelectorAll('[aria-label]'))
.find(el => /이전/.test(el.getAttribute('aria-label')));
}
if (btn) {
btn.click();
} else {
console.log('이전 영상 버튼을 찾지 못했습니다.');
}
}
break;
}
case "NEXT_SHORTS": {
if (document.location.href.search("shorts") > -1) {
// 1. 유튜브 쇼츠의 스크롤 컨테이너들 후보 (버전에 따라 다름)
const container = document.getElementById('shorts-container') ||
document.querySelector('ytd-shorts') ||
document.querySelector('#items.ytd-vertical-list-renderer');
if (container) {
// 컨테이너 내부에서 현재 뷰포트 높이만큼 스크롤
container.scrollBy({
top: window.innerHeight,
behavior: 'smooth'
});
} else {
// 컨테이너를 못 찾을 경우, 키보드 'J'나 'ArrowDown'을 시뮬레이션하는 게 가장 정확합니다.
const event = new KeyboardEvent('keydown', {
key: 'ArrowDown',
keyCode: 40,
code: 'ArrowDown',
which: 40,
bubbles: true
});
document.dispatchEvent(event);
}
} else {
// 1) 예전/기본 플레이어용 클래스
let btn = document.querySelector('.ytp-next-button');
// 2) aria-label 기반 (언어별로 텍스트 다를 수 있음)
if (!btn) {
btn = document.querySelector('button[aria-label="다음 동영상"], button[aria-label="다음"]');
}
// 3) 혹시 아이콘 버튼이 다른 태그일 수도 있으니 좀 더 느슨하게
if (!btn) {
btn = Array.from(document.querySelectorAll('[aria-label]'))
.find(el => /다음/.test(el.getAttribute('aria-label')));
}
if (btn) {
btn.click();
} else {
console.log('다음 영상 버튼을 찾지 못했습니다.');
}
}
break;
}
case "CLICK_PREV_CHAPTER" : {
const links = document.querySelectorAll("a");
let found = false;
for (let link of links) {
if (link.textContent.includes("이전화 보기")) {
link.click();
found = true;
break;
}
}
if (!found) {
port.postMessage({ type: "MSG", msg: "이전화 버튼을 찾을 수 없습니다." });
}
break;
}
case "MARKER": {
const isDown = response["isDown"];
const scrollRatio = 0.6; // 이동 비율 (30%)
const viewportHeight = window.innerHeight;
const distance = viewportHeight * scrollRatio;
const startY = window.scrollY;
const id = 'scroll-ghost-layer';
let ghost = document.getElementById(id);
if (ghost) ghost.remove();
ghost = document.createElement('div');
ghost.id = id;
// 💡 isDown에 따라 그라데이션 방향과 보더 위치를 반전
const gradDir = isDown ? 'to top' : 'to bottom';
const borderStyle = isDown ? 'border-top: 3px solid rgba(0,122,255,0.4);' : 'border-bottom: 3px solid rgba(0,122,255,0.3);';
ghost.style.cssText = `
position: absolute;
top: ${startY}px;
left: 0;
width: 100%;
height: ${viewportHeight}px;
background: linear-gradient(${gradDir}, rgba(0,122,255,0.5), transparent);
${borderStyle}
z-index: 2147483647;
pointer-events: none;
transition: opacity 0.8s ease-out;
opacity: 1;
`;
document.body.appendChild(ghost);
// 실제 스크롤 수행
const targetY = isDown ? startY + distance : startY - distance;
window.scrollTo({
top: targetY,
behavior: 'smooth'
});
// 레이어 제거
setTimeout(() => {
ghost.style.opacity = '0';
setTimeout(() => ghost.remove(), 800);
}, 1000);
break;
}
case "CLICK_NEXT_CHAPTER" : {
const links = document.querySelectorAll("a");
let found = false;
for (let link of links) {
@@ -83,17 +264,17 @@ port.onMessage.addListener(response => {
if (!found) {
port.postMessage({ type: "MSG", msg: "다음화 버튼을 찾을 수 없습니다." });
}
break;
break;
}
case "fetchAllImages": {
const targetSrc = response["targetSrc"];
const imageUrls = findAllRelatedImages(targetSrc);
// 찾은 이미지 URL 목록을 'allImagesFound' 타입으로 네이티브 앱에 다시 전송
sendMessage({
type: "allImagesFound",
urls: imageUrls
});
break;
const targetSrc = response["targetSrc"];
const imageUrls = findAllRelatedImages(targetSrc);
// 찾은 이미지 URL 목록을 'allImagesFound' 타입으로 네이티브 앱에 다시 전송
sendMessage({
type: "allImagesFound",
urls: imageUrls
});
break;
}
case "search" : {
var keyword = response["keyword"];
@@ -131,7 +312,7 @@ port.onMessage.addListener(response => {
const elements = document.querySelectorAll(".main-content"); // 또는 getElementsByClassName("item")
const matched = Array.from(elements).filter(el =>
el.textContent.includes(keyword) // 대소문자 구분
el.textContent.includes(keyword) // 대소문자 구분
);
@@ -284,15 +465,15 @@ if(document.querySelector("#html_encoder_div")) {
);
}
function removeSpecificGifs() {
const images = document.getElementsByTagName('img');
for (let i = images.length - 1; i >= 0; i--) {
const src = images[i].src;
// 요청하신 특정 도메인과 gif 패턴, 쿼리 파라미터를 체크
if (src.includes('tokinbtoki') && src.includes('.gif') && src.includes('_=')) {
images[i].parentNode.removeChild(images[i]);
}
}
}
const images = document.getElementsByTagName('img');
for (let i = images.length - 1; i >= 0; i--) {
const src = images[i].src;
// 요청하신 특정 도메인과 gif 패턴, 쿼리 파라미터를 체크
if (src.includes('tokinbtoki') && src.includes('.gif') && src.includes('_=')) {
images[i].parentNode.removeChild(images[i]);
}
}
}
function getList(children) {
// port.postMessage("Start of getList!" + children);
@@ -395,7 +576,7 @@ function scrollByPercentUpDown(isToDown , max) {
window.scrollTo({ top: currentScroll + (moveAmount * isToDown) , behavior: "smooth" });
}
function loadComplete() {
try {port.postMessage(JSON.stringify({type: "NotRegistered"}));}catch (e) {}
try {port.postMessage(JSON.stringify({type: "NotRegistered"}));}catch (e) {}
}
function hideBook() {
@@ -492,7 +673,7 @@ function scrollToLazyImg(fastMode) {
// 한 번에 이동할 픽셀
const step = fastMode ? 600 : 200;
// 반복 간격(ms) (느릴수록 로딩에 더 여유 생김)
const delay = fastMode ? 200 : 600;
const delay = fastMode ? 300 : 500;
// 스크롤 현재 위치 추적
let currentY = window.scrollY;
let maxY = Math.max(
@@ -521,7 +702,7 @@ function scrollToLazyImg(fastMode) {
// 직접 메시지 보내거나, 원하는 최종 동작 실행
// 예: window.postMessage('saveToObsidian', '*');
}
}, 800);
}, delay);
}
}
@@ -555,7 +736,7 @@ function gotoNext() {
var targetElement = null;
document.querySelectorAll('.btn-group')?.forEach((el) => {
var pageLinks =el?.querySelectorAll('a');
var pageLinks =el?.querySelectorAll('a');
if (pageLinks) {
pageLinks.forEach(function(link) {