// ==UserScript==
// @name OMPS多人在线同播
// @namespace https://xypp.cc/omps/
// @version 6.1
// @description OMPS多人在线同播。脚本默认对所有站点均生效。您可以在TamperMonkey=>管理面板=>OMPS多人在线同播=>设置=>用户排除中修改不想要生效的网站或直接修改源代码
// @author 小鱼飘飘
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=omofun.tv
// @grant GM_setValue
// @grant GM_getValue
// @grant unsafeWindow
// @grant GM_getTab
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
//为非油猴的直接运行方式优化
var GM_window, GM_get, GM_set;
if (typeof unsafeWindow != 'object') GM_window = window;
else GM_window = unsafeWindow;
if (typeof GM_getValue != 'function') {
GM_get = function (key, val) {
return GM_window.localStorage.getItem(key) || val;
};
GM_set = function (key, val) {
return GM_window.localStorage.setItem(key, val);
};
} else {
GM_get = GM_getValue;
GM_set = GM_setValue;
}
const URL = "wss://public.xypp.cc:8093";
try {
document.body.setAttribute("data-omps-injected", "true");
} catch (e) { }
function getTextSafe(text) {
var tmpElement = document.createElement("div");
if (tmpElement.textContent !== null) tmpElement.textContent = text;
else tmpElement.innerText = text;
var retText = tmpElement.innerHTML;
return retText;
}
var ws;
var video;
var trustKey = GM_get("trust", "none");
var initFinish = false, lastTime = -1, pauseAt, globalCount = 24, toastCnt = 0, tmpLocalDelay, localDelay, initTime, videoCode = "", HASH = {}, videoTitle = "", videoUrl = "";
const css = `.omps-friend{position:absolute;top:140px;left:0}.omps-friend .item{height:30px;border-radius:0 40px 40px 0;background-color:rgba(0,0,0,0.772);padding-left:10px;padding-right:5px;line-height:25px;font-size:15px;color:white;max-width:300px;margin-top:3px}.omps-friend .item.offline{opacity:.5;text-decoration:line-through}.omps-tip{position:absolute;top:100px;height:40px;border-radius:0 40px 40px 0;left:-300px;background-color:rgba(0,0,0,0.772);padding-left:10px;line-height:35px;color:white;max-width:100%;z-index:10000000;transition:all 1s;opacity:0}.omps-tip.open{left:0;opacity:1}.omps-tip div{display:inline;font-size:20px}.omps-tip .btn{color:black;background-color:#fff;border-radius:30px;padding:5px 7px;margin-right:6px;line-height:13px;box-shadow:grey 1px 1px 1px;text-align:center;display:inline-block;vertical-align:middle}.omps-tip .btn svg,.omps-chat-input svg,.omps-chat svg,.omps-friend svg{height:20px;width:20px}.omps-tip .btn svg path{fill:black}.omps-tip .btn:hover{background-color:#dcdcdc}.omps-tip .btn:active{box-shadow:inset gray 1px 1px 1px}.omps-tip .btn span{display:none}.omps-tip .btn:hover span{animation:showLabelAnim 1s linear 1s 1;animation-fill-mode:forwards;max-width:0;overflow-x:hidden;word-break:keep-all;margin:0;display:unset;padding:0;line-height:20px;overflow-y:clip;float:right}@keyframes showLabelAnim{0%{max-width:0}100%{max-width:200px}}.omps-config{font-size:18px;z-index:10000003;max-width:calc(100% - 100px);position:absolute;top:50px;width:600px;left:50px;background-color:rgba(0,0,0,0.772);border-radius:10px;color:white;padding:20px;max-height:calc(100% - 100px);overflow:auto}.omps-config input{display:block;outline:0;border:0;border-radius:5px;color:black;background-color:rgba(255,255,255,0.772)}.omps-config input:active{box-shadow:skyblue 0 0 5px 3px}.omps-config input:focus{box-shadow:skyblue 0 0 3px 1px}.omps-config input.i{height:30px;width:300px;max-width:100%}.omps-config input.c{height:20px;width:20px;-webkit-appearance:checkbox!important;appearance:checkbox!important}.omps-config label{display:block;text-decoration:underline}.omps-config small{display:block;color:lightgray}.omps-config .btn{color:black;background-color:#fff;border-radius:30px;padding:5px 10px;margin-right:10px;box-shadow:grey 1px 1px 1px;text-align:center;display:inline-block;vertical-align:middle}.omps-config .btn:hover{background-color:#dcdcdc}.omps-config .btn:active{box-shadow:inset gray 1px 1px 1px}.omps-chat{font-size:18px;position:absolute;top:5px;right:0;overflow-x:hidden;max-width:100%;width:400px}.omps-chat .item{border-radius:40px 0 0 40px;background-color:rgba(0,0,0,0.772);color:white;max-width:calc(100% - 30px);z-index:10000000;transition:all 1s;opacity:0;transform:translateX(100%);position:relative;margin-top:2px;max-height:0;line-break:loose;word-break:break-all;white-space:normal;overflow:hidden}.omps-chat .item.open{transform:translateX(0%);opacity:1;max-height:400px;padding:10px}.omps-chat .item .name{text-decoration:underline;font-weight:bold}.omps-chat .item .delay{font-size:x-small;font-style:italic;position:absolute;top:1px;right:1px}.omps-chat-input{position:absolute;bottom:50px;right:100px;width:calc(100% - 200px);background-color:rgba(0,0,0,0.772);height:40px}.omps-chat-input{font-size:18px;position:absolute;bottom:150px;right:100px;width:calc(100% - 200px);background-color:rgba(0,0,0,0.772);border-radius:50px;padding:10px 30px;opacity:0;transition:all .5s}.omps-chat-input.tipPos{animation:omps-tipPos 1s ease-in-out 0s infinite}.omps-chat-input:hover,.omps-chat-input.inputActive{opacity:1}@keyframes omps-tipPos{0%{opacity:0}50%{opacity:.5}100%{opacity:0}}.omps-chat-input input{background-color:rgba(0,0,0,0);display:inline-block;outline:0;border:rgba(255,255,255,0.497) 1px solid;border-radius:5px;width:calc(100% - 100px);height:100%;color:white}.omps-chat-input input:active{box-shadow:skyblue 0 0 5px 3px}.omps-chat-input input:focus{box-shadow:skyblue 0 0 3px 1px}.omps-chat-input .btn,.omps-chat .btn{color:black;background-color:#fff;border-radius:30px;padding:5px 10px;margin-right:10px;box-shadow:grey 1px 1px 1px;text-align:center;display:inline-block;vertical-align:middle}.omps-chat-input .btn svg path,.omps-chat .btn svg path{fill:black}.omps-chat-input .btn:hover,.omps-chat .btn:hover{background-color:#dcdcdc}.omps-chat-input .btn:active,.omps-chat .btn:active{box-shadow:inset gray 1px 1px 1px}.omps-chat .btn{padding: 2px 5px;font-size: 16px;}`;
const lang = {
join: "检测到视频,点击进入联机放映",
reconfigure: "重新填写配置",
quickJoin: "快速加入",
quit: "关闭",
setting: {
userId: {
label: "用户名",
tip: "其他用户看到您的名字。请不要使用短用户名防止重名"
},
group: {
label: "加入的房间ID",
tip: "该房间ID用于同步进度。与您的朋友输入相同的房间ID且您和朋友正在观看相同的视频时,你们的进度将会被同步"
},
autoJoin: {
label: "自动加入",
tip: "勾选后,下次检测到视频将会自动进入上次填写的群组"
},
silent: {
label: "静默模式",
tip: "仅会提示您失去同步消息,不会提示您成功消息"
},
friend: {
label: "显示好友",
tip: "在窗口左侧显示一个好友列表,展示您和好友的进度"
},
showMsgIpt: {
label: "显示消息输入框",
tip: "在视频下方中央显示一个输入框,这将您允许发送消息"
},
hideMsg: {
label: "隐藏消息",
tip: "隐藏消息,不显示别人发送的消息。注意,打开此功能后,显示消息输入框功能将失效。"
},
saveExit: "保存并关闭",
saveJoin: "保存并连接"
},
conErr: "无法连接到服务器,请刷新页面重试",
pauseMsg: "有一位朋友的视频太慢了,等他一下...",
playFail: "未能正确的开始播放视频!您需要手动点击播放按钮,否则您的好友可能需要等待您",
delay: ["延迟达到了", "ms,可能会影响您或其他人的观影体验"],
success: "连接成功,延迟",
syncSuccess: "同步进度完成",
playerJoin: "加入了放映厅",
sync: "同步",
call: "集合",
sendmsg: "发送",
unsync: ["失去同步!您可以同步至", "的最快进度(", "s)或者呼叫其他用户集合"],
unsync_top: "失去同步!您是目前的最快进度,您可以呼叫其他用户集合",
videoChange: "视频变更,准备重连",
dumplName: "注册失败,与服务器中已连接的用户重名",
secondConnect: "因为您的另一个客户端的连接,本页面已与服务器断开连接",
tiper:"提示",
jumpTip:["用户[","]从此视频转向观看‘","’","点击前往"],
jumpConfirm:["您即将前往","跳转到目标网站可能会带来不明的风险,您确定要跳转吗?"]
}
//===========设置相关============
var setting = {
autoJoin: "",
userId: parseInt(Math.random() * 10000),
group: "",
silent: "",
friend: "",
showMsgIpt: "",
hideMsg: ""
};
//导入设置(TamporMonkey/LocalStorage)
for (const settingItem in setting) {
if (Object.hasOwnProperty.call(setting, settingItem)) {
const defaultVal = setting[settingItem];
setting[settingItem] = GM_get(settingItem, defaultVal);
}
}
var openedSettingPanel;
//[函数]打开设置面板
function openSettingPanel() {
if (openedSettingPanel) {
closeSettingPanel();
}
var el = document.createElement("div");
el.className = "omps-config";
el.id = "omps-config";
el.onclick = noPop
el.innerHTML = msgMaker.settingPanel();
document.body.appendChild(el);
openedSettingPanel = el;
}
function saveSettings() {
var el = document.getElementById("omps-config");
if (!el) return;
GM_set("userId", document.getElementById("omps-input-name").value);
GM_set("group", document.getElementById("omps-input-group").value);
GM_set("autoJoin", document.getElementById("omps-input-quick").checked ? "1" : "");
GM_set("silent", document.getElementById("omps-input-silent").checked ? "1" : "");
GM_set("friend", document.getElementById("omps-input-friend").checked ? "1" : "");
GM_set("showMsgIpt", document.getElementById("omps-input-showMsgIpt").checked ? "1" : "");
GM_set("hideMsg", document.getElementById("omps-input-hideMsg").checked ? "1" : "");
setting.userId = document.getElementById("omps-input-name").value;
setting.group = document.getElementById("omps-input-group").value;
setting.autoJoin = document.getElementById("omps-input-quick").checked ? "1" : "";
setting.silent = document.getElementById("omps-input-silent").checked ? "1" : "";
setting.friend = document.getElementById("omps-input-friend").checked ? "1" : "";
setting.showMsgIpt = document.getElementById("omps-input-showMsgIpt").checked ? "1" : "";
setting.hideMsg = document.getElementById("omps-input-hideMsg").checked ? "1" : "";
}
function closeSettingPanel() {
var el = openedSettingPanel;
if (el && el.parentNode) {
el.parentNode.removeChild(el);
}
}
//===========设置相关============
var msgMaker = {
settingPanel: () => {//设置面板
return `
${lang.setting.userId.tip}
${lang.setting.group.tip}
${lang.setting.autoJoin.tip}
${lang.setting.silent.tip}
${lang.setting.friend.tip}
${lang.setting.showMsgIpt.tip}
${lang.setting.hideMsg.tip}
${lang.setting.saveExit}
${lang.setting.saveJoin}
`;
},
joinAsk: (hasConfigured) => {
return `${lang.join}
${lang.reconfigure}
${lang.quickJoin}
${lang.quit}
`;
},
success: (code, delv) => {
return `${lang.success}${getTextSafe(delv)}
${lang.reconfigure}
${lang.quit}
`;
},
conErr: () => {
return `${lang.conErr}`;
},
pauseMsg: () => {
return `${lang.pauseMsg}`;
},
playFail: () => {
return `${lang.playFail}`;
},
delayTip: (delv) => {
return `${lang.delay[0]}${getTextSafe(delv)}${lang.delay[1]}`;
},
syncSuccess: () => {
return lang.syncSuccess;
},
playerJoin: (pname) => {
return `${getTextSafe(pname)}${lang.playerJoin}`;
},
unsync: (target, deltaTime) => {
return `${lang.unsync[0]}${getTextSafe(target)}${lang.unsync[1]}${getTextSafe(deltaTime)}${lang.unsync[2]}
${lang.sync}
${lang.call}
`
},
unsync_top: () => {
return `${lang.unsync_top}
${lang.call}
`
},
chat_input: () => {
return `
${lang.sendmsg}
`;
},
chat_block: (name, msg, time) => {
return `
${getTextSafe(name)}
:
${getTextSafe(msg)}
${time}
`;
},
error: (msg) => {
if (msg == "E_USERNAME_DUMPL") {
return `
${lang.dumplName}
${lang.reconfigure}
${lang.quit}
`;
} else if (msg == "E_SECOND_CONN") {
return `${lang.secondConnect}
${lang.reconfigure}
${lang.quickJoin}
${lang.quit}
`;
}
},
userJump:(name,title,url) =>{
if(title.length>80){
title = title.substr(0,80)+"...";
}
var urlDat = "";
try { urlDat = window.btoa(url) }catch(e){}
var urlBtn = `