This commit is contained in:
2025-07-16 18:21:04 +09:00
parent 405b8c8fed
commit a00b2764b0
145 changed files with 6641 additions and 3219 deletions
@@ -0,0 +1,40 @@
browser.webRequest.onHeadersReceived.addListener(
function(details) {
let headers = details.responseHeaders || [];
// Cache-Control 헤더가 없거나 no-store, no-cache 등일 때 수정
let found = false;
for (let header of headers) {
if (header.name.toLowerCase() === "cache-control") {
header.value = "public, max-age=31536000"; // 1년 캐시
found = true;
}
}
if (!found) {
headers.push({name: "Cache-Control", value: "public, max-age=31536000"});
}
return {responseHeaders: headers};
},
{urls: ["*://*/*.gif"], types: ["image"]},
["blocking", "responseHeaders"]
);
//const originalLog = console.log;
//console.log = function(...args) {
// // 메시지 가공 또는 네이티브로 전달
// originalLog.apply(console, args);
// browser.runtime.sendNativeMessage("browser", args);
//};
browser.webRequest.onBeforeRequest.addListener(
function(details) {
return { cancel: true };
},
{ urls: ["*://*/*.gif"], types: ["image"] },
["blocking"]
);
//window.addEventListener('error', function(event) {
// if (event.message && event.message.includes('No impl for message: MozAfterPaint')) {
// // 앱으로 오류 신호 전달
// browser.runtime.sendMessage({ type: 'RELOAD_REQUEST' });
// }
//});
@@ -0,0 +1,86 @@
function getList() {
const contentsType = location.hostname.search('newtoki') > -1 ? 'newtoki' : location.hostname.search('booktoki') > -1 ? 'booktoki' : 'manatoki';
const contentsArray = [];
var children = document.getElementsByClassName('list-body')[0].children;
var maxCount = children.length;
for (i= 0; i < maxCount; i++) {
var chapterNum = children[i].getElementsByClassName('wr-num')[0].textContent;
var pageUrl = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].href;
if (pageUrl != null && pageUrl.length > 0 && pageUrl.startsWith('http')) {
pageUrl = new URL(pageUrl).pathname;
if (pageUrl && pageUrl.startsWith('http')) {
var urlObj = new URL(pageUrl);
var paths = urlObj.pathname.split('/').filter(Boolean);
if (paths.length > 0) {
var last = paths[paths.length - 1];
if (!/^\\d+$/.test(last)) {
paths.pop();
}
}
pageUrl = '/' + paths.join('/');
}
console.log(pageUrl);
} else {
console.log("pageUrl.startsWith('http') == false" + pageUrl);
}
var chapterTitle = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].innerText;
if(chapterTitle.split('\\n').length > 1) {
chapterTitle = chapterTitle.split('\\n')[1];
}
var bookPageUrl = location.pathname;
var bookTitle = document.getElementsByClassName('view-title')[0].getElementsByTagName('span')[0].innerText;
var data = {
'contentsType': contentsType,
'chapterID': Number(chapterNum),
'chapterNum': Number(chapterNum),
'pathUrl': pageUrl,
'bookPageUrl': bookPageUrl,
'chapterTitle': chapterTitle,
'bookTitle': bookTitle,
};
contentsArray.push(
data
);
}
if(contentsArray.length > 0) {
window.webkit.messageHandlers.ContentsRcv.postMessage(JSON.stringify({
'contentsType': contentsType,
'bookTitle': bookTitle,
'bookPageUrl': new URL(location.href).pathname,
'pages': contentsArray ,
}));
}
}
getList();
function check2() {
var children = document.getElementsByClassName('list-body')[0].children;
var maxCount = children.length;
for (i= 0; i < maxCount; i++) {
var pageUrl = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].href;
if (pageUrl != null && pageUrl.length > 0 && pageUrl.startsWith('http')) {
if (pageUrl) {
var paths = pageUrl.split('/')
if (paths.length > 0) {
var last = paths[paths.length - 1];
if (last && Array.from(last).every(ch => ch >= '0' && ch <= '9')) {
console.log("only nums " + last)
} else {
console.log("not only nums " + last)
paths.pop();
}
}
pageUrl = paths.join('/');
pageUrl = new URL(pageUrl).pathname;
}
console.log(pageUrl);
} else {
}
}
}
check2();
@@ -0,0 +1,28 @@
{
"browser_specific_settings": {
"gecko": {
"id": "messaging@booktoki468.com"
}
},
"manifest_version": 2,
"version": "1.0",
"name": "Sample Extension",
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["messaging.js"]
}
],
"permissions": [
"nativeMessaging",
"nativeMessagingFromContent",
"geckoViewAddons",
"webRequest",
"webRequestBlocking",
"*://*/*.gif"
]
}
@@ -0,0 +1,177 @@
const port = browser.runtime.connectNative("browser");
port.onMessage.addListener(response => {
var type= response["type"];
switch (type) {
case "getList": {
try {
// var listBody = null
// try {listBody = document.querySelector(".list-body");}catch (e) {}
// var title = null
// var contents = null
// try {title = toonTitle(document.querySelector(".page-desc")); }catch (e) {}
// try {contents = toonContents(document.querySelector("#novel_content"))}catch (e) {}
// console.log("listBody", listBody);
// console.log("title", title);
if(listBody) {
// getList(listBody.children)
} else if(title && contents) {
// if (toonTitle !== undefined && toonContents !== undefined && toonTitle !== "" && toonContents !=="") {
// sendMessage(
// {
// type: "BookContents",
// book : {
// chapterTitle : title,
// bookContents : contents
// }
// }
// );
// }
} else {
loadComplete()
}
} catch (e) {
loadComplete()
console.error(e);
}
}break;
case "scrollDown":{
var max = response["max"]
var current = response["current"]
var isUpDown = response["isUpDown"]
if (max > 0 && current > 0) { scrollByPercent(Number(current),Number(max)); }
else scrollByPercentUpDown(Number(isUpDown),100);
}
break;
case "onLoaded":{
}
break;
default:
port.postMessage(`Received: ${JSON.stringify(response)}`);
break
}
});
if(document.querySelector(".list-body")) {
var listBody = null
try {listBody = document.querySelector(".list-body");}catch (e) {}
getList(listBody.children)
} else if(document.querySelector("#novel_content")){
var title = null
var contents = null
try {title = toonTitle(document.querySelector(".page-desc")); }catch (e) {}
try {contents = toonContents(document.querySelector("#novel_content"))}catch (e) {}
if (toonTitle !== undefined && toonContents !== undefined && toonTitle !== "" && toonContents !=="") {
sendMessage(
{
type: "BookContents",
book : {
chapterTitle : title,
bookContents : contents
}
}
);
}
} else if(document.querySelector("#html_encoder_div")) {
sendMessage(
{
type: "WebtoonContents",
}
);
} else {
sendMessage({type:"MSG",msg:"connected has Nothings"});
loadComplete()
}
function getList(children) {
// port.postMessage("Start of getList!" + children);
const contentsArray = [];
var maxCount = children.length;
for (i= 0; i < maxCount; i++) {
var chapterNum = children[i].getElementsByClassName('wr-num')[0].textContent;
var pageUrl = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].href;
if (pageUrl != null && pageUrl.length > 0 && pageUrl.startsWith("http")) {
pageUrl = new URL(pageUrl).pathname;
}
var chapterTitle = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].innerText;
if(chapterTitle.split('\n').length > 1) {
chapterTitle = chapterTitle.split('\n')[1];
}
var bookPageUrl = location.pathname;
var bookTitle = document.getElementsByClassName('view-title')[0].getElementsByTagName('span')[0].innerText;
var data = {
'chapterID': Number(chapterNum),
'chapterNum': Number(chapterNum),
'pathUrl': pageUrl,
'bookPageUrl': bookPageUrl,
'chapterTitle': chapterTitle,
'bookTitle': bookTitle,
};
contentsArray.push(
data
);
}
if(contentsArray.length > 0) {
sendMessage(
{
type: "getListResult",
bookInfos: {
bookTitle: bookTitle,
bookPageUrl: new URL(location.href).pathname,
pages: contentsArray ,
}
}
);
}
}
function toonTitle(toon_title) {
return toon_title != null ? toon_title.innerText : null
}
function toonContents(novel_content) {
return novel_content != null ? novel_content.innerText : null
}
function scrollByPercent(current , max) {
const pageHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
);
const currentScroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
const moveAmount = pageHeight / max;
window.scrollTo({ top: moveAmount * current, behavior: "smooth" });
}
function scrollByPercentUpDown(isToDown , max) {
const pageHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
);
const currentScroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
const moveAmount = Math.max(pageHeight / max,100);
window.scrollTo({ top: currentScroll + (moveAmount * isToDown) , behavior: "smooth" });
}
function loadComplete() {
// try {port.postMessage(JSON.stringify({type: "NotRegistered"}));}catch (e) {}
}
function sendMessage(msg) {
port.postMessage(JSON.stringify(msg));
}
function dssd() {
}