// ==UserScript== // @name bilibili notify // @namespace heroesm // @include http://live.bilibili.com/feed/getList/1 // @version 1.0.5.3 // @grant none // // @description 自动监听bilibili直播推送信息,当所关注者开启直播时自动打开直播网页的javascript脚本。 // @downloadURL none // ==/UserScript== function main(){ "use strict"; var sAltAPI = 'http://api.live.bilibili.com/ajax/feed/list?pagesize=30&page=1'; var running = true; var rProFilter, rConFilter; var rFilter = /./; var sMode = 'pro'; var aTimer = []; var aAltRoomid = []; var sTitle = ''; function prepare(){ Document.prototype.$ = Document.prototype.querySelector; Element.prototype.$ = Element.prototype.querySelector; Document.prototype.$$ = Document.prototype.querySelectorAll; Element.prototype.$$ = Element.prototype.querySelectorAll; } function start(){ var timer = setTimeout(function(){ window.location.reload(); }, 30000); aTimer.push(timer); document.$('#pause').style.display = 'unset'; document.$('#start').style.display = 'none'; document.title = sTitle; return timer; } function stop(){ var nTimer = aTimer.pop(); while (nTimer){ clearTimeout(nTimer); nTimer = aTimer.pop(); } document.$('#pause').style.display = 'none'; document.$('#start').style.display = 'unset'; sTitle = document.title; document.title = '已暂停'; } function update(){ try{ var sCon = document.$('#con').value.trim(); localStorage.bilinotify_con = sCon; rConFilter = new RegExp(sCon); var sPro = document.$('#pro').value.trim(); localStorage.bilinotify_pro = sPro; rProFilter = new RegExp(sPro); } catch(e){console.log(e);} localStorage.bilinotify_mod = sMode = document.$('input[name=mode]:checked').value; if (sMode == 'pro'){ rFilter = rProFilter; } else{ rFilter = rConFilter; } } function checkopen(item){ var con = Boolean(sMode == 'con'); if(con ^ rFilter.test(item.nickname)){ window.open(item.link + '###', item.nickname); } } function build(){ var style = document.createElement('style'); style.id = 'bilinotify_css'; style.innerHTML = [ 'input[type=text] {width: 50%;}' ].join('\n'); document.head.appendChild(style); document.body.insertAdjacentHTML( 'beforeend', [ '
', ' ', ' 使用该正则表达式按昵称进行排除:', '', '
', '
', ' ', ' 使用该正则表达式按昵称进行匹配:', ' ', '
', '
', ' ', ' ', ' ', '
' ].join('\n') ); if (localStorage.bilinotify_con){ document.$('#con').value = localStorage.bilinotify_con; } if (localStorage.bilinotify_pro){ document.$('#pro').value = localStorage.bilinotify_pro; } if (localStorage.bilinotify_mod){ document.$('input[type=radio][value=' + localStorage.bilinotify_mod + ']').checked = true; } update(); document.$('#confirm').onclick = update; document.$('#start').onclick = start; document.$('#pause').onclick = stop; } function run(){ try{ prepare(); }catch(e){} var Obj = JSON.parse(document.body.childNodes[0].textContent.slice(1,-2)); build(); var Data = Obj.data; if(Obj.code == -101){ document.body.insertAdjacentHTML('beforeend', '

未登录'); document.title = '未登录'; } else if(Data.count>0) { document.title = "(!)有" + Data.count + "个直播"; for(var x=0, item, sHTML; x', '
', '
', ' ', '
', ' ${item.nickname}', '
', ' ${item.roomname}', '
', '
' ].join('\n').replace(/\$\{([^\}]+)\}/g, function(sMatch, sP1){ return eval(sP1); })); document.body.insertAdjacentHTML( 'beforeend', sHTML ); checkopen(item); } } else{ document.body.insertAdjacentHTML('beforeend', '

无直播'); document.title = "无直播"; } sTitle = document.title; start(); console.log('ended'); } function handleAltList(sRes){ var div = document.createElement('div'); div.textContent = sRes; document.body.appendChild(div); var Obj = JSON.parse(sRes.slice(1,-2)); if (Obj.code == 0){ var aRooms = Obj.data.list; aRooms || (aRooms = []); for (var i=0; i