好色TV-优化

好色TV-hsex.tv自动宽屏

// ==UserScript==
// @name         好色TV-优化
// @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  好色TV-hsex.tv自动宽屏
// @match        https://hsex.tv/video-*
// @match        https://hsex.men/video-*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hsex.tv
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function(){"use strict";const CONFIG={wideScreenMode:!0,selectors:{videoContainer:".videos_box",videoElement:".video-js",mainContainer:".container",
videoCol:".col-md-8",sideCol:".col-md-4",controlBar:".vjs-control-bar",panelDefault:".panel-default"}};class WideScreen{static init(){
this.setWideScreenMode(),this.setupResizeListener()}static setWideScreenMode(){
const t=document.querySelector(CONFIG.selectors.videoContainer),e=document.querySelector(CONFIG.selectors.videoElement);if(!t&&!e)return
;this.applyMainContainerStyles(),this.applyVideoColStyles(),this.applySideColStyles(),this.applyPanelStyles(),
t&&(t.classList.contains("hsx-initialized")||t.classList.add("hsx-hidden-until-ready"),t.style.width="100%",t.style.maxWidth="100%",
t.style.margin="0 auto",t.style.position="relative"),e&&(e.style.height="",e.style.width="100%",e.style.maxWidth="100%",
e.classList.contains("vjs-fluid")||e.classList.add("vjs-fluid"));const n=document.querySelector(CONFIG.selectors.videoContainer)
;n&&(n.classList.remove("hsx-hidden-until-ready"),n.classList.add("hsx-initialized"))}static applyMainContainerStyles(){
const t=document.querySelector(CONFIG.selectors.mainContainer);t&&(t.style.width="100%",t.style.maxWidth="100%",t.style.padding="0")}
static applyVideoColStyles(){const t=document.querySelector(CONFIG.selectors.videoCol);t&&(t.style.width="100%",t.style.maxWidth="100%",
t.style.flexBasis="100%",t.style.padding="0 10px",t.classList.remove("col-md-8"),t.classList.add("col-md-12"))}static applySideColStyles(){
const t=document.querySelector(CONFIG.selectors.sideCol);t&&(t.style.display="none")}static applyPanelStyles(){
const t=document.querySelector(CONFIG.selectors.panelDefault);t&&(t.style.position="relative",t.style.clear="both",t.style.marginTop="15px",
t.style.zIndex="1")}static setupResizeListener(){window.addEventListener("resize",()=>{this.setWideScreenMode()})}}class LayoutReflow{static init(){
this.reflowLayout()}static reflowLayout(){try{const t=this.findLeftColumn(),e=this.findRightColumn();if(!t)return
;const n=document.querySelector(CONFIG.selectors.panelDefault)||document.querySelector(CONFIG.selectors.videoContainer)||t
;let i=document.querySelector(".hsx-two-col");i||(i=this.createTwoColumnLayout(n,t))
;const o=i.querySelector(".hsx-left"),s=i.querySelector(".hsx-right");this.handleRecommendedVideos(t,s),this.handleAuthorVideos(e,o)}catch(t){void 0}}
static findLeftColumn(){const t=document.querySelector(".videos");if(t){const e=t.closest(".col-md-8, .col-md-12");if(e)return e}
const e=document.querySelector(CONFIG.selectors.panelDefault);if(e){const t=e.closest(".col-md-8, .col-md-12");if(t)return t}
return document.querySelector(".col-md-8")||document.querySelector("#container .row > .col-md-12")}static findRightColumn(){
const t=document.querySelector(CONFIG.selectors.sideCol);if(t)return t
;const e=Array.from(document.querySelectorAll("h4")).find(t=>t.textContent&&-1!==t.textContent.indexOf("作者视频"))
;return e?e.closest(".col-md-4")||e.closest(".col-md-12"):null}static createTwoColumnLayout(t,e){const n=document.createElement("div")
;n.className="hsx-switch";const i=document.createElement("div");i.className="hsx-switch-btn active",i.textContent="作者视频"
;const o=document.createElement("div");o.className="hsx-switch-btn",o.textContent="推荐视频",n.appendChild(i),n.appendChild(o)
;const s=document.createElement("div");s.className="hsx-two-col single-left";const a=document.createElement("div");a.className="hsx-left"
;const l=document.createElement("div");return l.className="hsx-right",s.appendChild(a),s.appendChild(l),
t&&t.parentNode?(t.parentNode.insertBefore(n,t.nextSibling),n.parentNode.insertBefore(s,n.nextSibling)):(e.appendChild(n),e.appendChild(s)),
i.addEventListener("click",()=>{i.classList.add("active"),o.classList.remove("active"),s.classList.add("single-left"),
s.classList.remove("single-right")}),o.addEventListener("click",()=>{o.classList.add("active"),i.classList.remove("active"),
s.classList.add("single-right"),s.classList.remove("single-left")}),s}static handleRecommendedVideos(t,e){if(e&&0===e.childElementCount){
const n=Array.from(t.querySelectorAll("h4")).find(t=>t.textContent&&-1!==t.textContent.indexOf("推荐视频"));if(n){
let i=n.closest(".col-xs-12")||n.closest(".col-md-12")||n.parentElement
;for(i=i?i.nextElementSibling:null;i&&t.contains(i)&&(!i.classList||!i.classList.contains("hsx-two-col"));){const t=i.nextElementSibling
;if(i.querySelector&&i.querySelector(".thumbnail")){e.appendChild(i);const t=i.querySelector(".image");t&&(t.style.backgroundSize="cover",
t.style.backgroundPosition="center",t.style.minHeight="120px")}i=t}}}}static handleAuthorVideos(t,e){if(e&&0===e.childElementCount&&t){
const n=Array.from(t.querySelectorAll("h4")).find(t=>t.textContent&&-1!==t.textContent.indexOf("作者视频"));if(n){
let i=n.closest(".col-md-12")||n.closest(".col-xs-12")||t;for(i=i?i.nextElementSibling:null;i&&(t.contains(i)||i.closest(".col-md-4"));){
const t=i.nextElementSibling;if(i.querySelector&&i.querySelector(".thumbnail")){e.appendChild(i);const t=i.querySelector(".image")
;t&&(t.style.backgroundSize="cover",t.style.backgroundPosition="center",t.style.minHeight="90px")}i=t}}
0===e.querySelectorAll(".thumbnail").length&&Array.from(t.querySelectorAll(".thumbnail")).forEach(t=>{
const n=t.closest(".col-xs-6, .col-md-3, .col-xs-12, .col-md-12")||t;if(!e.contains(n)){e.appendChild(n);const t=n.querySelector(".image")
;t&&(t.style.backgroundSize="cover",t.style.backgroundPosition="center",t.style.minHeight="90px")}}),t&&t.parentElement&&(t.style.display="none")}}}
const t=class{static init(){this.addStyles()}static addStyles(){const t=document.createElement("style");t.textContent=this.cssRules,
document.head.appendChild(t)}}
;t.cssRules='\n    .container {\n      width: 100% !important;\n      max-width: 100% !important;\n      padding: 0 8px !important;\n    }\n    .videos_box {\n      width: 100% !important;\n      max-width: 100% !important;\n      margin: 0 auto !important;\n      position: relative !important;\n      z-index: 5 !important;\n      aspect-ratio: 16 / 9 !important;\n      min-height: 200px !important;\n      overflow: hidden !important;\n    }\n    .videos_box.hsx-hidden-until-ready { visibility: hidden !important; }\n    .video-js,\n    .video-play-dimensions {\n      width: 100% !important;\n      max-width: 100% !important;\n      position: relative !important;\n      z-index: 5 !important;\n    }\n    .video-js.vjs-fluid {\n      padding-top: 56.25% !important;\n      height: auto !important;\n    }\n    .video-play-dimensions { height: auto !important; }\n    .video-js .vjs-poster { opacity: 0.001 !important; }\n    .hsx-two-col {\n      display: grid !important;\n      grid-template-columns: minmax(280px, 1fr) minmax(0, 3fr) !important;\n      grid-gap: 16px !important;\n      margin-top: 16px !important;\n      width: 100% !important;\n    }\n    .hsx-two-col.single-left,\n    .hsx-two-col.single-right {\n      grid-template-columns: 1fr !important;\n    }\n    .hsx-two-col.single-left .hsx-right { display: none !important; }\n    .hsx-two-col.single-right .hsx-left { display: none !important; }\n    .hsx-left,\n    .hsx-right {\n      width: 100% !important;\n      display: grid !important;\n      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;\n      gap: 12px !important;\n      align-content: start !important;\n    }\n    .hsx-right > *,\n    .hsx-left > * { display: block !important; }\n    .hsx-two-col [class*="col-"] {\n      float: none !important;\n      width: auto !important;\n      max-width: 100% !important;\n      padding: 0 !important;\n    }\n    .hsx-two-col .row { margin: 0 !important; display: contents !important; }\n    .hsx-two-col .thumbnail {\n      margin-bottom: 0 !important;\n      display: block !important;\n    }\n    .hsx-two-col .thumbnail .image {\n      background-position: center center !important;\n      background-size: cover !important;\n      width: 100% !important;\n      min-height: 120px !important;\n    }\n    .hsx-switch {\n      display: flex !important;\n      gap: 8px !important;\n      margin: 10px 0 !important;\n    }\n    .hsx-switch .hsx-switch-btn {\n      padding: 6px 12px !important;\n      background: #2b2b2b !important;\n      color: #cfcfcf !important;\n      border-radius: 4px !important;\n      cursor: pointer !important;\n      user-select: none !important;\n    }\n    .hsx-switch .hsx-switch-btn.active {\n      background: #4a90e2 !important;\n      color: #fff !important;\n    }\n    .col-md-12 {\n      width: 100% !important;\n      max-width: 100% !important;\n      flex-basis: 100% !important;\n      padding: 0 10px !important;\n    }\n    .vjs-control-bar {\n      position: absolute !important;\n      left: 0 !important;\n      right: 0 !important;\n      bottom: 0 !important;\n      z-index: 10 !important;\n      clear: none !important;\n      width: auto !important;\n    }\n    .panel-default {\n      position: relative !important;\n      clear: both !important;\n      margin-top: 16px !important;\n      z-index: 1 !important;\n      width: 100% !important;\n      float: none !important;\n    }\n    .col-md-12:after {\n      content: "" !important;\n      display: table !important;\n      clear: both !important;\n    }\n    .thumbnail { margin-bottom: 15px; }\n  '
;let e=t;const n=class{static init(){this.setupDocumentListeners(),this.setupMutationObserver()}static runUpdates(){WideScreen.setWideScreenMode(),
LayoutReflow.reflowLayout()}static setupDocumentListeners(){
"loading"===document.readyState?document.addEventListener("DOMContentLoaded",this.runUpdates):this.runUpdates(),document.addEventListener("load",t=>{
const e=t.target;"VIDEO"!==e.tagName&&"IFRAME"!==e.tagName||this.runUpdates()},!0),window.addEventListener("load",this.runUpdates)}
static setupMutationObserver(){this.observer=new MutationObserver(t=>{t.some(t=>t.addedNodes.length>0)&&this.runUpdates()}),
this.observer.observe(document.body,{childList:!0,subtree:!0})}static destroy(){this.observer&&(this.observer.disconnect(),this.observer=null)}}
;n.observer=null;let i=n;function init(){WideScreen.init(),LayoutReflow.init(),i.init()}e.init(),init()})();