// ==UserScript== // @name DRRR助手(drrr-helper) 2024新春版 // @description Dollars聊天室辅助脚本 // @namespace Violentmonkey Scripts // @match https://drrr.com/room/* // @license MIT // @version 4.2.9 // @author QQ:121610059 // @update 2024-02-10 20:00:01 // @run-at window-load // @supportURL https://greasyfork.org/zh-CN/scripts/414535-drrr-com%E6%99%BA%E8%83%BD%E8%84%9A%E6%9C%AC-%E8%87%AA%E5%8A%A8%E5%AF%B9%E8%AF%9D-%E8%87%AA%E5%8A%A8%E7%82%B9%E6%AD%8C // @downloadURL none // ==/UserScript== (function () { 'use strict'; // 清空控制台信息 console.clear(); // 被禁止进入房间 if (document.querySelector('.container')) { alert('🆕 被禁止进入该房间,请尝试其他房间。'); return; } unsafeWindow.DRRR_HELPER_API = { // 弹出提示信息 showTip: (message, type = '', title = '提示信息', time = 3000) => { unsafeWindow.swal(title, message, type); setTimeout(() => unsafeWindow.swal.close() ,time); }, // 自定义播放事件 onMusic: { start: function(e) { console.log('开始播放') console.log(e) }, end: function(e) { console.log('播放结束') console.log(e) }, pause: function(e) { console.log('播放暂停') console.log(e) }, stop: function (e) { console.log('播放停止') console.log(e) }, loaderror: function (e, n) { console.log('😊 播放错误: ', '错误代码' + e, n) } }, // 消息处理方法 onHandleMessage: { chat: (user,message) => { console.log('🆕 聊天消息: ', user, message) }, join: (user) => { console.log('🆕 进入房间', user) }, leave: (user) => { console.log('🆕 离开房间', user) }, default: () => { //console.log('🆕 收到其他类型的消息') } }, // 发送消息方法 sendMessage: (data = false)=> { // 示例数据 const example = [ { message: 'xiaoxi', url: '网址', to: '用户id' }, { music: 'music', name: '歌曲名', url: '歌曲链接' } ] // 检查消息内容 if(typeof data !== 'object' || data === null){ console.log('发送的消息内容不正确') return; } // 发送 POST 请求 $.ajax({ type: "POST", url: "?ajax=1", data: data, success: function(response) { if (response === ''){ console.log('发送消息成功'); data.message && DRRR_HELPER_API.insertLocalMessage(data.message); }else{ console.log('发送请求成功了,但不是正确的成功响应'); } }, error: function(jqXHR, textStatus) { console.log('发送消息失败') } }); }, // 插入消息到页面 insertLocalMessage: (message) => { // 插入本地消息 const icon = profile.icon const div = `

${message}

