$(document).ready(function () {
$('.logo').on('click', function () {
window.location.href = "https://www.bibidd.com";
})
$('.quanpinghei').hide();
$('.back').on('click', function () {
history.back(-1);
})
let url = window.location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(
decodeURIComponent(strs[i].split("=")[1])
);
}
}
console.log(theRequest);
$('.videoName').text(theRequest.videoname);
var username = localStorage.getItem('username');
var uid = localStorage.getItem("uid");
if (uid) {
$("#register").text("My Collection");
$("#login").text("Log out");
$("#login").css("backgroundColor", "#D6565A");
} else {
$("#register").text("Sign up");
$("#login").text("Login");
$("#login").css("backgroundColor", "#CE5C2A");
}
// 获取视频id
var videoid = theRequest.videoid;
// 获取点赞数量
var fabulous = theRequest.fabulous;
$('.fabulous').find("p").eq(0).text(fabulous);
// 获取视频数据
function getData() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/video_detail',
dataType: "json",
data: {
video_id: videoid
},
success: function (res) {
},
complete: function (res) {
let videoSrc = res.responseJSON.data;
$('iframe').attr('src', videoSrc);
}
})
}
// 调用 获取视频数据 接口
getData();
// 判断该视频是否被收藏
var collectionStatus;
function collectionData() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/yn_shoucang',
dataType: "json",
data: {
type: 'video',
cid: videoid,
uid: uid
},
success: function (res) {
},
complete: function (res) {
let collectionData = res.responseJSON.message;
if (collectionData === 'ok') {
// 已经被收藏
$('.collection img').attr('src', '/Public/bibidd/images/xingsel.png');
$('.collection').find("p").eq(0).text('Favorite');
collectionStatus = true;
} else {
$('.collection img').attr('src', '/Public/bibidd/images/xing.png');
$('.collection').find("p").eq(0).text('Not collected');
collectionStatus = false;
}
}
})
}
if (uid) {
collectionData();
$('.userName').text(username);
} else {
$('.collection').find("p").eq(0).text('Not collected');
$('.userName').text('Please login');
}
// 获取评论数据
function commentData() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/comments_list',
dataType: "json",
data: {
type: 'video',
cid: videoid
},
success: function (res) {
},
complete: function (res) {
let commentData = res.responseJSON.data;
let commentListHtml = '';
$.each(commentData, function (index, data) {
commentListHtml += '
';
})
$('.commentList').html(commentListHtml);
}
})
}
commentData();
// 评论
var commentStatus = true;
$('.sendBtn').on('click', function () {
let commentInputVal = $('#commentInput').val();
if (uid) {
if (commentInputVal && uid) {
if (commentStatus) {
// 添加评论内容
let commentListHtml = '';
commentListHtml += '';
$('.commentList').append(commentListHtml);
$('#commentInput').val('');
commentStatus = false;
// 添加评论到数据库中
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/add_comments',
dataType: "json",
data: {
type: 'video',
cid: theRequest.videoid,
uid: uid,
username: username,
content: commentInputVal
},
success: function (res) {
},
complete: function () {
commentStatus = true;
}
})
}
}
} else if (commentInputVal && !uid) {
$('.loginBox').show();
}
})
// 点赞
var fabulousStatus = true;
$('.fabulous').on('click', function () {
$('.fabulous img').attr('src', '/Public/bibidd/images/loading.gif');
setTimeout(() => {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/dianzan_img_video',
dataType: "json",
data: {
type: 'video',
cid: videoid,
uid: uid
},
success: function (res) {
let fabulous = $('.fabulous').find("p").eq(0).text();
$('.fabulous').find("p").eq(0).text(Number(fabulous) + 1);
$('.fabulous img').attr('src', '/Public/bibidd/images/zan.png');
}
})
}, 2000);
})
var collectionChange = false;
// 收藏
$('.collection').on('click', function () {
if (uid) {
if (collectionStatus) {
$('.collection img').attr('src', '/Public/bibidd/images/xing.png');
$('.collection').find("p").eq(0).text('Not collected');
collectionclose();
} else {
$('.collection img').attr('src', '/Public/bibidd/images/xingsel.png');
$('.collection').find("p").eq(0).text('Favorite');
collectionAdd();
}
} else {
// 弹窗提示去登录
$('.loginBox').show();
}
})
$('.guanbi').on('click', function () {
$('.loginBox').hide();
})
// 查看我的收藏
$('#register').on('click', function () {
if ($(this).text() === 'My Collection') {
$(location).attr('href', 'collection.html?status=' + 1);
} else {
// 注册
$(location).attr('href', 'register.html?status=' + 1);
}
$('.loginBox').hide();
})
// 登录/退出登录
$('#login').on('click', function () {
if ($(this).text() === 'Log out') {
// 退出登录
localStorage.removeItem('uid');
location.reload();
} else {
// 登录
$(location).attr('href', 'login.html?status=' + 1);
}
$('.loginBox').hide();
})
// 添加收藏
function collectionAdd() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/add_to_shoucang',
dataType: "json",
data: {
type: 'video',
cid: videoid,
uid: uid
},
success: function (res) {
},
complete: function (res) {
let collectionData = res.responseJSON.message;
if (collectionData === 'ok') {
// 已经被收藏
$('.collection img').attr('src', '/Public/bibidd/images/xingsel.png');
$('.collection').find("p").eq(0).text('Favorite');
collectionStatus = true;
} else {
$('.collection img').attr('src', '/Public/bibidd/images/xing.png');
$('.collection').find("p").eq(0).text('Not collected');
collectionStatus = false;
tip('Please try again later');
}
}
})
}
// 取消收藏
function collectionclose() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/quxiao_shoucang',
dataType: "json",
data: {
type: 'video',
cid: videoid,
uid: uid
},
success: function (res) {
},
complete: function (res) {
let collectionData = res.responseJSON.message;
if (collectionData === 'ok') {
// 已经取消收藏
$('.collection img').attr('src', '/Public/bibidd/images/xing.png');
$('.collection').find("p").eq(0).text('Not collected');
collectionStatus = false;
} else {
$('.collection img').attr('src', '/Public/bibidd/images/xingsel.png');
$('.collection').find("p").eq(0).text('Favorite');
$('.collection').find("p").eq(0).text('Favorite');
collectionStatus = true;
tip('Please try again later');
}
}
})
}
// 获取推荐视频
function getTuiJianVideoData() {
$.ajax({
type: 'post',
url: 'https://www.bibidd.com/bibidd/Media/tuijian_shipin',
dataType: "json",
data: {
cid: videoid,
},
success: function (res) {
},
complete: function (res) {
let dataArray = res.responseJSON.data;
let videoHtml = '';
$.each(dataArray, function (index, data) {
videoHtml += '';
videoHtml +=
'
';
videoHtml += '
';
videoHtml += '
' + data.title + "
";
videoHtml += '
' + videoTime(data.time_chuo) + '
';
videoHtml += '
';
videoHtml += "
";
})
$('.video').html(videoHtml);
var loadingUrl = "/Public/bibidd/images/loading.png";
$(".lazy").lazyload({
effect: 'show',
placeholder: loadingUrl,
failurelimit: 10,
skip_invisible: false,
});
// 查看视频详情
$(".videoContent").on("click", function () {
let looks = $(this).find("#looks").eq(0).text();
$(this).find("#looks").eq(0).text(Number(looks) + 1);
$(location).attr("href", "videodetails.html?videoid=" + dataArray[$(this).index()].id + "&fabulous=" + dataArray[$(this).index()].thumbs_up + "&favorite=" + dataArray[$(this).index()].favorite + '?status=' + 1);
});
}
})
}
getTuiJianVideoData();
// 时间戳转换
function formatDateTime(inputTime) {
var timeStr;
var date = new Date(inputTime);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? "0" + m : m;
var d = date.getDate();
d = d < 10 ? "0" + d : d;
var h = date.getHours();
h = h < 10 ? "0" + h : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? "0" + minute : minute;
second = second < 10 ? "0" + second : second;
let date1 = new Date(inputTime).getTime(); //开始时间
let date2 = new Date().getTime(); //结束时间
let date3 = Math.floor(date2 - date1);
//计算出相差天数
let days = Math.floor(date3 / (24 * 3600 * 1000));
//计算出小时数
let leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
let hours = Math.floor(leave1 / (3600 * 1000));
//计算相差分钟数
let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
let minutes = Math.floor(leave2 / (60 * 1000));
//计算相差秒数
let leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
let seconds = Math.round(leave3 / 1000);
if (days === 0 && hours === 0 && minutes <= 5) {
// 超过一分钟的显示具体时间,精确到分钟,如:15分钟前。
// timeStr = minutes < 10 ? "0" + minutes + '分钟前' : minutes + '分钟前';
timeStr = "just";
} else if (days === 0 && hours < 1 && minutes >= 5) {
// 超过一分钟的显示具体时间,精确到分钟,如:15分钟前。
// timeStr = hours < 10 ? "0" + hours + '小时前' : hours + '小时前';
timeStr = "Within 1 hour";
} else if (days === 0 && hours < 24 && hours >= 1) {
// 超过一分钟的显示具体时间,精确到分钟,如:15分钟前。
// timeStr = hours < 10 ? "0" + hours + '小时前' : hours + '小时前';
timeStr = h + ":" + minute;
}
return timeStr;
}
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
function judgeDate(timestamp) { // 判断是否是今天还是昨天,在项目中用于说说时的时间显示
//昨天的时间
var day1 = new Date();
day1.setDate(day1.getDate() - 1);
var yesterday = day1.format("yyyy-MM-dd");
//今天的时间
var day2 = new Date();
day2.setTime(day2.getTime());
var today = day2.format("yyyy-MM-dd");
if (timestamp) {
var date = new Date(timestamp);
} else {
var date = new Date();
}
Y = date.getFullYear(),
m = date.getMonth() + 1,
d = date.getDate(),
H = date.getHours(),
i = date.getMinutes();
if (m < 10) {
m = '0' + m;
}
if (d < 10) {
d = '0' + d;
}
if (H < 10) {
H = '0' + H;
}
if (i < 10) {
i = '0' + i;
}
var t = Y + '-' + m + '-' + d + ' ' + H + ':' + i;
if (t.split(" ")[0] == today) {
// return "今天"+t.split(" ")[1];
return formatDateTime(timestamp);
return H + ':' + i;
} else if (t.split(" ")[0] == yesterday) {
return "yesterday ";
} else {
return m + '-' + d;
}
}
function tip(text) {
$('#tip').show();
$('.tiptext').text(text);
setTimeout(() => {
$('#tip').hide();
}, 1000);
}
function videoTime(time) {
let timeStr = '';
timeStr = Math.floor(time / 60 / 60) + ':' + Math.floor(time / 60) % 60 + ':' + time % 60
return timeStr
}
})
' + data.username + '
'; commentListHtml += '' + judgeDate(Number(data.time) * 1000) + '
'; commentListHtml += '