// ==UserScript==
// @name 輕小說文庫直書工具
// @namespace http://tampermonkey.net/
// @version 1.00
// @description 將顯示方式轉為直書,新增黑夜模式,兼容輕小說文庫+
// @author 0225
// @license GPL-license
// @match https://www.wenku8.net/*
// @grant none
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
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 = '
'
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 foottext = document.getElementById('foottext');
if (foottext) {
Object.assign(foottext.style, {
position: 'fixed',
right: '0',
bottom: '0',
zIndex: '2000',
display: 'block',
backgroundColor: 'rgba(255, 255, 255, 0.8)',
padding: '5px',
borderRadius: '5px',
});
}
const sidepanel = document.getElementById('sidepanel-panel');
if (sidepanel) {
foottext.style.display = 'none';
const angleDownButton = sidepanel.querySelector('.fa-solid.fa-angle-down');
const angleUpButton = sidepanel.querySelector('.fa-solid.fa-angle-up');
if (angleDownButton) {
angleDownButton.parentElement.remove();
}
if (angleUpButton) {
angleUpButton.parentElement.remove();
}
const moveRightButton = document.createElement('div');
moveRightButton.className = 'sidepanel-button';
moveRightButton.innerHTML = '';
moveRightButton.onclick = () => {
window.scrollTo(document.body.scrollWidth, 0);
};
const moveLeftButton = document.createElement('div');
moveLeftButton.className = 'sidepanel-button';
moveLeftButton.innerHTML = '';
moveLeftButton.onclick = () => {
window.scrollTo(0, 0);
};
sidepanel.appendChild(moveRightButton);
sidepanel.appendChild(moveLeftButton);
const nightModeButton = document.createElement('div');
nightModeButton.className = 'sidepanel-button';
nightModeButton.innerHTML = '';
let isNightMode = false;
nightModeButton.onclick = () => {
isNightMode = !isNightMode;
document.body.style.backgroundColor = isNightMode ? 'black' : 'white';
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';
}
checkOverlap(title, adtop);
};
sidepanel.appendChild(nightModeButton);
}
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';
}
}
};
if (title && adtop) {
checkOverlap(title, adtop);
}
window.scrollTo(document.body.scrollWidth, 0);
};
window.addEventListener('load', init);
})();