video fullpage

2024-7-12 18:05:52

目前為 2024-07-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name        video fullpage
// @namespace   github.q962
// @match       https://*/*
// @version     1.2
// @author      q962
// @grant       GM_registerMenuCommand
// @grant       GM_addStyle
// @grant       GM_deleteValue
// @grant       GM_deleteValues
// @grant       GM_setValue
// @grant       GM_setValues
// @grant       GM_getValue
// @grant       GM_getValues
// @grant       GM_listValues
// @grant       GM_addElement
// @license     MIT

// @description 2024-7-12 18:05:52
// ==/UserScript==

let global_css = `
.___fullpage{
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 999999999 !important;
  position: fixed !important;
  background: black !important;
  display: block !important;
}

.___fix > * {
  display: none;
}

.__dialog {
  position: fixed;
  width: 600px;
  height: auto;
  top: 30vh;
  z-index: 99999;
}
.__dialog > *, .__dialog > h1 {
  color: black;
}
.__dialog input {
  width: 90%;
}
`;

GM_addStyle(global_css);

/////////////////////////////////////////////////////////


let count_dialog = GM_addElement('dialog');
count_dialog.classList.add("__dialog");
count_dialog.innerHTML = `
  <h1>设置上层层数</h1>
  <label>正则:<input id="regex"/></label><br/>
  <label>层数:<input id="count" min=0 max=15 type="number"  value=0 /></label><br/>
  <br/>
  <button id="ok">确定</button>
  <button id="cancel">取消</button>
  <p id="msg"></p>
`;

let regex_elem = count_dialog.querySelector("#regex");
let count_elem = count_dialog.querySelector("#count");
let msg_elem = count_dialog.querySelector("#msg");

count_dialog.querySelector("#ok").addEventListener("click", ()=>{
  let regex_str = regex_elem.value;
  let count = count_elem.value;

  if( !regex_str ) return;
  try{
    new RegExp(regex_str);
  } catch(error){
    msg_elem.innerText = error;
    return;
  }

  if( count>15 || count < 0 ){
    msg_elem.innerText = "0 <= 层数  <=15";
    return;
  }

  GM_setValue(location.origin, JSON.stringify({regex: regex_str, count: count}));

  count_dialog.open = false;
});

count_dialog.querySelector("#cancel").addEventListener("click", ()=>{
  count_dialog.open = false;
});

/////////////////////////

function get_upCount(){
  let j = JSON.parse(GM_getValue(location.origin)||null);
  if(!j) return 0;

  if( j.regex ) {
    try{
      let regex = new RegExp(j.regex);
      if( !regex.test(location.href) ) return 0;
   } catch(error){return 0;}
  }

  return parseInt(j.count);
}


///////////////////////////////

const all_video_elems = [];

let upCount = get_upCount();
let current_video_parent_elemt = null;
let current_video_elem = null;
let current_video_next_elemt = null;

///////////////////////////////

function settings(){
  count_elem.value = 0;
  regex_elem.value = (location.origin+location.pathname).replaceAll(".","\\.");

  let j = JSON.parse(GM_getValue(location.origin)||null);
  if( j ) {
    if( j.regex ) regex_elem.value = j.regex;
    if( j.count ) count_elem.value = j.count;
  }

  msg_elem.innerText = "";

  count_dialog.open = true;
}

function set_fullpage(){

  if(!current_video_elem)return;

  if(current_video_elem.classList.contains("___fullpage")){
      current_video_elem.classList.remove("___fullpage");

      document.body.classList.remove("___fix");

      current_video_parent_elemt.insertBefore(current_video_elem, current_video_next_elemt);
  }else{
      current_video_elem.classList.add("___fullpage");

      document.body.classList.add("___fix");

      document.body.append(current_video_elem);
  }
}

GM_registerMenuCommand('全页', set_fullpage);
GM_registerMenuCommand('设置', settings);

function bind_evnet(elem){
  elem.addEventListener('play', function (e) {
    current_video_elem = null;

    do {
      if(current_video_elem)
        current_video_elem = current_video_elem.parentElement;
      else
        current_video_elem = e.target;

      current_video_parent_elemt = current_video_elem.parentElement;
      current_video_next_elemt = current_video_elem.nextSibling;

    } while( --upCount >= 0 );
  });

  elem.addEventListener('pause', function (e) {
  });
}

function findingVideoElem(){

  let video_elems = document.querySelectorAll("video");

  for( let index=0; index < video_elems.length; index++){
    let video_elem = video_elems[index];

    if( !( video_elem in all_video_elems )) {
      bind_evnet( video_elem );
      all_video_elems.push( video_elem );
    }
  }
}

setInterval(findingVideoElem, 2000);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址