九色-优化

91porny(九色)视频宽屏

// ==UserScript==
// @name         九色-优化
// @version      1.0.2
// @namespace    https://sleazyfork.org/zh-CN/users/1461640-%E6%98%9F%E5%AE%BF%E8%80%81%E9%AD%94
// @author       星宿老魔
// @description  91porny(九色)视频宽屏
// @match        https://91porny.com/*
// @match        https://*.jiuse.vip/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=91porny.com
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function(){"use strict";const e=class _StyleInjector{static init(){console.log("[StyleInjector] 初始化样式注入...")
;this.addStyles()}static addStyles(){const e=document.createElement("style");e.textContent=this.cssRules
;document.head.appendChild(e);console.log("[StyleInjector] 样式注入完成")}}
;e.cssRules=`\n    .videoPlayContainer {\n      width: 100% !important;\n      max-width: 100% !important;\n      margin: 0 auto !important;\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    .video-js {\n      width: 100% !important;\n      max-width: 100% !important;\n    }\n    .row .col-100 {\n      width: 100% !important;\n      max-width: 100% !important;\n      flex-basis: 100% !important;\n      margin: 0 !important;\n      padding: 0 10px !important;\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    .row {\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    .row .side.col-40.col-md-50 {\n      display: none;\n    }\n    .videoPlayContainer .scale {\n      padding-bottom: 0 !important;\n      height: auto !important;\n      min-height: 0 !important;\n      aspect-ratio: unset !important;\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    .videoPlayContainer .video-js {\n      position: relative !important;\n      top: 0 !important;\n      left: 0 !important;\n    }\n    .videoPlayContainer,\n    .videoPlayContainer > *,\n    .col-100 {\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    body .container .row:first-child {\n      margin-top: 0 !important;\n      padding-top: 0 !important;\n    }\n    \n    .rec-tabs-container {\n        display: flex;\n        gap: 10px;\n        margin-bottom: 10px;\n    }\n    .rec-tab-button {\n        background-color: #333;\n        color: #fff;\n        border: 1px solid #555;\n        padding: 8px 15px;\n        cursor: pointer;\n        border-radius: 5px;\n        font-size: 16px;\n        font-weight: bold;\n    }\n    .rec-tab-button.active {\n        background-color: #f0ad4e;\n        color: #000;\n        border-color: #f0ad4e;\n    }\n    .rec-tab-button:not(.active):hover {\n        background-color: #444;\n    }\n    #recommended-videos-container, #author-videos-container {\n        flex-wrap: wrap;\n    }\n    .d9867a703dd9335a77b9f88459aa7bff {\n      display: none !important;\n    }\n    \n    /* 广告拦截CSS - 仅针对特定广告容器 */\n    .aa9965ce0d851e635fa7ec1dbf56d965,\n    #po-s6 {\n      display: none !important;\n      visibility: hidden !important;\n    }\n  `
;let t=e;const CONFIG={debounceDelay:250,selectors:{videoContainer:".videoPlayContainer",videoElement:".video-js",
videoColumn:".left.col-60.offset-md-10.col-md-40, .left.col-md-40.offset-md-10.col-60"}};class WideScreen{static init(){
console.log("[WideScreen] 初始化宽屏显示...");this.setWideScreenMode();this.setupResizeListener()}static setWideScreenMode(){
const e=document.querySelector(CONFIG.selectors.videoContainer)
;const t=document.querySelector(CONFIG.selectors.videoElement);if(!e&&!t){
console.log(`[WideScreen] ${window.location.hostname}宽屏模式: 未找到视频元素`);return}this.applyVideoColumnClasses()
;this.calculateVideoHeight(e,t);console.log(`[WideScreen] ${window.location.hostname}宽屏模式: 已启用宽屏模式`)}
static applyVideoColumnClasses(){const e=document.querySelector(CONFIG.selectors.videoColumn);if(e){
e.classList.remove("col-60","offset-md-10","col-md-40");e.classList.add("col-100")}}static calculateVideoHeight(e,t){
if(t){const n=16/9;const o=e?e.offsetWidth:window.innerWidth;const i=o/n;t.style.height=`${i}px`}}
static setupResizeListener(){window.addEventListener("resize",()=>{
const e=document.querySelector(CONFIG.selectors.videoContainer)
;const t=document.querySelector(CONFIG.selectors.videoElement);this.calculateVideoHeight(e,t)})}}
class VideoRecommendation{static init(){console.log("[VideoRecommendation] 初始化视频推荐...")
;this.modifyVideoRecommendations()}static modifyVideoRecommendations(){
if(document.getElementById("rec-tabs-container"))return
;const e=Array.from(document.querySelectorAll("h5.container-title")).find(e=>"视频推荐"===e.textContent?.trim())
;if(!e)return;const t=e.parentElement;const n=t.nextElementSibling;if(!n||!n.classList.contains("row"))return
;n.id="recommended-videos-container";n.style.display="flex";const o=this.createAuthorInfoContainer()
;n.parentNode?.insertBefore(o,n);const i=this.createAuthorVideosContainer();o.parentNode?.insertBefore(i,o.nextSibling)
;const{recommendedBtn:s,authorBtn:c,buttonContainer:d}=this.createTabButtons();t.innerHTML="";t.appendChild(d)
;this.setupTabEvents(s,c,n,i,o)}static createAuthorInfoContainer(){const e=document.createElement("div")
;e.id="author-info-container";e.style.display="none";return e}static createAuthorVideosContainer(){
const e=document.createElement("div");e.id="author-videos-container";e.className="row";e.style.display="none";return e}
static createTabButtons(){const e=document.createElement("button");e.textContent="视频推荐"
;e.className="rec-tab-button active";const t=document.createElement("button");t.textContent="作者视频"
;t.className="rec-tab-button";const n=document.createElement("div");n.id="rec-tabs-container"
;n.className="rec-tabs-container";n.appendChild(e);n.appendChild(t);return{recommendedBtn:e,authorBtn:t,
buttonContainer:n}}static setupTabEvents(e,t,n,o,i){e.addEventListener("click",()=>{e.classList.add("active")
;t.classList.remove("active");n.style.display="flex";o.style.display="none";i.style.display="none"})
;t.addEventListener("click",()=>{t.classList.add("active");e.classList.remove("active");n.style.display="none"
;o.style.display="flex";i.style.display="block";if(0===o.children.length){
const e=document.querySelector('.d-flex.justify-content-between a[href*="/author/"]')
;if(e)this.fetchAuthorInfoAndVideos(e.href,o,i);else o.innerHTML='<p style="color: white; padding: 20px;">未找到当前视频的作者信息。</p>'
}})}static fetchAuthorInfoAndVideos(e,t,n){t.innerHTML='<p style="color: white; padding: 20px;">正在加载作者视频...</p>'
;n.innerHTML="";fetch(e).then(e=>e.text()).then(o=>{const i=new DOMParser;const s=i.parseFromString(o,"text/html")
;const c=Array.from(s.querySelectorAll("p, h1, h2, h3, h4, h5")).find(e=>e.textContent?.includes("共计")&&e.textContent?.includes("视频"))
;if(c){const t=document.createElement("a");t.href=e;t.target="_blank";let o=c.textContent?.trim()||""
;let i=o.split(",")[0];if(i===o)i=o.split(",")[0];t.textContent=i;t.title="点击跳转作者主页";t.style.color="#f0ad4e"
;t.style.display="block";t.style.marginBottom="10px";n.appendChild(t)}const d=s.querySelectorAll(".colVideoList")
;t.innerHTML="";if(d.length>0)d.forEach(e=>{t.appendChild(e)
});else t.innerHTML='<p style="color: white; padding: 20px;">该作者没有其他视频。</p>'}).catch(e=>{console.error("获取作者视频失败:",e)
;t.innerHTML='<p style="color: white; padding: 20px;">加载作者视频失败。</p>'})}}const n=class _AdBlocker{static init(){
console.log("[AdBlocker] 初始化广告拦截...");if(!this.isInitialized){this.setupAdWatcher();this.isInitialized=true}
this.removeAuthorComments()}static removeAuthorComments(){
const e=document.querySelector(".aa9965ce0d851e635fa7ec1dbf56d965");if(e){e.remove()
;console.log("[AdBlocker] 已移除作者留言广告区域")}const t=document.getElementById("po-s6");if(t){t.remove()
;console.log("[AdBlocker] 已移除作者留言广告区域 (通过ID)")}
const n=document.querySelectorAll('div[class*="aa9965ce0d851e635fa7ec1dbf56d965"]');n.forEach(e=>{e.remove()
;console.log("[AdBlocker] 已移除广告元素")})}static setupAdWatcher(){const startObserver=()=>{if(!document.body){
if("loading"===document.readyState)document.addEventListener("DOMContentLoaded",startObserver);else setTimeout(startObserver,100)
;return}const observer=new MutationObserver(e=>{e.forEach(e=>{if(e.addedNodes.length>0)e.addedNodes.forEach(e=>{
if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(this.isAdElement(t)){t.remove();console.log("[AdBlocker] 已移除动态加载的广告")}
const n=t.querySelectorAll(".aa9965ce0d851e635fa7ec1dbf56d965, #po-s6");n.forEach(e=>{e.remove()
;console.log("[AdBlocker] 已移除子元素中的广告")})}})})});observer.observe(document.body,{childList:true,subtree:true})
;console.log("[AdBlocker] 广告监听器已启动")};startObserver()}static isAdElement(e){const t=e.className||"";const n=e.id||""
;return t.includes("aa9965ce0d851e635fa7ec1dbf56d965")||"po-s6"===n}static checkAndRemoveAds(){
this.removeAuthorComments()}};n.isInitialized=false;let o=n;function debounce(e,t){let n
;return function executedFunction(...o){const later=()=>{clearTimeout(n);e(...o)};clearTimeout(n)
;n=window.setTimeout(later,t)}}const i=class _DOMObserver{static init(){console.log("[DOMObserver] 初始化DOM监听...")
;this.setupDocumentListeners();this.setupMutationObserver()}static setupDocumentListeners(){const e=500
;const runUpdates=()=>{WideScreen.setWideScreenMode();VideoRecommendation.modifyVideoRecommendations()
;o.checkAndRemoveAds()}
;if("loading"===document.readyState)document.addEventListener("DOMContentLoaded",()=>setTimeout(runUpdates,e));else setTimeout(runUpdates,e)
;document.addEventListener("load",e=>{const t=e.target
;if("VIDEO"===t.tagName||"IFRAME"===t.tagName)WideScreen.setWideScreenMode()},true)
;window.addEventListener("load",runUpdates)}static setupMutationObserver(){const runUpdates=()=>{
WideScreen.setWideScreenMode();VideoRecommendation.modifyVideoRecommendations();o.checkAndRemoveAds()}
;const e=debounce(runUpdates,CONFIG.debounceDelay);this.observer=new MutationObserver(t=>{let n=false;t.forEach(e=>{
if(e.addedNodes.length>0)e.addedNodes.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e
;if(t.matches&&(t.matches(".videoPlayContainer")||t.matches(".video-js")||t.matches('[class*="recommend"]')||t.matches('[class*="video"]')||"VIDEO"===t.tagName||"IFRAME"===t.tagName))n=true
}})});if(n)e()});if(document.body){this.observer.observe(document.body,{childList:true,subtree:true})
;console.log("[DOMObserver] DOM监听器已启动")}else{const startWhenReady=()=>{if(document.body){
this.observer?.observe(document.body,{childList:true,subtree:true});console.log("[DOMObserver] DOM监听器已启动(延迟)")
}else setTimeout(startWhenReady,100)}
;if("loading"===document.readyState)document.addEventListener("DOMContentLoaded",startWhenReady);else startWhenReady()}}
static destroy(){if(this.observer){this.observer.disconnect();this.observer=null}}};i.observer=null;let s=i
;console.log("[九色-优化] 开始加载");t.init();function init(){o.init();WideScreen.init();VideoRecommendation.init();s.init()
;console.log(`[九色-优化] ${window.location.hostname}宽屏模式: 已启用`);console.log("[九色-优化] 所有模块加载完成")}init()})();