// ==UserScript==
// @name 輕小說文庫直書工具
// @namespace http://tampermonkey.net/
// @version 1.05
// @description 將顯示方式轉為直書,新增黑夜模式,兼容輕小說文庫+
// @author 0225
// @license GPL-license
// @match https://www.wenku8.net/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
GM_addStyle(`
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css');
`);
if (document.querySelector('.main.nav') || document.getElementById('info')) {
return;
}
const titleElement = document.getElementById('title');
if (titleElement && (titleElement.innerText.includes('插图') || titleElement.innerText.includes('插圖'))) {
return;
}
const init = () => {
const adv4 = document.getElementById('adv4');
adv4 && adv4.remove();
const adv5 = document.getElementById('adv5');
adv5 && adv5.remove();
const footlink = document.getElementById('footlink');
if (footlink) {
footlink.style.border = 'none';
footlink.style.padding = '10px';
}
const leftDiv = document.getElementById('linkleft');
leftDiv && leftDiv.remove();
const headlink = document.getElementById('headlink');
if (headlink) {
Object.assign(headlink.style, {
position: 'fixed',
left: '0',
bottom: '0',
zIndex: '2000',
display: 'block',
});
}
const rightDiv = document.getElementById('linkright');
if (rightDiv) {
Object.assign(rightDiv.style, {
position: 'absolute',
left: '0',
top: '0',
zIndex: '1000',
});
}
const adtop = document.getElementById('adtop');
if (adtop) {
Object.assign(adtop.style, {
position: 'fixed',
top: '0',
left: '50%',
transform: 'translateX(-50%)',
zIndex: '2000',
display: 'block',
});
}
const content = document.getElementById('content');
if (content) {
const emptyLines = document.createElement('div');
emptyLines.innerHTML = '<br><br><br><br>';
content.insertBefore(emptyLines, content.firstChild);
content.style.marginTop = '30px';
Object.assign(content.style, {
writingMode: 'vertical-rl',
textOrientation: 'upright',
overflowY: 'auto',
overflowX: 'hidden',
whiteSpace: 'normal',
width: 'auto',
maxHeight: '80vh',
lineHeight: '1.6',
transition: 'color 0.3s, background-color 0.3s',
});
}
const contentMain = document.getElementById('contentmain');
if (contentMain) {
Object.assign(contentMain.style, {
width: 'auto',
borderLeft: 'none',
borderRight: 'none',
boxShadow: 'none',
});
}
document.body.style.width = 'auto';
window.addEventListener('wheel', (event) => {
if (event.deltaY > 0) {
window.scrollBy(-50, 0);
event.preventDefault();
} else if (event.deltaY < 0) {
window.scrollBy(50, 0);
event.preventDefault();
}
});
const title = document.getElementById('title');
if (title) {
Object.assign(title.style, {
position: 'fixed',
right: '0',
top: '0',
writingMode: 'horizontal-tb',
textOrientation: 'upright',
zIndex: '1000',
whiteSpace: 'nowrap',
paddingRight: '10px',
});
}
let rightSpace = document.getElementById('rightspace');
if (!rightSpace) {
rightSpace = document.createElement('div');
rightSpace.id = 'rightspace';
Object.assign(rightSpace.style, {
position: 'fixed',
right: '0',
top: '0',
width: 'auto',
height: '100vh',
backgroundColor: 'transparent',
});
document.body.appendChild(rightSpace);
}
const sidepanel = document.getElementById('sidepanel-panel');
if (sidepanel) {
sidepanel.style.display = 'none';
}
const foottext = document.getElementById('foottext');
if (foottext) {
Object.assign(foottext.style, {
position: 'fixed',
right: '10px',
bottom: '30px',
zIndex: '2000',
display: 'flex',
justifyContent: 'space-between',
backgroundColor: 'rgba(255, 255, 255, 0.8)',
padding: '10px',
borderRadius: '5px',
boxShadow: '0 2px 5px rgba(0, 0, 0, 0.2)',
});
headlink.parentNode.insertBefore(foottext, headlink);
const footLinks = foottext.querySelectorAll('a');
const newButtonsHtml = `
<a id="bookmarkBtn" style="margin: 0 5px;" title="添加書籤"><i class="fas fa-bookmark"></i></a>
<a id="backToBookBtn" style="margin: 0 5px;" title="返回書頁"><i class="fas fa-book"></i></a>
<a id="nextPageBtn" style="margin: 0 5px;" title="下一章"><i class="fas fa-chevron-left"></i></a>
<a id="prevPageBtn" style="margin: 0 5px;" title="上一章"><i class="fas fa-chevron-right"></i></a>
<a id="backToContentsBtn" style="margin: 0 5px;" title="返回書目"><i class="fas fa-list"></i></a>
<a id="refreshBtn" style="margin: 0 5px;" title="刷新頁面"><i class="fas fa-sync"></i></a>
<a id="moveLeftBtn" style="margin: 0 5px;" title="移至最左"><i class="fas fa-backward"></i></a>
<a id="moveRightBtn" style="margin: 0 5px;" title="移至最右"><i class="fas fa-forward"></i></a>
<a id="nightModeBtn" style="margin: 0 5px;" title="黑暗模式"><i class="fas fa-moon"></i></a>
`;
foottext.innerHTML = newButtonsHtml;
document.getElementById('bookmarkBtn').onclick = () => {
const bookmarkUrl = window.location.href;
const bookmarkTitle = document.title;
alert(`書籤已添加:${bookmarkTitle}`);
};
document.getElementById('backToBookBtn').onclick = () => {
const bookUrl = footLinks[1].href;
window.location.href = bookUrl;
};
document.getElementById('nextPageBtn').onclick = () => {
const nextPageUrl = footLinks[3].href;
window.location.href = nextPageUrl;
};
document.getElementById('prevPageBtn').onclick = () => {
const prevPageUrl = footLinks[2].href;
window.location.href = prevPageUrl;
};
document.getElementById('backToContentsBtn').onclick = () => {
const contentsUrl = footLinks[4].href;
window.location.href = contentsUrl;
};
document.getElementById('refreshBtn').onclick = () => {
window.location.reload();
};
document.getElementById('moveLeftBtn').onclick = () => {
window.scrollTo(0, 0);
};
document.getElementById('moveRightBtn').onclick = () => {
window.scrollTo(document.body.scrollWidth, 0);
};
const nightModeBtn = document.getElementById('nightModeBtn');
let isNightMode = false;
nightModeBtn.onclick = () => {
isNightMode = !isNightMode;
document.body.style.backgroundColor = isNightMode ? 'black' : 'white';
const color = isNightMode ? 'white' : 'black';
const adtop = document.getElementById('adtop');
if (adtop) {
adtop.style.color = isNightMode ? 'white' : 'black';
}
if (title) {
title.style.color = isNightMode ? 'white' : 'black';
}
const content = document.getElementById('content');
if (content) {
content.style.color = isNightMode ? 'white' : 'black';
}
};
}
if (title && adtop) {
checkOverlap(title, adtop);
}
window.scrollTo(document.body.scrollWidth, 0);
};
const checkOverlap = (titleElement, adtopElement) => {
if (titleElement && adtopElement) {
const adtopRect = adtopElement.getBoundingClientRect();
const titleRect = titleElement.getBoundingClientRect();
if (
titleRect.bottom > adtopRect.top &&
titleRect.top < adtopRect.bottom &&
titleRect.right > adtopRect.left &&
titleRect.left < adtopRect.right
) {
titleElement.style.display = 'none';
} else {
titleElement.style.display = 'block';
}
}
};
window.addEventListener('load', init);
})();