Greasy Fork

Greasy Fork is available in English.

学外语视频外挂悬浮可点复制翻译字幕,Learn-foreign-language-video-floating-plug-in-for-clickable-copying-subtitle

显示按钮:电脑鼠标移动或者移动端触摸屏幕, 视频内鼠标滑轮滚动视频快进, F全屏快捷键,----------- 电脑建议配合欧路词典划词翻译, iphone 建议使用快捷指令获取剪贴板翻译, 安卓手机建议使用屏幕取词软件

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         学外语视频外挂悬浮可点复制翻译字幕,Learn-foreign-language-video-floating-plug-in-for-clickable-copying-subtitle
// @description  显示按钮:电脑鼠标移动或者移动端触摸屏幕, 视频内鼠标滑轮滚动视频快进, F全屏快捷键,----------- 电脑建议配合欧路词典划词翻译, iphone 建议使用快捷指令获取剪贴板翻译, 安卓手机建议使用屏幕取词软件
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @require      https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js
// @require      https://unpkg.com/default-passive-events
// @include      *
// @match        *://*/*
// @namespace    http://tampermonkey.net/
// @version      2023.12.20.18.12.05
// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @author       You
// ==/UserScript==

(()=>{"use strict";const x=e=>{console.log("%c"+e,`
      background-color: #811f21;
      color: white;
      line-height:1.5rem;
      padding:0 0.5rem;
    `)};function F(e){!function(e){if(document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement){if(e===document.fullscreenElement||e===document.mozFullScreenElement||e===document.webkitFullscreenElement||e===document.msFullscreenElement)return console.log("元素处于全屏状态"),1;console.log("元素不处于全屏状态")}else console.log("不处于全屏状态")}(e)?(x("全屏视频"),e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen(),void 0!==window.ActiveXObject&&null!=(e=new ActiveXObject("WScript.Shell"))&&e.SendKeys("{F11}")):(x("退出全屏视频"),document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen())}let S=0;const T=(e=[],t=0,o=0,n=0,s=e?.length,l=Math?.floor((n+s)/2),i=5e3)=>{if(console.log("二分查找递归:",t,n,s,l),x("二分查找次数:"+S),i<o)return x("栈溢出调用 :",o),!1;i=e?.[l];switch(!0){case i?.startTime<=t&&i?.endTime>=t:x("二分查找 :找到字幕了");var a=item?.text?.split(/\s+/)?.map((e=>`<span  style="user-select:text;  word-wrap: break-word;  overflow-wrap: break-word;  white-space:pre-wrap;  transition: all 0.2s ease-in-out;  line-height: 5vw !important;  padding: 0 .2vw;"   class="clickable_subtitle_word">${e}</span><i> </i>`)).join("");a=(clickable_subtitle_wapper.html(`<p   class="clickable_subtitle_middle"  style="user-select:text;  word-wrap: break-word;  overflow-wrap: break-word;  white-space:pre-wrap;  line-height: 4rvw !important;">${a}</p>`),$(".clickable_subtitle_middle"));a.on("mousedown","span",copyWord),a.on("touchstart","span",copyWord),a.on("mouseenter","span",copyWord),a.on("mouseleave","span",(function(e){isMovesONword=!1,$(this).css({"background-color":"#fff0","border-radius":"1vw"})}));break;case i?.startTime<t&&i?.endTime<t:x("二分查找 :中分字幕小往后找"),T(e,t,++S,l+1,s);break;case i?.endTime>t&&i?.startTime>t:x("二分查找 :中分字幕大往前找"),T(e,t,++S,n,l-1)}};window.addEventListener("load",(function(){x("视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying"),$("iframe").each((function(){$(this).attr("allowfullscreen","true")}));const t=$("video");var e=t.parent(),o=(e=(e.addClass("videoWrapper"),e.css({position:"relative"}),t.append("<style>video::cue{opacity: 0 !important}</style>"),t.attr("controls","true"),t.attr("playsInline","true"),$("<button class='switchButton'>全屏</button>")),e.on("click",(function(e){e.stopPropagation(),x("全屏开关点击"),F(document.querySelector(".videoWrapper"))})),{"z-index":"2147483647",color:"#fff",position:"absolute",transition:"all 0.2s ease-in-out"}),n={margin:"1vw",display:"block",padding:"0.5vw","border-radius":".5vw","background-color":"#1118","font-size":"1.5vw",cursor:"pointer","user-select":"text","line-height":"2.5rem !important",color:"#fffb",transition:"all 0.2s ease-in-out"},s=(e.css({...n}),$("<button class='switchButton'>显隐</button>"));let l=!0;s.css({...n});const i=$("<div class='floating_plug_in_for_clickable_subtitle_copying'></div>");s.on("click",(function(e){e.stopPropagation(),x("字幕显示开关点击"),l=!l,i.css({display:l?"block":"none"})})),i.click((function(e){x("字幕外层点击"),e.stopPropagation()})),i.on("mousedown",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),x("视频暂停")})),i.on("touchstart",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),x("视频暂停")})),i.on("mouseup",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),x("视频暂停")):(console.log(" :",[t]),g||(t?.[0].play(),x("视频播放")))})),i.on("touchend",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),x("视频暂停")):(console.log(" :",[t]),t?.[0].play(),x("视频播放"))})),i.css({...o,border:"2px solid #aaa8",transform:"translateX(-50%)",display:"block","user-select":"text",width:"80vw",bottom:"0",left:"50%",padding:"3vw 3vw 10vh 3vw","background-color":"#1b2129ee","font-size":" 3vw","text-align":" center",mask:"linear-gradient(180deg, black 0%, rgba(0, 0, 0, 1) 80%,rgba(0, 0, 0, 0.0) 95%)","border-radius":"3vw 3vw 0 0","box-shadow":"inset 0 0 2vw #666"});var a=$('<track  class="videoTrack" kind = "subtitles" default /> '),c=(a=(t.prepend(a),a.on("loadeddata",(e=>{e.stopPropagation(),x("轨道数据缓存"),console.log("数据 :",e)})),$(`
  <div>
    <input 
      id='subtitle_input' 
      style='font-size: 2vw;' 
      class='clickable_subtitle_input_file'
      type='file' 
      accept='.vtt'
      placeholder="上传字幕文件(.vtt)"
    ></input>
    <label style='font-size: 2vw;' for='subtitle_input'>请上传该视频字幕文件(.vtt)</label>  
  </div> 
  `)),a.css({"font-size":" 2vw","background-color":"#0004","order-radius":" 2vw !important",padding:"1vw 4vw",display:"flex","justify-content":"space-between","align-items":"center"}),$(`
  <span>字幕文件转格式.srt->:</span>
  <a 
    style='color:#fff;' 
    href='https://converter.app/cn/srt-vtt/' 
    target='转格式'
  > (.vtt)网站0</a>
  <a 
    style='color:#fff;' 
    href='https://subtitletools.com/convert-subtitles-to-plain-text-online' 
    target='转格式'
  > (.txt)网站1</a>
  <a 
    style='color:#fff;' 
    href='https://converts.me/tools/conversion/subtitle/srt-to-txt' 
    target='转格式'
  > (.txt)网站2</a>
  `));c.css({"line-height":"5vw"}),a.css({"font-size":"2vw","line-height":"5vw"}),a.on("change",(e=>{e.stopPropagation();e=e.target.files[0];console.log("file :",e),e&&(document.querySelector(".videoTrack").src=URL.createObjectURL(e),console.log("视频元素 :",[t]))}));let r=0,u=-1;t.on("timeupdate",(e=>{e.stopPropagation();e=e?.target;var t=e?.currentTime+r;e?.textTracks[0];e?.textTracks[0]?.cues?.length&&u!==parseInt(e?.currentTime)&&T(e?.textTracks[0]?.cues,t,++S);u=parseInt(e?.currentTime)}));var p=$("<a class='clickable_subtitle_find_subtitle_webSite' href='https://assrt.net/' target='字幕网'>找字幕文件网1 </a>"),d=$("<a class='clickable_subtitle_find_subtitle_webSite' href='https://www.opensubtitles.org/zh' target='字幕网'>找字幕文件网2 </a>"),m=$("<a class='clickable_subtitle_find_subtitle_webSite' href='https://subscene.com/' target='字幕网'>找字幕文件网3 </a>"),f=(p.css({color:"#fff"}),d.css({color:"#fff"}),m.css({color:"#fff"}),$("<div class='clickable_subtitle_find_subtitle_wapper'></div>")),b=(f.css({"line-height":"6vw !important"}),$("<div class='clickable_subtitle_find_subtitle_webSite_wapper'></div>"));b.css({display:"flex","justify-content":"space-between","align-items":"center","font-size":"2vw","order-radius":"2vw !important",padding:"1vw 4vw","background-color":"#0004","line-height":"5vw"}),b.append(p),b.append(d),b.append(m),f.append(a),f.append(c),f.append(b),i.prepend(f);let g=!1;i.on("mouseenter",(function(e){e.stopPropagation(),g=!0,console.log("鼠标移入了外框!"),t?.[0].pause(),x("视频暂停")})),i.on("mouseleave",(function(e){e.stopPropagation(),g=!1,console.log("鼠标移出了外框!"),i.css({height:"auto"}),$(".clickable_subtitle_middle").css({"margin-top":"0"}),t?.[0].play(),x("视频播放")}));p=$(".videoWrapper");p.css({"font-size":"2vw",padding:"0 1rem !important"});const v=$('<div class="buttonWrapper"/>');let w=!1,h=void(v.on("mouseenter",(function(){console.log("鼠标移入了按钮!"),w=!0})),v.on("mouseleave",(function(){console.log("鼠标移出了按钮!"),w=!1})),v.css({...o,top:"50%",right:"0",color:"#fff",transform:"translateY(-50%)"}),t.on("touchstart",(e=>{e.stopPropagation(),v.css({opacity:"1",transition:"all 0.2s ease-in-out"})})),t.on("touchend",(e=>{e.stopPropagation(),this.setTimeout((()=>{v.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3)})));$(document).on("mousemove",(function(e){e.stopPropagation(),h=!1,clearTimeout($.data(this,"timer")),v.css({opacity:"1",transition:"all 0.2s ease-in-out"}),w||$.data(this,"timer",setTimeout((()=>{w=!1,v.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3))}));d=$("<button>加</button>");d.css({...n});const k=$("<div>0秒</div>"),_=(k.css({...n}),()=>{k.text(r+"秒")});d.on("click",(e=>{e.stopPropagation(),r++,_()}));m=$("<button>减</button>");m.css({...n}),m.on("click",(e=>{e.stopPropagation(),r--,_()})),$("<div/>").css({display:"flex","justify-content":"space-between","align-items":"center"}),v.append(e),v.append(s),v.append($("<div>&nbsp;&nbsp;</div>")),v.append(m),v.append(k),v.append(d),p.append(v),p.append(i),document.querySelector(".floating_plug_in_for_clickable_subtitle_copying").onwheel=function(e){console.log("字幕上滚动鼠标滑轮 :",e),e.preventDefault(),e.deltaY<0?(console.log("向上滚动"),document.querySelector("video").currentTime-=5):(console.log("向下滚动"),document.querySelector("video").currentTime+=5)};function y(e){e?.preventDefault();var t=e?.key;e=e?.keyCode;console?.log("key :",t,e),"f"!==t&&"F"!==t||F(document.querySelector(".videoWrapper"))}document?.addEventListener("keyup",y),document?.querySelector("video").addEventListener("keyup",y),$("*").css("user-select","text")}),!1)})();