// ==UserScript== // @name 测试学外语视频外挂悬浮可点复制翻译字幕(google搜视频在线播-配合欧路词典),Learn-foreign-language-video-clickable-copying-subtitle // @description 电脑建议配合欧路词典划词翻译(查看图片展示设置) , 加减按钮调节字幕偏移时间(有的视频插入了广告导致字幕错位) , 显示按钮:电脑鼠标移动或者移动端触摸屏幕 , 字幕内鼠标滑轮滚动视频快进 , F全屏快捷键,(暂时不好用后期修复) , 移动端建议 (需要魔法-iphone下载m3u3免费资源下载器(safari插件),safari长按浏览器网络视频下载) , 地址 : https://translation-of-video-subtitles-by-extracting-words.vercel.app/ , 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.24.18.39.51 // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org // @author You // @downloadURL none // ==/UserScript== (()=>{"use strict";const F=e=>{console.log("%c"+e,` background-color: #811f21; color: white; line-height:1.5rem; padding:0 0.5rem; `)};function T(e){var t;t=e,!(document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement)||t!==document.fullscreenElement&&t!==document.mozFullScreenElement&&t!==document.webkitFullscreenElement&&t!==document.msFullscreenElement?(t=e,F("全屏视频"),t.requestFullscreen?t.requestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.msRequestFullscreen&&t.msRequestFullscreen(),void 0!==window.ActiveXObject&&null!=(e=new ActiveXObject("WScript.Shell"))&&e.SendKeys("{F11}")):(F("退出全屏视频"),document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen())}window.addEventListener("load",(function(){F("视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying"),$("iframe").each((function(){$(this).attr("allowfullscreen","true")})),navigator.mediaSession.setActionHandler("previoustrack",(function(){document.querySelector("video").currentTime-=3})),navigator.mediaSession.setActionHandler("nexttrack",(function(){document.querySelector("video").currentTime+=3}));const t=$("video");var e=t.parent(),o=(e=(e.addClass("videoWrapper"),e.css({position:"relative"}),t.append(""),t.attr("controls","true"),t.attr("playsInline","true"),t.attr("autopictureinpicture","true"),$("")),e.on("click",(function(e){e.stopPropagation(),F("全屏开关点击"),T(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","backdrop-filter":"blur(4px)"},s=(e.css({...n}),$(""));let r=!0;s.css({...n});const i=$("
");s.on("click",(function(e){e.stopPropagation(),F("字幕显示开关点击"),r=!r,i.css({display:r?"block":"none"})})),i.click((function(e){F("字幕外层点击"),e.stopPropagation()})),i.on("mousedown",(e=>{e.stopPropagation(),t?.[0].pause(),F("视频暂停")})),i.on("touchstart",(e=>{e.stopPropagation(),t?.[0].pause(),F("视频暂停")}));let a=!1;i.on("mouseup",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(t?.[0].pause(),F("视频暂停")):a||(t?.[0].play(),F("视频播放"))})),i.on("touchend",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(t?.[0].pause(),F("视频暂停")):a||(t?.[0].play(),F("视频播放"))})),i.css({...o,"backdrop-filter":"blur(8px)",mask:"linear-gradient(180deg, black 0%, rgba(0, 0, 0, 1) 80%,rgba(0, 0, 0, 0.0) 95%)",border:"2px solid #aaa8",transform:"translateX(-50%)",display:"block","user-select":"text",width:"80vw",bottom:"0",left:"50%",padding:"3vw 3vw 10vh 3vw","font-size":" 3vw","text-align":" center","border-radius":"3vw 3vw 0 0"});var l=$(' '),c=(l=(t.prepend(l),l.on("loadeddata",(e=>{e.stopPropagation(),F("轨道数据缓存")})),$(`
`)),l.css({"font-size":" 2vw","background-color":"#0004","order-radius":" 2vw !important",padding:"1vw 4vw",display:"flex","justify-content":"space-between","align-items":"center"}),$(` 字幕文件转格式.srt->: (.vtt)网站0 (.vtt)网站1 (.txt)网站2 (.txt)网站3 `));c.css({"line-height":"5vw"}),l.css({"font-size":"2vw","line-height":"5vw"}),l.on("change",(e=>{e.stopPropagation();e=e.target.files[0];e&&(document.querySelector(".videoTrack").src=URL.createObjectURL(e))}));let u=0,p=-1,d=-1;function m(e){console.log("单词元素 :",e),F($(this).text()+"被点击了"),$(this).css({"background-color":"#fff3","border-radius":"1vw"}),console.log("单词元素 :",[this,e]);(t=document?.createRange())?.selectNode(e);var t=window?.getSelection()?.addRange(t);console.log("添加选取 :",t),F(t?"添加选取成功":"添加选取失败");const o=e?.target?.textContent.match(/\b[\w]+\b/);navigator?.clipboard?.writeText(o)?.then((()=>{F("复制成功 "+o)}))?.catch((()=>{F("复制失败 "+o)}))}t.on("timeupdate",(e=>{e.stopPropagation();e=e?.target;var t=e?.currentTime+u,o=e?.textTracks[0]?.cues;if(e?.textTracks[0]?.cues?.length&&p!==parseInt(e?.currentTime))for(let e=0;e=t){d!==e&&(n=n?.text?.split(/\s+/)?.map((e=>`${e} `)).join(""),i.html(`

