Last active
October 3, 2018 09:14
-
-
Save bigshans/df122d675f6592b1a99266f1f68efcd0 to your computer and use it in GitHub Desktop.
bilibili_season_update.user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name bilibili 首页番剧更新 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2.0 | |
// @description try to take over the world! | |
// @author Bigshans | |
// @match https://www.bilibili.com/ | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getCookie(name){ | |
var strcookie = document.cookie;//获取cookie字符串 | |
var arrcookie = strcookie.split("; ");//分割 | |
//遍历匹配 | |
for ( var i = 0; i < arrcookie.length; i++) { | |
var arr = arrcookie[i].split("="); | |
if (arr[0] == name){ | |
return arr[1]; | |
} | |
} | |
return ""; | |
} | |
function req() { | |
return GM_xmlhttpRequest({ | |
method:"GET", | |
headers:{"Accept": "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, image/apng, */*;q=0.8"}, | |
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid='+getCookie('DedeUserID')+'&type=512&rsp_type=1¤t_dynamic_id=170304923692235433', | |
onload : function(response) { | |
var json = response.responseText; | |
var array = JSON.parse(json); | |
var nums = array['data']['new_num'] + array['data']['update_num']; | |
console.log(json); | |
function go(nums){ | |
var Obj=document.querySelector("[report-id=playpage_dynamic]"); | |
if (Obj) { | |
var node = document.getElementById('seasonList'); | |
if (node) { | |
if (node.getElementById('num')) { | |
if (parseInt($('#num').innerText) < nums) { | |
$('num').innerText = nums; | |
} | |
} else { | |
if (nums !== 0) { | |
$('#sub-a').innerHTML = "番剧 <div id='num' class='num'>"+nums+"</div> "; | |
} | |
} | |
} else { | |
if (nums === 0) { | |
$("<li report-id='nop' class='nav-item' id='seasonList'><a class='t' href='https://t.bilibili.com/?tab=512' id='sub-a' target='view_window'> 番剧 <!--<div class='num'>1</div>--> </a> </li>").insertAfter(Obj); | |
} else { | |
$("<li report-id='nop' class='nav-item' id='seasonList'><a class='t' href='https://t.bilibili.com/?tab=512' id='sub-a' target='view_window'> 番剧 <div id='num' class='num'>"+nums+"</div> </a> </li>").insertAfter(Obj); | |
} | |
} | |
$("#seasonList").hover(function() { | |
if (document.getElementById('num')) { | |
$('#num').remove(); | |
$('#listShow').remove(); | |
} | |
if (document.getElementById('listShow')) { | |
$('#listShow').show(); | |
return; | |
} | |
append(); | |
}, function(){ | |
$('#listShow').hide(); | |
}); | |
} else { | |
setTimeout(_go(), 500); | |
}} | |
function _go() { | |
return go(nums); | |
} | |
go(nums); | |
setTimeout(req(), 5000); | |
} | |
}) | |
} | |
function append() { | |
GM_xmlhttpRequest({ | |
method:"GET", | |
headers:{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, | |
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid='+getCookie('DedeUserID')+'&type=512', | |
onload : function (response) { | |
// console.log(response.responseText); | |
var json = response.responseText; | |
var list = JSON.parse(json); | |
var cards = list['data']['cards'].slice(0,6); | |
var len = cards.length; | |
var node = ""; | |
for(let i = 0; i < len; ++i) { | |
var card = JSON.parse(cards[i]['card']); | |
// console.log( card); | |
node += '<li> <a target="view_window" href="'+card['url'] + '" >【' + | |
card['apiSeasonInfo']['title'] + ' ' + card['index'] + '】 ' | |
+ card['index_title'] + '</a></li>' | |
} | |
node = '<div class="favorities-m mini-wnd-nav favorite-wnd dd-bubble" id="listShow" display="none">' + | |
'<ul class="list history">' + '<div>' + node + '</div></ul>' + '<div><a href="https://t.bilibili.com/?tab=512" target="view_window" class="read-more">查看更多<i class="b-icon b-icon-arrow-r"></i></div></div>' | |
$(node).insertAfter($('#sub-a')); | |
} | |
}) | |
} | |
setTimeout(req(), 500); | |
// GM_xmlhttpRequest({ | |
// method:"GET", | |
// headers:{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, | |
// url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid='+getCookie('DedeUserID')+'&type=512', | |
// onload : function (response) { | |
// // console.log(response.responseText); | |
// var json = response.responseText; | |
// var list = JSON.parse(json); | |
// var card = list['data']['cards']; | |
// setTimeout(_go(),500); | |
// function go(list){ | |
// var Obj=document.querySelector("[report-id=playpage_dynamic]"); | |
// if(Obj){ | |
// $("<li report-id='nop' class='nav-item' id='seasonList'><a class='t' href='https://t.bilibili.com/?tab=512' id='sub-a' target='view_window'> 番剧 <!--<div class='num'>1</div>--> </a> </li>").insertAfter(Obj); | |
// var node = ''; | |
// $('#seasonList').hover(function(){ | |
// if (document.getElementById('listShow')) { | |
// $('#listShow').show(); | |
// return; | |
// } else { | |
// var len = list.length; | |
// for(let i = 0; i < len; ++i) { | |
// var card = JSON.parse(list[i]['card']); | |
// // console.log( card); | |
// node += '<li> <a target="view_window" href="'+card['url'] + '" >【' + | |
// card['apiSeasonInfo']['title'] + ' ' + card['index'] + '】 ' | |
// + card['index_title'] + '</a></li>' | |
// } | |
// node = '<div class="favorities-m mini-wnd-nav favorite-wnd dd-bubble" id="listShow" display="none">' + | |
// '<ul class="list history">' + '<div>' + node + '</div></ul>' + '<div><a href="https://t.bilibili.com/?tab=512" target="view_window" class="read-more">查看更多<i class="b-icon b-icon-arrow-r"></i></div></div>' | |
// $(node).insertAfter($('#sub-a')); | |
// console.log('add it');}}, | |
// function(){ | |
// $('#listShow').hide(); | |
// }) | |
// }else{setTimeout(_go(),500);} | |
// } | |
// function _go() { | |
// return go(card.slice(0,6)); | |
// } | |
// } | |
// }) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment