Last active
September 25, 2019 18:39
-
-
Save g8up/5a4a2a50475ae3a972dd7ee068993b00 to your computer and use it in GitHub Desktop.
让直播房间页面按访问量降序排列(目前支持斗鱼、熊猫、战旗)
This file contains hidden or 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
javascript: void ((function () { | |
/* | |
* 直播房间排序 V2.1.1 | |
* 功能:让直播房间页面按访问量降序排列(目前支持斗鱼、熊猫、战旗) | |
* 需要[制作成 Chrome 书签](http://pan.baidu.com/s/1skgEosX) | |
* 更新时间:2019年9月26日02:38:23,修复斗鱼平台 | |
*/ | |
function Sortor($container, getPeopleNumFn) { | |
this.$container = $container; | |
this.rooms = $container.find('li'); | |
this.getPeopleNumFn = getPeopleNumFn; | |
this.run(); | |
} | |
Object.assign(Sortor.prototype, { | |
run: function () { | |
this.sort(); | |
this.append(); | |
this.shining(); | |
}, | |
sort: function () { | |
var gn = this.getPeopleNumFn; | |
return [].sort.call(this.rooms, function (room1, room2) { | |
return gn(room2) - gn(room1); /* 按从大到小对 roomView 里的数字进行排序*/ | |
}); | |
}, | |
append: function () { | |
this.$container.html(this.rooms); | |
}, | |
shining: function () { | |
this.$container.css({ | |
opacity: 0 | |
}).animate({ | |
opacity: 1 | |
}); | |
} | |
}); | |
function formatNum(numStr) { | |
if (numStr.indexOf('万') > -1) { | |
num = numStr.replace('万', ''); | |
num = parseInt(num, 10) * 10000; | |
return num; | |
} | |
else { | |
return parseInt(numStr, 10); | |
} | |
} | |
/** | |
* 插入 jQuery lib | |
*/ | |
(function (src, callbackFn) { | |
if (!window.jQuery) { | |
var script = document.createElement('script'); | |
script.src = src; | |
script.setAttribute('data-info', '我的插入'); | |
script.onload = function () { | |
console.info('jQuery has been injected.'); | |
callbackFn && callbackFn(); | |
} | |
; | |
document.head.appendChild(script); | |
} | |
else { | |
callbackFn && callbackFn(); | |
} | |
})("//libs.baidu.com/jquery/2.0.0/jquery.min.js", function () { | |
var host = location.host; | |
if (host.indexOf('douyu') > -1) { | |
var $cont = $('#listAll').find('ul'); | |
new Sortor($cont, function (room) { | |
var view = $(room).find('.DyListCover-hot'); | |
var num = view.text(); | |
return formatNum(num); | |
}); | |
} | |
else if (host.indexOf('panda') > -1) { | |
var $cont = $('.video-list'); | |
new Sortor($cont, function (room) { | |
return Number($(room).find('.video-number').text()); | |
}); | |
} | |
else if (host.indexOf('zhanqi') > -1) { | |
var $cont = $('.live-list-tabc.active>.js-room-list-ul'); | |
new Sortor($cont, function (room) { | |
var num = $(room).find('.views>span.dv').text(); | |
return formatNum(num); | |
}); | |
} | |
}); | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment