// ==UserScript==
// @name 增強漫畫櫃
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 漫畫櫃自動隐藏頂部元素、中鍵捲動頁面、圖片高寬調整、自動切換上下一章、更改cookie
// @license MIT
// @match *://www.manhuagui.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
//-----------------------------------------------------------------------------------------------------------
//禁用tbBox.live
(function($) {
'use strict';
function disableTbBoxLive() {
if ($('#tbBox').off) {
$('#tbBox').off();
}
if ($('#tbBox').die) {
$('#tbBox').die();
}
}
// 確保在 DOM 準備好後執行
$(document).ready(function() {
disableTbBoxLive();
});
// 監控 DOM 變化,持續禁用 #tbBox.live
const observer = new MutationObserver(() => {
if ($('#tbBox').length) {
disableTbBoxLive();
}
});
observer.observe(document.body, { childList: true, subtree: true });
})(window.jQuery);
(function() {
'use strict';
//-----------------------------------------------------------------------------------------------------------
//滑鼠中鍵捲動頁面(上下和左右)
let isMiddleButtonPressed = false;
let lastX = 0;
let lastY = 0;
// 監聽滑鼠中鍵按下事件
document.addEventListener('mousedown', function(e) {
if (e.button === 1) { // 判斷是否是中鍵(button 1)
isMiddleButtonPressed = true;
document.body.style.cursor = 'grab';
lastX = e.clientX; // 記錄初始的X座標
lastY = e.clientY; // 記錄初始的Y座標
e.preventDefault(); // 防止預設行為(如點擊選擇文本等)
}
});
// 監聽滑鼠中鍵釋放事件
document.addEventListener('mouseup', function(e) {
if (e.button === 1) { // 中鍵釋放
isMiddleButtonPressed = false;
document.body.style.cursor = 'default';
}
});
// 監聽滑鼠移動事件
document.addEventListener('mousemove', function(e) {
if (isMiddleButtonPressed) {
let deltaX = e.clientX - lastX; // 計算滑鼠水平移動的距離
let deltaY = e.clientY - lastY; // 計算滑鼠垂直移動的距離
window.scrollBy(-deltaX*2, -deltaY*4); // 依照滑鼠移動量來捲動頁面(上下和左右)
lastX = e.clientX; // 更新滑鼠的最後X座標
lastY = e.clientY; // 更新滑鼠的最後Y座標
}
});
//-----------------------------------------------------------------------------------------------------------
//隱藏元素
const url = window.location.href;
if (url.includes('html')) {
// 获取要隐藏的元素
var header = document.querySelector('.header'); // 修改为你要隐藏的元素的ID或选择器
var headerheight = '50px';
var headerinner = document.querySelector('.header-inner');
var title = document.querySelector('.title');
var w980tc = document.querySelector('.w980.tc');
var w980sub = document.querySelector('.w980.clearfix.sub-btn');
if (header) {
// 隐藏元素
header.style.position = 'absolute';
header.style.top = '0px';
header.style.left = '0px';
header.style.width = '100%';
header.style.height = headerheight;
header.style.backgroundColor = 'transparent';
header.style.borderBottom = '0px';
header.style.zIndex = '1';
headerinner.style.display = 'none';
title.style.display = 'none';
w980tc.style.display = 'none';
w980sub.style.display = 'none';
// header.style.height = '10px';
header.style.display = 'block';
header.style.marginBottom = '0px';
w980sub.style.margin = '0px auto';
// 为元素添加hover事件
header.addEventListener('mouseover', function() {
header.style.position = 'relative';
header.style.backgroundColor = '#1e8ad6';
header.style.borderBottom = '2px solid #114f7b';
headerinner.style.display = 'block';
title.style.display = 'block';
w980tc.style.display = 'block';
w980sub.style.display = 'block';
header.style.height = '34px';
});
header.addEventListener('mouseout', function() {
header.style.position = 'absolute';
header.style.backgroundColor = 'transparent';
header.style.borderBottom = '0px';
headerinner.style.display = 'none';
title.style.display = 'none';
w980tc.style.display = 'none';
w980sub.style.display = 'none';
header.style.height = headerheight;
});
title.addEventListener('mouseover', function() {
header.style.position = 'relative';
header.style.backgroundColor = '#1e8ad6';
header.style.borderBottom = '2px solid #114f7b';
headerinner.style.display = 'block';
title.style.display = 'block';
w980tc.style.display = 'block';
w980sub.style.display = 'block';
header.style.height = '34px';
});
title.addEventListener('mouseout', function() {
header.style.position = 'absolute';
header.style.backgroundColor = 'transparent';
header.style.borderBottom = '0px';
headerinner.style.display = 'none';
title.style.display = 'none';
w980tc.style.display = 'none';
w980sub.style.display = 'none';
header.style.height = headerheight;
});
w980tc.addEventListener('mouseover', function() {
header.style.position = 'relative';
header.style.backgroundColor = '#1e8ad6';
header.style.borderBottom = '2px solid #114f7b';
headerinner.style.display = 'block';
title.style.display = 'block';
w980tc.style.display = 'block';
w980sub.style.display = 'block';
header.style.height = '34px';
});
w980tc.addEventListener('mouseout', function() {
header.style.position = 'absolute';
header.style.backgroundColor = 'transparent';
header.style.borderBottom = '0px';
headerinner.style.display = 'none';
title.style.display = 'none';
w980tc.style.display = 'none';
w980sub.style.display = 'none';
header.style.height = headerheight;
});
w980sub.addEventListener('mouseover', function() {
header.style.position = 'relative';
header.style.backgroundColor = '#1e8ad6';
header.style.borderBottom = '2px solid #114f7b';
headerinner.style.display = 'block';
title.style.display = 'block';
w980tc.style.display = 'block';
w980sub.style.display = 'block';
header.style.height = '34px';
});
w980sub.addEventListener('mouseout', function() {
header.style.position = 'absolute';
header.style.backgroundColor = 'transparent';
header.style.borderBottom = '0px';
headerinner.style.display = 'none';
title.style.display = 'none';
w980tc.style.display = 'none';
w980sub.style.display = 'none';
header.style.height = headerheight;
});
}
//-----------------------------------------------------------------------------------------------------------
//改變css style
const style = document.createElement('style');
style.textContent = `
.notice-bar .notice{
width:initial;
float: initial;
}
.w998, .w728, .w980, .chapter, .chapter-list, .latest-list, .latest-list ul, .contList, .book-list ul, .cmt-cont, .cover-list, .tbCenter, #mangabox {
width:100%;
}
.w860 {
float:left;
}
.tbCenter {
border:0px;
background-color: transparent;
}
.footer-cont {
width:100%;
padding: 0;
}
.sub-btn {
width:980px;
}
`;
document.head.appendChild(style);
function resizeImage() {
const windowHeight = window.innerHeight;
const windowWidth = window.innerWidth;
const img = document.getElementById('mangaFile');
if (img && img.complete) {
const style = document.getElementById('mangaFile-resize-style') || document.createElement('style');
style.id = 'mangaFile-resize-style';
if (!document.head.contains(style)) {
document.head.appendChild(style);
}
const adjustedWidth = (windowHeight / img.naturalHeight) * img.naturalWidth;
if (img.naturalHeight > img.naturalWidth && windowHeight > 1.5*windowWidth) {
// 圖片高度大於圖片寬度,且圖片寬度超過視窗寬度,將圖片寬度設為視窗寬度
style.innerHTML = `#mangaFile { width: ${windowWidth}px; height: auto; }`;
} else if (img.naturalHeight > windowHeight) {
// 圖片高度大於視窗高度,將圖片高度設為視窗高度
style.innerHTML = `#mangaFile { height: ${windowHeight}px; width: auto; }`;
} else {
// 其他情況,auto
style.innerHTML = `#mangaFile { height: auto; width: auto; }`;
}
}
}
function observeImage() {
const img = document.getElementById('mangaFile');
if (img) {
img.addEventListener('load', resizeImage);
if (img.complete) {
resizeImage();
}
}
}
const observer = new MutationObserver(() => {
observeImage();
});
observer.observe(document.body, { childList: true, subtree: true });
window.addEventListener('load', observeImage);
//-----------------------------------------------------------------------------------------------------------
//Auto Scroll to Right on Large Images
function scrollToRightIfNeeded() {
const viewportWidth = window.innerWidth;
const images = document.querySelectorAll('img');
for (const img of images) {
if (img.complete && img.offsetWidth > viewportWidth) {
setTimeout(() => {
window.scrollTo({ left: document.documentElement.scrollWidth, behavior: 'auto' });
}, 50); // Reduced delay and faster scroll behavior
break; // Only scroll once for the first oversized image
}
}
}
// Run on page load
window.addEventListener('load', scrollToRightIfNeeded);
// Optional: observe new images added dynamically
const scrollobserver = new MutationObserver(scrollToRightIfNeeded);
scrollobserver.observe(document.body, { childList: true, subtree: true });
//-----------------------------------------------------------------------------------------------------------
//自動上下一章
const pbokobserver = new MutationObserver((mutations) => {
const okButton = document.querySelector('.pb-ok'); // Assuming this is the class for the confirm button
if (okButton) {
console.log('Confirm button found, triggering onOk function...');
okButton.click(); // Simulate the button click which should call onOk
// If you want to directly call the function without button click:
// if (typeof r === 'function') r(1); // Replace '1' if needed
pbokobserver.disconnect(); // Stop observing once the button is found and action taken
}
});
pbokobserver.observe(document.body, { childList: true, subtree: true });
//-----------------------------------------------------------------------------------------------------------
//修改cookie為CN
const targetCookieName = 'country';
const newValue = 'CN';
const domain = '.manhuagui.com'; // 注意:跨子域需要加前缀点,如 .example.com
const path = '/'; // 可选,Cookie作用路径
const days = 7; // Cookie有效期(天)
// 设置Cookie,支持domain
function setCookie(name, value, days, domain, path = '/') {
const expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=${path};domain=${domain};`;
console.log(`Cookie ${name} 已修改为 ${value}, domain: ${domain}`);
}
// 读取当前Cookie
function getCookie(name) {
const cookies = document.cookie.split(';');
for (let cookie of cookies) {
const [key, value] = cookie.trim().split('=');
if (key === name) return value;
}
return null;
}
// 检查并修改Cookie
const currentValue = getCookie(targetCookieName);
if (currentValue !== newValue) {
setCookie(targetCookieName, newValue, days, domain, path);
} else {
console.log(`Cookie ${targetCookieName} 已是最新值,无需修改`);
}
} else {
document.querySelectorAll('a[target]').forEach(link => {
link.setAttribute('target', '_self');
});
}})();