// ==UserScript== // @name AcFun - 我的关注直播间 // @namespace http://tampermonkey.net/ // @version 1.1.0 // @description 修改uid: 0.0伪用户的直播间页面样式,只展示所关注的直播间列表 // @author dareomaewa // @match https://live.acfun.cn/live/0.0 // @icon https://www.google.com/s2/favicons?sz=64&domain=acfun.cn // @grant none // @require https://cdn.staticfile.org/jquery/3.5.0/jquery.min.js // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const config = { maxLiveSize: 1001, love: { // true: 打开love样式 false: 关闭 open: true, // 添加love UP主的uid,使用逗号分隔“,”,例如:[123,456,] ups: [], }, egg: { // 彩蛋开关 true: 打开 false: 关闭 open: true, type: 0, upsInfo: { 416752: { uid: 416752, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_30a99a69987d4995b43df39320491711.jpg', ], }, 36626547: { uid: 36626547, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_3151ca8705334d88ba6cdc4834573ec1.jpg', ], }, 23682490: { uid: 23682490, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_b8fbdbdd47be447895464b5555225679.jpg', ], }, 1345673: { uid: 1345673, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_5d8820b3b8ca42d38f17240c48102752.jpg', ], }, 179922: { uid: 179922, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_75e7e36b3e6445baa02f1c8618b4359c.jpg', ], }, 30561040: { uid: 30561040, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_61f0f008b94c4d579f789c06e5d2ee4f.jpg', ], }, 40740702: { uid: 40740702, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_25a67815bb984f5ea853395af9c8c237.jpg', ], }, 12553939: { uid: 12553939, coverUrls: [ 'https://imgs.aixifan.com/newUpload/776907_b8ac4f947626494cbb96356794d39e3c.jpg', ], }, }, }, }; function StringBuffer() { this.__strings__ = []; }; StringBuffer.prototype.Append = function (str) { this.__strings__.push(str); return this; }; StringBuffer.prototype.ToString = function () { return this.__strings__.join(''); }; function createLiveListItemHtmlStr(data) { var htmlStr = new StringBuffer(); htmlStr.Append('
'); htmlStr.Append(' '); htmlStr.Append('
'); htmlStr.Append(' '); htmlStr.Append('
'); htmlStr.Append(' '); htmlStr.Append('
'); htmlStr.Append(' ' + data.likeCount+ ''); htmlStr.Append(''); htmlStr.Append(' ' + data.onlineCount+ ''); htmlStr.Append(''); htmlStr.Append('
'); if (config.egg.open && Object.keys(config.egg.upsInfo).some(e => e === data.user.id)) { const eggCoverUrl = config.egg.upsInfo[data.user.id].coverUrls[config.egg.type]; htmlStr.Append('
'); htmlStr.Append(' '); htmlStr.Append(' '); htmlStr.Append('
'); htmlStr.Append('
'); return htmlStr.ToString(); } function waitElement(selector, times, interval, flag=true){ var _times = times || -1, _interval = interval || 1, _selector = selector, _iIntervalID, _flag = flag; return new Promise(function(resolve, reject){ _iIntervalID = setInterval(function() { if(!_times) { clearInterval(_iIntervalID); reject(); } _times <= 0 || _times--; var _self = $(_selector); if( (_flag && _self.length) || (!_flag && !_self.length) ) { clearInterval(_iIntervalID); resolve(_iIntervalID); } }, _interval); }); } function addChild(fatherNode, childNode, innerHtmlStr, type) { childNode.innerHTML = innerHtmlStr; if (type) { fatherNode.appendChild(childNode); }else { fatherNode.appendChild(childNode.childNodes[0]); } } function addChildDiv(fatherNode, innerHtmlStr) { addChild(fatherNode, document.createElement("div"), innerHtmlStr); } function addChildScript(fatherNode, scriptStr) { addChild(fatherNode, document.createElement("script"), scriptStr, 'script'); } function addChildStyle(fatherNode, styleStr) { addChild(fatherNode, document.createElement("style"), styleStr, 'style'); } function initLiveContainer(liveContainerSelector, liveList) { waitElement(liveContainerSelector).then(function() { var othersLiveContainer = document.querySelector(liveContainerSelector); //console.log(liveList); liveList.forEach(data => { addChildDiv(othersLiveContainer, createLiveListItemHtmlStr(data)); }); }); } function replaceText(selector, newText) { waitElement(selector).then(function() {document.querySelector(selector).innerText = newText;}); } function removeNode(selector) { waitElement(selector).then(function() {document.querySelector(selector).remove();}); } function confirmMoreLive(selector) { const msg = '确定跳转AC直播大屏幕吗?你将可能进入未曾关注过的直播间。'; waitElement(selector).then(function() { const moreLiveNodes = document.querySelectorAll(selector); moreLiveNodes.forEach(node => { node.setAttribute('href', 'javascript:if(confirm("' + msg + '")) window.open("/");'); node.removeAttribute('target'); }); }); } replaceText('title', '我的关注直播间'); //replaceText('.recmd-live-title', '我的关注直播间'); removeNode('.player-outer-wrapper'); removeNode('.recmd-live-container'); confirmMoreLive('.more-live'); confirmMoreLive('.live-page-title'); confirmMoreLive('a[href="/"].live'); $.ajax({ url: '/api/channel/list?count=' + config.maxLiveSize + '&pcursor=&filters=[%7B%22filterType%22:3,+%22filterId%22:0%7D]', type: 'get', success: function (res) { //console.log(res); const liveList = res.liveList; replaceText('.recmd-live-title', '我的关注直播间 (' + liveList.length + ')'); let loveUps = config.love.ups; waitElement('.recommend-live-wrapper').then(function() { const recommendLiveWrapperNode =document.querySelector('.recommend-live-wrapper'); addChildDiv(recommendLiveWrapperNode, '
'); addChildDiv(recommendLiveWrapperNode, '
'); }); waitElement('head').then(function() { const headNode = document.querySelector('head'); addChildStyle(headNode, '.live-check-cover {color: #fff;position: absolute;right: 4px;bottom: 5px;border-radius: 3px;text-align: center;width: auto;height: 19px;z-index: 996;} .live-check-cover-desc {font-size: 12px;line-height: 17px;height: 18px;display: inline-block;vertical-align: top;width: 58px;}'); if (config.love.open) { addChildStyle(headNode, '#loveLiveContainer .live-list-item .list-content-top .list-content-data {background: linear-gradient(180deg,transparent,rgb(254 129 141 / 83%));} .list-container {min-height: 500px;}'); } if (config.egg.open) { addChildScript(headNode, 'function danmakuMaskTrigger(selector0, selector1){document.querySelector(selector0).setAttribute("style", "display: block;");document.querySelector(selector1).setAttribute("style", "display: none;");}'); } }); if (!config.love.open || loveUps.length ===0) { initLiveContainer('#othersLiveContainer', liveList); }else { const loveLiveList = liveList.filter((e) => loveUps.some((uid) => uid === e.authorId)); initLiveContainer('#loveLiveContainer', loveLiveList); const othersLiveList = liveList.filter((e) => !loveUps.some((uid) => uid === e.authorId)); initLiveContainer('#othersLiveContainer', othersLiveList); } } }); window.aikaCut = function aikaCut() { event.preventDefault(); $.ajax({ url: 'https://id.app.acfun.cn/rest/web/token/get', type: 'post', data: {'sid': 'acfun.midground.api'}, xhrFields: { withCredentials: true }, success: function (res) { //console.log(res); const aikaText = document.getElementById('aika-text'); const aikaCut = document.getElementById('aika-cut'); const aikaTestValue = aikaText.value.trim(); if (/https:\/\/onvideo.kuaishou.com\/vangogh\/editor\/(\d+)\?source=ac/g.test(aikaTestValue)) { aikaCut.href = 'https://onvideoapi.kuaishou.com/rest/infra/sts?sid=acfun.midground.api&authToken=' + res['acfun.midground.api.at'] + '&followUrl=' + encodeURI(aikaTestValue); } else if (/^\d+$/.test(aikaTestValue)) { aikaCut.href = 'https://onvideoapi.kuaishou.com/rest/infra/sts?sid=acfun.midground.api&authToken=' + res['acfun.midground.api.at'] + '&followUrl=' + encodeURI('https://onvideo.kuaishou.com/vangogh/editor/' + aikaTestValue + '?source=ac'); } else { aikaCut.href = '#'; } console.log(aikaCut.href); const aikaA = document.createElement('a'); aikaA.href = aikaCut.href; aikaA.target = '_blank'; aikaA.click(); aikaA.remove(); } }); } const aikaTextHtmlStr = `
`; const aikaBtnHtmlStr = `
直播剪辑
`; waitElement('.list-right').then(function() { const listRightNode = document.querySelector('.list-right'); addChild(listRightNode, document.createElement("div"), aikaTextHtmlStr, 'div'); addChild(listRightNode, document.createElement("div"), aikaBtnHtmlStr, 'div'); }); })();