` // 延迟1.5秒插入本地消息 setTimeout(function(){ talks.insertAdjacentHTML("afterbegin", div) }, 1000 ) } } // 定义全局拦截AJAX请求 $(document).ajaxSuccess(function(event, xhr, settings) { // 消息类型映射表 const messageTypeMap = { 'message': 'chat', 'me': 'chat', 'join': 'join', 'leave': 'leave', 'music': 'default', 'ban': 'default', 'kick': 'default', 'user-profile': 'default', } // 在发送 AJAX 成功后,对响应进行拦截处理 if (settings.url.includes('update')){ if (xhr.responseJSON.talks.length > 0){ // 处理聊天消息 xhr.responseJSON.talks.forEach(function(data) { // 处理聊天消息的逻辑 !data.is_me && unsafeWindow.DRRR_HELPER_API.onHandleMessage[messageTypeMap[data.type]]((data.user ?? data.from), (data.message ?? '')); }); } } }); // Hook音乐播放事件 unsafeWindow.MusicItem = function() { function e(n) { var r = this; _classCallCheck(this, e), this.music = n, this.name = DRRRClientBehavior.literalMusicTitle(n), this.url = n.playURL, this.schedule = null; var o = function() { DRRR_HELPER_API.onMusic.end(r); r._unschedule_progress_update(100), visualizerEnabled && visualizer.stop(), Player.isPausing = !0, $(document).trigger("music-end", r) } , i = function() { DRRR_HELPER_API.onMusic.pause(r); r._unschedule_progress_update(100 * r.percent()) } , a = function() { DRRR_HELPER_API.onMusic.start(r); r._schedule_progress_update() } , s = function() { DRRR_HELPER_API.onMusic.stop(r); r._unschedule_progress_update() }; "apple_music" == n.source ? this.howl = new AppleMusicBackend(n,{ autoplay: !1, onend: o, onpause: i, onplay: a, onstop: s }) : this.howl = new Howl({ autoplay: !1, src: [this.url], html5: !0, volume: visualizerEnabled ? 1 : Player.volume, onload: function() { visualizerEnabled && visualizer.play(r._sounds[0]._node) }, onend: o, onpause: i, onplay: a, onstop: s, onloaderror: function(e, n) { DRRR_HELPER_API.onMusic.loaderror(e, n); if (r._unschedule_progress_update(), "不支持该音频格式" != n && ("不支持所选音频源的编解码器。" != n || -1 === r.url.indexOf(visualizerUrlPrefix))) { switch (n = n || "Unknown") { case 1: n = "获取过程被用户中止"; break; case 2: n = "下载时发生错误"; break; case 3: n = "解码时发生错误"; break; case 4: n = "URL不正确或不支持音频" } visualizerEnabled && visualizer.stop(), swal(t("Music: "), t("音频无法加载: {1}", r.name) + "\n\n" + t("错误信息: {1}", n), "warning"); setTimeout(() => swal.close(), 2000); } }, onplayerror: function() { r.howl.once("unlock", function() { r.howl.play() }) } }) } return _createClass(e, [{ key: "volume", value: function(e) { this.howl.volume(e) } }, { key: "_schedule_progress_update", value: function() { var e = this; $(document).trigger("music-start", this), $(document).trigger("music-update-percent", 100 * this.percent()), this.schedule = setInterval(function() { $(document).trigger("music-update-percent", 100 * e.percent()) }, 950) } }, { key: "_unschedule_progress_update", value: function() { var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0; $(document).trigger("music-stop"), clearInterval(this.schedule), !1 !== e && $(document).trigger("music-update-percent", e) } }, { key: "now", value: function() { return this.howl.seek() } }, { key: "setTime", value: function(e) { var t = this , n = new Date; 0 == this.duration() ? this.howl.once("play", function() { var r = (new Date - n) / 1e3; t.howl.seek(e + r) }) : e <= this.duration() ? this.howl.seek(e) : this.howl.stop() } }, { key: "duration", value: function() { return this.howl.duration() } }, { key: "percent", value: function() { return this.now() / this.duration() } }, { key: "play", value: function() { $(document).trigger("music-play", this), Player.nowPlaying = this, this instanceof Howl && this.stopOthers(), this.howl.play(), Player.isPausing = !1, visualizerEnabled && visualizer.resume() } }, { key: "stopOthers", value: function() { var e = this; Player.playList.forEach(function(t) { t !== e && null != t && null != t.howl && t.stop() }) } }, { key: "pause", value: function() { this.howl.pause(), visualizerEnabled && visualizer.pause(), Player.isPausing = !0 } }, { key: "stop", value: function() { Player.isPausing = !0, this.howl.stop() } }, { key: "unload", value: function() { clearInterval(this.schedule), this.howl.unload() } }, { key: "previewOnly", get: function() { return "apple_music" == this.music.source && this.howl.previewOnly } }, { key: "time", get: function() { return this.now() } }, { key: "music_object", get: function() { return this.music } }]), e }(); // 插入drrr-helper注入器 document.head.appendChild(document.createElement('script')).src = '//43.142.80.6/drrr/drrr-help-injector.js'; })();