Greasy Fork

Greasy Fork is available in English.

视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying

视频外挂西悬浮可点复制翻译字幕,floating plug-in for clickable subtitle copying

当前为 2023-12-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying

// @namespace    http://tampermonkey.net/
// @version      2023.12.15.11.34.37
// @description  视频外挂西悬浮可点复制翻译字幕,floating plug-in for clickable subtitle copying
// @author       You

// @match        *://*/*

// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant        none

// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @include      *

// @license      MIT

// ==/UserScript==

(function () {
  'use strict';

  // Your code here...

  // 报错油猴脚本使用jquery报错eslint:no-undef-‘$‘ is not defined
  /* globals jQuery, $, waitForKeyElements */

  // 彩色打印
  console.clog = (content) => {
    console.log(
      `%c${content}`,
      "background-color: #811f21; color: white;line-height:1.5rem; padding:0 0.5rem;"
    );
  }

  // 全屏封装
  function goFullScreen(element) {

    console.clog('全屏视频');
    // var element = document.getElementById("fullscreenElement");
    if (element.requestFullscreen) {
      element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
      element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
      element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
      element.msRequestFullscreen();
    }
  }

  function exitFullScreen() {
    console.clog('退出全屏视频');
    if (document.exitFullscreen) {
      document.exitFullscreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
      document.webkitExitFullscreen();
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    }
  }
  function checkFullScreen(element) {
    // var element = document.getElementById("fullscreenElement");

    if (document.fullscreenElement ||
      document.mozFullScreenElement ||
      document.webkitFullscreenElement ||
      document.msFullscreenElement) {
      if (element === document.fullscreenElement ||
        element === document.mozFullScreenElement ||
        element === document.webkitFullscreenElement ||
        element === document.msFullscreenElement) {
        console.log("元素处于全屏状态");
        return true
      } else {
        console.log("元素不处于全屏状态");
        return false
      }
    } else {
      console.log("不处于全屏状态");
      return false
    }
  }
  function autoFullScreen(el) {
    // var el = document,
    //   cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen,
    //   wscript;
    // if (typeof cfs != "undefined" && cfs) {
    //   cfs.call(el);
    //   return;
    // }
    if (!checkFullScreen(el)) {
      goFullScreen(el)
    } else {
      exitFullScreen()
      return
    }
    if (typeof window.ActiveXObject != "undefined") {
      wscript = new ActiveXObject("WScript.Shell");
      if (wscript != null) {
        wscript.SendKeys("{F11}");
      }
    }
  }

  // 等待网页完成加载
  window.addEventListener('load', function () {
    // 加载完成后执行的代码
    console.clog('视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying');

    // 视频外层
    $('video').parent().addClass("videoWrapper");
    // $('video').wrapAll('<div class="videoWrapper" style="position: relative;"/>');

    // 全屏开关元素
    const clickable_subtitle_switch_button = $("<div class='switchButton'>全屏</div>")
    // 全屏开关事件
    clickable_subtitle_switch_button.click(function (event) {
      console.clog('全屏开关点击');
      autoFullScreen(document.querySelector('.videoWrapper'));
      // 阻止冒泡
      event.stopPropagation();
    });
    // 全屏开关样式
    clickable_subtitle_switch_button.css({
      'line-height': '1.5rem',
      'padding': '0 3rem',
      'font-size': '1rem',
      'top': '50%',
      'left': '95%',
      'transform': 'translate(-50%,-50%)',
      'z-index': '2147483647',
      'color': '#fff',
      'background-color': '#888',
      'position': 'absolute',
      'cursor': 'pointer',
      'user-select': 'none !important',
    });

    // 网页外挂字幕元素
    const clickable_subtitle_wapper = $("<div class='floating_plug_in_for_clickable_subtitle_copying'>可点击字幕</div>")

    // 网页外挂字幕事件
    clickable_subtitle_wapper.click(function (event) {
      console.clog('字幕外层点击');

      // 阻止冒泡
      event.stopPropagation();
    });
    // 网页外挂字幕样式
    clickable_subtitle_wapper.css({
      'user-select': 'auto !important',
      'with': '50vw',
      'line-height': '1.5rem',
      'padding': '0 0.5rem',
      'font-size': '1rem',
      'bottom': '10%',
      'left': '50%',
      'transform': 'translate(-50%,-50%)',
      'z-index': '2147483647',
      'color': '#fff',
      'background-color': '#444',
      'position': 'absolute',
    });

    // 网页外挂字幕文件
    const clickable_subtitle_input_file = $("<input class='clickable_subtitle_input_file' type='file' accept='.srt/.vtt' >上传文件(.srt/.vtt)</input>")

    // 射手字幕网找字幕
    const clickable_subtitle_find_subtitle_webSite = $("<a class='clickable_subtitle_find_subtitle_webSite' href='https://assrt.net/' target='字幕网'>找英文字幕</a>")
    clickable_subtitle_find_subtitle_webSite.css({
      display: 'block',
      color: '#fff',
    })

    // 找字幕外层
    const clickable_subtitle_find_subtitle_wapper = $("<div class='clickable_subtitle_find_subtitle_wapper'></div>")

    clickable_subtitle_find_subtitle_wapper.append(clickable_subtitle_find_subtitle_webSite)
    clickable_subtitle_find_subtitle_wapper.append(clickable_subtitle_input_file)
    clickable_subtitle_wapper.append(clickable_subtitle_find_subtitle_wapper);

    // 准备改成父级嵌套
    // 挂载开关
    const videoWrapper = $('.videoWrapper')
    videoWrapper.append(clickable_subtitle_switch_button);
    videoWrapper.append(clickable_subtitle_wapper);
  }, false);

})();