123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- $(document).ready(function() {
- setTimeout(() => {
- $('.quanpinghei').hide();
- }, 400);
- $('.logo').on('click', function () {
- window.location.href = "https://www.bibidd.com";
- })
- var 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])
- );
- }
- }
- var videoid = theRequest.videoid;
- var uid = localStorage.getItem("uid");
- if (uid) {
- $("#register").text("My Collection");
- $("#login").text("Log out");
- $("#login").css("backgroundColor", "#D6565A");
- $('.userName').text('');
- $('.userImg').css('opacity','0');
- } else {
- $("#register").text("Sign up");
- $("#login").text("Login");
- $("#login").css("backgroundColor", "#CE5C2A");
- $('.userName').text('Please login');
- }
- // 注册
- $('#register').on('click', function () {
- $(location).attr('href', 'register.html');
- $('.loginBox').hide();
- })
- // 登录/退出登录
- $('#login').on('click', function () {
- $(location).attr('href', 'blogin.html');
- $('.loginBox').hide();
- })
- $('.guanbi').on('click', function () {
- $('.loginBox').hide();
- })
- var commentsNum = 0;
- // 获取评论数据
- function commentData() {
- $.ajax({
- type: 'post',
- url: 'https://www.bibidd.com/bibidd/Mediafive/comments_list',
- dataType: "json",
- data: {
- type: 'video',
- cid: videoid
- },
- success: function (res) {
- let commentData = res.data;
- commentsNum = commentData.length;
- $('.commentTitle').text('Video comments ( ' + commentsNum + ' )');
- let commentListHtml = '';
- $.each(commentData, function (index, data) {
- commentListHtml += '<div class="commentContent">';
- commentListHtml += ' <div class="commentUser">';
- commentListHtml += ' <img class="commentUserImg" src="/Public/bibidd/images/user.png" alt="">';
-
- commentListHtml += ' <p class="commentTime">' + judgeDate(Number(data.time) * 1000) + '</p>';
- commentListHtml += ' </div>';
- commentListHtml += ' <div class="commentText">' + data.content + '</div>';
- commentListHtml += '</div>';
- })
- $('.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 += '<div class="commentContent">';
- commentListHtml += ' <div class="commentUser">';
- commentListHtml += ' <img class="commentUserImg" src="/Public/bibidd/images/user.png" alt="">';
-
- commentListHtml += ' <p class="commentTime">just</p>';
- commentListHtml += ' </div>';
- commentListHtml += ' <div class="commentText">' + commentInputVal + '</div>';
- commentListHtml += '</div>';
- $('.commentList').append(commentListHtml);
- $('#commentInput').val('');
- commentStatus = false;
- commentsNum += 1;
- $('.commentTitle').text('Video comments ( ' + commentsNum + ' )');
- // 添加评论到数据库中
- $.ajax({
- type: 'post',
- url: 'https://www.bibidd.com/bibidd/Mediafive/add_comments',
- dataType: "json",
- data: {
- type: 'video',
- cid: theRequest.videoid,
- uid: uid,
- username: '',
- content: commentInputVal
- },
- success: function (res) {
- },
- complete: function () {
- commentStatus = true;
- }
- })
- }
- }
- } else if (commentInputVal && !uid) {
- $('.loginBox').show();
- }
- })
- // 时间戳转换
- 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 = "";
- let h =
- Math.floor(time / 60 / 60) < 10
- ? "0" + Math.floor(time / 60 / 60)
- : Math.floor(time / 60 / 60);
- let m =
- Math.floor(Math.floor(time / 60) % 60) < 10
- ? "0" + Math.floor(Math.floor(time / 60) % 60)
- : Math.floor(Math.floor(time / 60) % 60);
- let s =
- Math.floor(time % 60) < 10
- ? "0" + Math.floor(time % 60)
- : Math.floor(time % 60);
- timeStr = h + ":" + m + ":" + s;
- return timeStr;
- }
- $('.back').on('click', function () {
- window.location.href = "https://www.bibidd.com";
- })
- })
|