$(function () {
var Util = {}
Util.alert = function (params) {
var confirmButtonText = params.confirmButtonText ? params.confirmButtonText : '确定'
var $mask = $('#mask')
var dialog = $(
'
'
)
if ($mask.length) {
$('#mask').show()
$('body').append(dialog)
} else {
var mask = $('')
$('body').append(mask)
$('body').append(dialog)
$('#mask').show()
}
$('.alert-close').on('click', function () {
params.hideMask = params.hideMask == undefined ? true : params.hideMask
if (params.hideMask) {
$('#mask').hide()
}
$('.alert').remove()
typeof params.onOk === 'function' && params.onOk()
})
}
// 确认
Util.confirm = function (params) {
var cancelButtonText = params.cancelButtonText ? params.cancelButtonText : '取消'
var confirmButtonText = params.confirmButtonText ? params.confirmButtonText : '确定'
var $mask = $('#mask')
var confirm = $(
''
)
if ($mask.length) {
$('#mask').show()
$('body').append(confirm)
} else {
var mask = $('')
$('body').append(mask)
$('body').append(confirm)
}
$('.confirm-close').on('click', function () {
$('#mask').hide()
$('.confirm').hide()
if (typeof params.onClose === 'function') {
params.onClose()
} else {
$('#mask').hide()
}
})
$('.confirm-ok').on('click', function () {
$('#mask').hide()
$('.confirm').hide()
typeof params.onOk === 'function' && params.onOk()
})
}
// var mySwiper = new Swiper('.swiper-container', {
// effect: 'fade',
// autoplay: {
// delay: 5000,
// disableOnInteraction: false
// },
// loop: true,
// pagination: {
// el: '.swiper-pagination',
// clickable: true
// },
// navigation: {
// nextEl: '.swiper-button-next',
// prevEl: '.swiper-button-prev'
// },
// lazy: {
// loadPrevNext: true
// }
// })
// 处理 webp 图片
var $img = $('img')
$img.on('error', function () {
var $src = $(this).attr('src')
if ($src.indexOf('webp') > -1) {
$(this).attr('src', $src.split('?')[0])
}
})
// 文章页轮播图
var swiper_single = new Swiper('.swiper-single', {
loop: true,
autoplay: {
delay: 5000,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
},
lazy: {
loadPrevNext: true
}
})
var postId = ''
$('.down').on('click', function () {
postId = $(this).data('id') || $('body').data('id')
$('#mask').show()
$('.down-box').show()
console.log('_czc', _czc)
_czc.push(['_trackEvent', '下载', '显示下载框', postId])
})
// $('#mask').on('click', function () {
// $(this).hide();
// $('.down-box').hide();
// });
var pageUrl = window.location.href
var originalUrl = pageUrl.split('#')[0]
var anchor = pageUrl.split('#')[1]
var postFlag = false
if (anchor == 'login') {
postId = $('.down').data('id')
$('#mask').show()
$('.down-box').show()
}
$('.close-down').on('click', function () {
$('#mask').hide()
$('.down-box').hide()
})
$('.close-login').on('click', function () {
$('.login').hide()
})
$('body').on('click', '.down-ct', function (e) {
var ajax_data = {
action: 'bigfa_like',
postId: postId
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data
})
_czc.push(['_trackEvent', '下载', '城通网盘', postId])
})
// $('.down-bd').on('click', function (e) {
// e.preventDefault()
// var ajax_data = {
// action: "down_bd",
// um_id: postId
// };
// $.ajax({
// type: 'post',
// url: '/wp-admin/admin-ajax.php',
// data: ajax_data,
// async: false,
// success: function (res) {
// if (res == '404') {
// alert('未找到资源,请刷新页面重试')
// } else {
// window.open(res)
// }
// }
// })
// });
$('body').on('click', '.down-bd', function (e) {
e.preventDefault()
if ($(this).hasClass('no-login')) {
Util.confirm({
cancelButtonText: '暂不登录',
confirmButtonText: '立即登录',
msg: '您未登录,请先登录
新用户注册立送 50 积分
',
onOk: function () {
$('.weLogin').trigger('click')
}
})
_czc.push(['_trackEvent', '登录', '显示是否登录'])
} else {
var ajax_data = {
action: 'down_bd',
postId: postId
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
async: false,
success: function (res) {
if (res == '404') {
alert('未找到资源,请刷新页面重试')
} else {
if (res.code == 200) {
window.open(res.data.url)
} else if (res.code == 201) {
alert(res.message)
} else {
window.open(res)
}
}
}
})
_czc.push(['_trackEvent', '下载', '百度网盘', postId])
}
})
$('body').on('click', '.down-bdbd', function (e) {
e.preventDefault()
if ($(this).hasClass('no-login')) {
$('.down-box').css({
'z-index': 900
})
Util.confirm({
cancelButtonText: '暂不登录',
confirmButtonText: '立即登录',
msg: '您未登录,请先登录
新用户注册立送 50 积分
',
onOk: function () {
$('.weLogin').eq(1).trigger('click')
_czc.push(['_trackEvent', '登录', '立即登录'])
},
onClose: function () {
$('.down-box').css({
'z-index': 1000
})
$('#mask').show()
_czc.push(['_trackEvent', '登录', '暂不登录'])
}
})
_czc.push(['_trackEvent', '登录', '显示是否登录'])
} else {
var ajax_data = {
action: 'down_bd',
postId: postId
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
async: false,
success: function (res) {
if (res.code == 200) {
window.open(res.data.url)
} else if (res.code == 201) {
alert(res.message)
} else {
window.open(res)
}
}
})
_czc.push(['_trackEvent', '下载', '百度网盘', postId])
}
})
$('body').on('click', '.down-ctzip', function (e) {
e.preventDefault()
if ($(this).hasClass('no-login')) {
$('.down-box').css({
'z-index': 900
})
Util.confirm({
cancelButtonText: '暂不登录',
confirmButtonText: '立即登录',
msg: '您未登录,请先登录
新用户注册立送 50 积分
',
onOk: function () {
$('.weLogin').eq(1).trigger('click')
_czc.push(['_trackEvent', '登录', '立即登录'])
},
onClose: function () {
$('.down-box').css({
'z-index': 1000
})
$('#mask').show()
_czc.push(['_trackEvent', '登录', '暂不登录'])
}
})
_czc.push(['_trackEvent', '登录', '显示是否登录'])
} else {
var ajax_data = {
action: 'down_ctzip',
postId: postId
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
async: false,
success: function (res) {
if (res == '404') {
alert('未找到资源,请刷新页面重试')
} else {
if (res.code == 200) {
window.open(res.data.url)
} else if (res.code == 201) {
alert(res.message)
} else {
window.open(res)
}
}
}
})
_czc.push(['_trackEvent', '下载', '本地下载', postId])
}
})
$('.pay').on('click', function (e) {
e.preventDefault()
var self = $(this)
$('.down-box').css({
'z-index': 900
})
Util.confirm({
msg: '确定要支付吗?',
onClose: function () {
$('.down-box').css({
'z-index': 1000
})
},
onOk: function () {
var ajax_data = {
action: 'pay',
post_id: postId
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
async: false,
success: function (res) {
$('.down-box').css({
'z-index': 1000
})
if (res.code === 200) {
var $buttons = $('.down-button').find('a')
$buttons.eq(0).removeClass('down-gray').addClass('down-ct')
$buttons.eq(1).removeClass('down-gray').addClass('down-bd')
$buttons.eq(2).removeClass('down-gray').addClass('down-ctzip')
self.parent().hide().next().show()
}
},
error: function () {}
})
}
})
})
// 登录
$('#loginBtn').on('click', function () {
var username = $('#username').val()
var password = $('#password').val()
var security = $('#security').val()
var ajax_data = {
action: 'ajaxlogin',
username: username,
password: password,
security: security
}
console.log('data', ajax_data)
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
success: function (res) {
console.log('res-4958', res)
if (res.code == 200) {
console.log('登录成功')
// $('.down-gray').eq(0).toggleClass('down-bd down-gray')
// $('.down-gray').eq(0).toggleClass('down-ctzip down-gray')
// $('.login').hide()
window.location.href = pageUrl + '#login'
window.location.reload()
}
}
})
})
// 注册
$('#regBtn').on('click', function () {
var username = $('#username').val()
var password = $('#password').val()
var password2 = $('#password2').val()
var email = $('#email').val()
var security = $('#security').val()
if (!username) {
alert('请输入用户名')
return
}
if (!password) {
alert('请输入密码')
return
}
if (!password2) {
alert('请再次输入密码')
return
}
if (!email) {
alert('请输入电子邮箱')
return
}
if (password != password2) {
alert('两次密码不一致')
return
} else {
var ajax_data = {
action: 'my_create_user',
username: username,
password: password,
email: email,
security: security
}
console.log('data', ajax_data)
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
success: function (res) {
if (res.code == 200) {
console.log('注册成功')
window.location.href = pageUrl + '#login'
window.location.reload()
}
}
})
}
})
// 登录注册切换
$('.to-reg').on('click', function () {
$('.login').addClass('reg').find('h5').text('用户注册')
})
$('.to-login').on('click', function () {
$('.login').removeClass('reg').find('h5').text('用户登录')
})
$('.show-login').on('click', function () {
$('.login').show()
})
$('.show-reg').on('click', function () {
$('.login').addClass('reg').show()
})
// 查询 ip 归属
$('body').on('click', '.ip-place', function (e) {
var ip = $(this).data('ip')
var $this = $(this)
var appkey = '396f5d0d5a1c6b941fc91b2978c696bf'
var url = 'https://apis.juhe.cn/ip/ip2addr'
$.getJSON(
url + '?callback=?',
{
ip: ip,
dtype: 'jsonp',
key: appkey
},
function (res) {
var errorcode = res.error_code
if (errorcode == 0) {
$this.html(res.result.area + '-' + res.result.location)
} else {
alert(errorcode + ':' + res.reason)
}
}
)
})
// 微信登录
var checkLogin = null
$('.weLogin').on('click', function () {
$('.down-box').css({
'z-index': 900
})
var $mask = $('#mask')
var $maskHtml = ''
if (!$mask.length) {
$maskHtml = ''
}
$('body').append(
$maskHtml +
''
)
$('#mask').show()
$('.ui-dialog-welogin').show()
new WxLogin({
self_redirect: false,
id: 'login_container',
appid: 'wx7d5667f2ced4ca87',
scope: 'snsapi_login',
redirect_uri: encodeURIComponent('https://www.dowebok.com/wechat'),
// state: "QAapAtFXm9wna4jA",
style: 'black',
href: 'https://www.dowebok.com/wp-content/themes/uehtml/wx_login.css'
})
})
$('body').on('click', '.ui-dialog__close', function () {
clearInterval(checkLogin)
$(this).parents('.ui-dialog').remove()
if ($('.down-box').is(':visible')) {
$('.down-box').css({
'z-index': 1000
})
} else {
$('#mask').hide()
$('.down-box').css({
'z-index': 1000
})
}
})
// 充值
$('.recharge-btn').on('click', function (e) {
e.preventDefault()
// 调整下载框层级
var $downBox = $('.down-box')
$downBox.css({
'z-index': 900
})
var $type = $(this).data('type')
var $typeStr = $type == 'alipay' ? '支付宝扫码支付' : '微信扫码支付'
var $mask = $('#mask')
var $maskHtml = ''
if (!$mask.length) {
$maskHtml = ''
}
$('body').append(
$maskHtml +
''
)
$('#mask').show()
$('.ui-dialog-pay').show()
var $type = $(this).data('type')
var $price = $(this).data('price')
var $title = $(this).data('title')
var ajax_data = {
action: 'recharge',
type: $type,
price: $price,
title: $title
}
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: ajax_data,
success: function (res) {
var resutl = jQuery.parseJSON(res)
$('#qrcode-pay').html('')
// Util.alert1({
// class: 'recharge',
// confirmButtonText: '充值完成',
// msg: '',
// hideMask: false,
// onOk: function() {
// $downBox.css({
// 'z-index': 1000
// })
// $.ajax({
// type: 'post',
// url: '/wp-admin/admin-ajax.php',
// data: {
// action: 'userpoint',
// },
// success: function (res) {
// var $resultPoint = res.data.point
// var $latestPoint = $('.latest-point')
// $latestPoint.text($resultPoint)
// var $post_point = $('#post_point').data('post-point')
// if($resultPoint >= $post_point) {
// $('.line').hide().next().show().next().hide()
// }
// }
// })
// }
// })
}
})
})
// 充值完成
$('body').on('click', '#pay-ok', function (e) {
e.preventDefault()
var thisPage = window.location.href
if (thisPage === 'https://www.dowebok.com/recharge') {
$('.ui-dialog-pay').remove()
$('#mask').hide()
} else {
var $downBox = $('.down-box')
$downBox.css({
'z-index': 1000
})
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
action: 'userpoint'
},
success: function (res) {
$('.ui-dialog-pay').remove()
var $resultPoint = res.data.point
var $latestPoint = $('.latest-point')
$latestPoint.text($resultPoint)
var $post_point = $('#post_point').data('post-point')
if ($resultPoint >= $post_point) {
$('.line').hide().next().show().next().hide()
}
}
})
}
})
// 测试
$('.ftp').on('click', function () {
Util.confirm({
cancelButtonText: '暂不登录',
confirmButtonText: '立即登录',
msg: '您未登录,请先登录
新用户注册立送 50 积分
',
onOk: function () {
$('.weLogin').trigger('click')
}
})
})
// 签到
var lock = false
$('.check-in').on('click', function () {
if (!$(this).hasClass('weLogin')) {
if (lock) {
return
}
lock = true
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
action: 'checkin'
},
success: function (res) {
lock = false
var html = ''
if (res.code == 200) {
if (res.message == '已签到') {
html =
'今日已签到
关注公众号,多一次签到,更多积分,更加便捷
明天继续 '
} else {
html =
'+20积分
关注公众号,多一次签到,更多积分,更加便捷
明天继续 '
}
var $mask = $('#mask')
var $maskHtml = ''
if (!$mask.length) {
$maskHtml = ''
}
$('body').append($maskHtml + html)
$('#mask').show()
$('.ui-dialog-check-in').show()
} else {
console.log('签到失败')
}
}
})
}
})
// 更新百度网盘地址
$('#ssss').on('click', function() {
console.log('ssss')
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
action: 'ssss',
id: $('#ss_id').text(),
url: $('#ss_url').text(),
pass: $('#ss_pass').text()
},
success: function (res) {
console.log(res)
$('#ssss').html('更新成功')
}
})
})
})