${n}

`),1<=e&&(n=(o?.[e-1])?.text?.split(/\s+/)?.map((e=>`${e} `)).join(""),i.append(`

${n}

`)),(n=$(".clickable_subtitle_middle")).on("mousedown","span",m),n.on("touchstart","span",m),n.on("mouseenter","span",m),n.on("mouseleave","span",(function(){$(this).css({"background-color":"#fff0","border-radius":"1vw"})})),d=e);break}}p=parseInt(e?.currentTime)}));var w=$("找字幕文件网1 "),b=$("找字幕文件网2 "),f=$("找字幕文件网3 "),v=(w.css({color:"#fff"}),b.css({color:"#fff"}),f.css({color:"#fff"}),$("
")),g=(v.css({"line-height":"6vw !important"}),$("
"));w=(g.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"}),g.append(w),g.append(b),g.append(f),v.append(l),v.append(c),v.append(g),i.prepend(v),i.on("mouseenter",(function(e){e.stopPropagation(),a=!0,t?.[0].pause(),F("视频暂停")})),i.on("mouseleave",(function(e){e.stopPropagation(),a=!1,i.css({height:"auto"}),$(".clickable_subtitle_middle").css({"margin-top":"0"}),window?.getSelection()?.toString()?(window?.getSelection()?.removeAllRanges(),t?.[0].pause(),F("视频暂停")):(t?.[0].play(),F("视频播放"))})),$(".videoWrapper"));w.css({"font-size":"2vw",padding:"0 1rem !important"});const h=$('
');let k=!1,y=void(h.on("mouseenter",(function(){k=!0})),h.on("mouseleave",(function(){k=!1})),h.css({...o,top:"50%",right:"0",color:"#fff",transform:"translateY(-50%)"}),t.on("touchstart",(e=>{e.stopPropagation(),h.css({opacity:"1",transition:"all 0.2s ease-in-out"})})),t.on("touchend",(e=>{e.stopPropagation(),clearTimeout($.data(this,"timer")),$.data(this,"timer",setTimeout((()=>{h.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3))})));$(document).on("mousemove",(function(e){e.stopPropagation(),y=!1,clearTimeout($.data(this,"timer")),h.css({opacity:"1",transition:"all 0.2s ease-in-out"}),k||$.data(this,"timer",setTimeout((()=>{k=!1,h.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3))}));b=$("");b.css({...n});const _=$("
0秒
"),x=(_.css({...n}),()=>{_.text(u+"秒")});b.on("click",(e=>{e.stopPropagation(),u++,x()}));f=$("");f.css({...n}),f.on("click",(e=>{e.stopPropagation(),u--,x()})),$("
").css({display:"flex","justify-content":"space-between","align-items":"center"}),h.append(e),h.append(s),h.append($("
  
")),h.append(f),h.append(_),h.append(b),w.append(h),w.append(i),document.querySelector(".floating_plug_in_for_clickable_subtitle_copying").onwheel=function(e){e.preventDefault(),e.deltaY<0?document.querySelector("video").currentTime-=3:document.querySelector("video").currentTime+=3};function S(e){e?.preventDefault();var t=e?.key;e=e?.keyCode;console?.log("key :",t,e),"f"!==t&&"F"!==t||T(document.querySelector(".videoWrapper"))}document?.addEventListener("keyup",S),document?.querySelector("video").addEventListener("keyup",S),$("*").css("user-select","text")}),!1)})();