Skip to content

Instantly share code, notes, and snippets.

@matin0728
Created April 27, 2017 10:08
Show Gist options
  • Save matin0728/386a4ca4bd263579554aa14d2dcf9ab0 to your computer and use it in GitHub Desktop.
Save matin0728/386a4ca4bd263579554aa14d2dcf9ab0 to your computer and use it in GitHub Desktop.
$('.video-link').each(function(index, link){
if ($(link).data("lens-id")) {
var v = $(link)
var img = v.data("poster"); // thumbnail.
var title = v.data("name");
v.addClass("video-box").addClass("own-video").addClass('loading').html(['<div class="loading"></div><div class="content"><span class="title">', title, '</span></div>'].join(''));
}
});
var testing = true; //是不是测试.
var timer = 15;
var testCounter = 0;
function updateVideoInfo(videoInfo) {
console.log('start tESTING!!')
//将 videoId 符合的 videoBox 更新状态
$('.video-link').each(function () {
var ownVideo = $(this);
//TODO: Update the video link state.
//Test
if (testing) {
//正常
if (testCounter % 3 == 0) {
ownVideo.find('.loading').css('background', ['url(\'', ownVideo.data('poster') , '\') no-repeat 50% 50%;background-size:100% 100%;overflow:hidden;'].join('')).html('<div class="wrap"><div class="normal"></div></div>')
} else if (testCounter % 3 == 1) {
//loading
ownVideo.find('.loading').css('background', '').html('<div class="wrap"><div class="loader"></div>视频上传中</div>')
} else if (testCounter % 3 == 2) {
//fail.
ownVideo.find('.loading').css('background', '').html('<div class="wrap"><span class="fail">视频上传失败</span></div>')
}
testCounter++;
}
});
if (testing) {
setTimeout(updateVideoInfo, 3000) //3秒更新一次状态.
}
}
window.updateVideoInfo = updateVideoInfo;
if (testing) {
window.updateVideoInfo()
}
function updateLoadingState() {
//get all own video ids.
var ids = [];
$('.video-link').each(function(index, link) {
if ($(link).data("lens-id")) {
ids.push($(link).data("lens-id"))
}
$.ajax({
type: "GET",
async: true,
url: "https://lens.zhihu.com/api/videos/" + ids.join(','),
dataType: "json",
headers: null/*header*/,
crossDomain: true,
success: updateVideoInfo,
error: function () {
alert('fail');
}
});
});
setTimeout(updateLoadingState, timer);//update every 15 seconds.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment