var visitDate = new Date();
var visitTime1 = visitDate.getTime();
var visitTime = String(Math.floor(visitTime1 / 1000));
var visitCode = visitTime.concat(String(Math.floor(Math.random() * 10 + 1) - 1)).concat(String(Math.floor(Math.random() * 10 + 1) - 1)).concat(String(Math.floor(Math.random() * 10 + 1) - 1)).concat(String(Math.floor(Math.random() * 10 + 1) - 1));
var urlHost = window.location.host.toLowerCase();
var visitUrl = window.location.pathname;
var visitUrls = visitUrl.split("/");
setTimeout(function() {
if (visitUrls.length >= 4 && urlHost == 'online.pubhtml5.com') {
$.getScript("../getuserinfo.js")
.done(function (script, textStatus) {
if(typeof user_type == 'undefined') {
user_type = userInfo['user_type']
disable_ad = userInfo['disable_ad']
}
if (user_type == 0) {
// 广告配置参数
var ads = [
{
name: 'ph_small',
width: 320,
height: 50,
googleAd: ' '
},
{
name: 'ph_middle',
width: 468,
height: 60,
googleAd: ' '
},
{
name: 'ph_large',
width: 728,
height: 90,
googleAd: ' '
}
];
// 根据窗口宽度,确定要加载的广告尺寸
var ad;
var windowWidth = $(window).width();
if (windowWidth >= 1000) {
ad = ads[2];
} else if (windowWidth < 1000 && windowWidth >= 600) {
ad = ads[1];
} else {
ad = ads[0];
}
var barHeight = 0;
var hasBar = false;
var bottom = 25;
var other = 8;
var old_buttonMargin = 0;
var old_topMargin = 0;
if (typeof toolBar == 'object' && typeof toolBar.getBottomHeight == 'function') {
var new_topMargin = 0
var barHeight = toolBar.getBottomHeight(true)
if(typeof isPhone === 'undefined' || typeof isPad === 'undefined') {
} else {
if (isPhone() || isPad()) {
barHeight = barHeight == 0 ? 40 : barHeight
new_topMargin = toolBar.getTopHeight(true)
}
}
hasBar = true;
bottom = barHeight + other / 2;
var h1 = bottom + other / 2 + ad.height
var h2 = old_buttonMargin + ad.height + other
old_buttonMargin = bookConfig.bottomMargin || 0;
old_topMargin = bookConfig.topMargin || 0;
bookConfig.bottomMargin = Math.max(h1,h2);//old_buttonMargin + ad.height + other;
bookConfig.topMargin = Math.max(old_topMargin, new_topMargin)
onStageResize()
}
// 构造广告的url
var iframeSrc, imgSrc;
if (location.host == 'localhost') {
imgSrc = "/visit/" + ad.name + ".png";
} else {
imgSrc = "//static.pubhtml5.com/book/banner/" + ad.name + ".png";
}
var $body = $("body");
var $container = $("
").css({
display: 'none',
zIndex: 99999,
position: "fixed",
width: ad.width + 'px',
height: ad.height + 'px',
left: "50%",
marginLeft: -ad.width / 2,
bottom: bottom,
border: "1px solid #181818",
background: "white"
});
var $adsText = $("Ads
").css({
position: "absolute",
left: "0",
bottom: "100%",
background: "white",
border: "1px solid gray",
color: "gray",
padding: "2px 6px",
fontSize: "13px",
lineHeight: "13px",
marginBottom: "2px"
});
var $closeBtn = $("").css({
cursor: "pointer",
position: "absolute",
border: "1px solid #181818",
width: 22,
height: 22,
cursor: "pointer",
background: "white url(//static.pubhtml5.com/book/banner/close.png) no-repeat 3px 3px",
left: "100%",
top: "0px",
marginLeft: "2px"
});
$container
.append($closeBtn)
.append($adsText);
var $fh_banner = $("").css({
position: "absolute",
width: "100%",
height: "100%"
});
// 手机禁用谷歌广告时,添加我们的广告。电脑始终加载我们的广告,没禁用谷歌的话,再加载谷歌广告挡住我们的广告
if (disable_ad == 1) {
addFH5Ad()
} else {
if (isPhone() || isPad()) {
// addMobileGoogleAd()
ad = ads[0];
$container
.append($(ad.googleAd))
.appendTo($body);
} else {
addPCGoogleAd()
}
}
// 广告容器延迟2s才出现
setTimeout(function () {
// 用了fadeIn, 会导致容器高度丢了,这里重新设置一下高度。
$container.height(ad.height).fadeIn(400);
}, 2000);
$closeBtn.on("click", function () {
$container.remove();
if(hasBar) {
bookConfig.bottomMargin = old_buttonMargin;
bookConfig.topMargin = old_topMargin
onStageResize()
}
return
});
function addFH5Ad() {
$container
.append($fh_banner)
.appendTo($body);
}
function addPCGoogleAd() {
$container
.append($(ad.googleAd))
.appendTo($body);
}
function addMobileGoogleAd() {
$("body").append('');
}
}
})
.fail(function (jqxhr, settings, exception) {
//加载失败
});
}
}, 2000)
function sendvisitinfo(type, page) {
var type = type;
var page = page;
if (type == null) {
var type = '';
}
if (page == null) {
var page = '';
}
var isAdd = false;
if (visitUrls.length >= 4) {
var uLink = visitUrls[1];
var bLink = visitUrls[2];
if (urlHost == 'online.pubhtml5.com') {
isAdd = true;
} else if ((urlHost == 'pubhtml5.com') && (visitUrls[1] == 'read')) {
var uLink = visitUrls[2];
var bLink = visitUrls[3];
isAdd = true;
} else {
if (uLink == 'books') {
uLink = 'domain_' + urlHost;
isAdd = true;
}
}
}
if (isAdd == true) {
jQuery(document).ready(function () {
getBookCaseConfig("//stat.pubhtml5.com/bookvisitinfo.html?uLink=" + uLink + "&bLink=" + bLink + "&type=" + type + "&page=" + page + "&code=" + visitCode);
});
}
}
function getBookCaseConfig(url, callBack) {
$.ajax({
async: true,
url: url,
type: "GET",
dataType: 'script',
jsonp: 'jsoncallback',
timeout: 5000,
beforeSend: function () {
},
success: function (json, s) {
},
complete: function (XMLHttpRequest, textStatus) {
if (textStatus == "success" && typeof callBack == "function") {
callBack();
};
},
error: function (xhr) {
}
});
};