JQuery源代碼cookie、setCookie、微信分享等功能,感興趣的朋友可以學(xué)習(xí)借鑒一下!
function cookie(I) { var H = document.cookie.split("; "); var G = new Object(); for (var J = 0; J < H.length; J++) { var F = H[J].split("="); if (F[0] == I) { return unescape(F[1]) } } return "" } function setCookie(G, E) { var H = arguments[2] ? arguments[2] : 3; var F = new Date(); F.setTime(F.getTime() + H * 24 * 60 * 60 * 1e3); document.cookie = G + "=" + escape(E) + ";expires=" + F.toGMTString() }
load方法中的使用代碼:
var ua = navigator.userAgent.toLowerCase(); var is_ie = false; if (/msie ([^;]+)/.test(ua) || "ActiveXObject" in window) { is_ie = true } $(window).load(function() { $(".button-close-window").click(function() { $("#qq-login-window").hide() }); var O = cookie("auth_id"); $(".download-btn,.xunleivip_dl,.xunlei_dl").click(function(G) { var B = $("#h_90sj").val(); var BS = $("#h_90sj").attr("data-ad"); var X = $("#h_97ui").val(); var XS = $("#h_97ui").attr("data-ad"); var Ku = $("#h_588ku").val(); var KuS = $("#h_588ku").attr("data-ad"); var W = $("#h_ooopic").val(); var WS = $("#h_ooopic").attr("data-ad"); var A = $("#h_site").val(); var M = $("#max").val(); var K = $("#kid").val(); var bid = $("#bigclassid").val(); var S = $("#status").val(); B = parseInt(B); BS = parseInt(BS); X = parseInt(X); XS = parseInt(XS); Ku = parseInt(Ku); KuS = parseInt(KuS); W = parseInt(W); WS = parseInt(WS); if (S == 0 && O.length > 0 && A == "http://588ku.com/" && Ku < M && KuS == 0) { $.post("http://www.dopic.net/index.php?m=show&a=ajaxAd", { url: A, kid: K, bid: bid }, function(data) {}); $("#status").val(1); $("#h_588ku").attr("data-ad", 1); $("#h_588ku").val(Ku + 1); window.open(A, "_blank"); G.preventDefault() } else if (S == 0 && O.length > 0 && A == "http://888taobao.com/index.php?m=sales&a=index&sales_id=34" && B < M && BS == 0) { $.post("http://www.dopic.net/index.php?m=show&a=ajaxAd", { url: A, kid: K, bid: bid }, function(data) {}); $("#status").val(1); $("#h_90sj").attr("data-ad", 1); $("#h_90sj").val(B + 1); window.open(A, "_blank"); G.preventDefault() } else if (S == 0 && O.length > 0 && A == "http://www.dopic.net/yangji/?hmsr=%E5%8D%83%E5%9B%BE&hmpl=&hmcu=&hmkw=&hmci=" && X < M && XS == 0) { $.post("http://www.dopic.net/index.php?m=show&a=ajaxAd", { url: A, kid: K, bid: bid }, function(data) {}); $("#status").val(1); $("#h_97ui").attr("data-ad", 1); $("#h_97ui").val(X + 1); window.open(A, "_blank"); G.preventDefault() } else if (S == 0 && O.length > 0 && A == "http://3dxuan.com/YangJi/index?type=2#demo-test" && W < M && WS == 0) { $.post("http://www.dopic.net/index.php?m=show&a=ajaxAd", { url: A, kid: K, bid: bid }, function(data) {}); $("#status").val(1); $("#h_ooopic").attr("data-ad", 1); $("#h_ooopic").val(W + 1); window.open(A, "_blank"); G.preventDefault() } else { G.preventDefault() } }); $("#TB_overlayBG").css({ height: $(window).height() + "px" }); $(".login-prompt").css({ left: ($(".wrapper").width() - 366) / 2 + "px", top: 200 + "px" }); $(".login-prompt .prompt-close,.login-prompt .op-no").bind("click", function() { window.location.href = "http://www.dopic.net/" }); $(window).scroll(function() { $("#TB_overlayBG").css({ height: $(window).height() + "px" }); $(".login-prompt").css({ left: ($(".wrapper").width() - 366) / 2 + "px", top: 200 + "px" }) }); $(window).resize(function() { $("#TB_overlayBG").css({ height: $(window).height() + "px" }); $(".login-prompt").css({ left: ($(".wrapper").width() - 366) / 2 + "px", top: 200 + "px" }) }); if (window.name) { var R = $("#vip_flag").val(); var K = window.name.split(","); var Q = K[0]; var M = K[1]; $("#count-down, .download-btn,.xunleivip_dl,.xunlei_dl,.vipgaosu").toggle(); function L() { $("#count-down em").text(Q); Q--; window.name = Q + "," + M; if (Q == 0) { clearInterval(N); window.name = ""; $("#count-down, .download-btn,.xunleivip_dl,.xunlei_dl,.vipgaosu").toggle() } } var N = setInterval(L, 1e3) } $(".download-btn,.xunleivip_dl,.xunlei_dl").click(function() { if ($(this).hasClass("vipexp")) { $(".vip_vexp").css({ left: ($(window).width() - 460) / 2 + "px", top: $(".sb_ul").offset().top + 49 + "px" }); $(".bg,.vip_vexp").show(); return false } $(".download-btn,.xunleivip_dl,.xunlei_dl,.vipgaosu,.report_img,.report_imgv").toggle(); $(".vipexp").hide(); var E = $(this).attr("href"); var F = $("#h_id").val(); var D = $("#h_size").val(); var H = $("#sns_share"); var C = $("#vip_flag").val(); if (H.length && H.is(":checked") === true) { var I = 1 } else { var I = 0 } var U = 0; if ($(this).hasClass("download-wtgao") || $(this).hasClass("download-wt")) { U = 1 } $.get("http://www.dopic.net/index.php?m=show&a=ajaxDownClick", { picid: F, share: I, wt_flag: U, picsize: D }, function(S) { window.location = E }, "json"); var B; if (window.name == "") { B = 15 } else { var G = window.name.split(","); B = G[0] } $("#count-down").toggle(); if (is_ie === false) { $("#dl_success,.mb10,#putong,.download_lianxi").toggle() } var V = setInterval(A, 1e3); function A() { $("#count-down em").text(B); B--; window.name = B + "," + E; if (is_ie === false && B == 9 && C != 1) { $(".vipexp").hide(); return } else if (B == 0) { clearInterval(V); window.name = ""; if ($("#dl_success").is(":visible")) { $(".vipexp").hide(); $("#count-down").toggle(); $(".free").show() } } } return false }); $(".vip_vexp_start").click(function() { var A = $(this).attr("href"); $.get("http://www.dopic.net/index.php?m=show&a=ajaxNorUserExp", function(B) { window.location = A }); setTimeout(function() { $(".bg,.vip_vexp").hide() }, 5e3) }); $(".vipgaosu").click(function() { $.get("http://www.dopic.net/index.php?m=show&a=vipcount", function(A) {}, "json") }); $(".report_a_new").click(function() { var B = 0; if ($(this).hasClass("reason5")) { B = 5 } else { if ($(this).hasClass("reason6")) { B = 6 } else { if ($(this).hasClass("reason7")) { B = 7 } else { if ($(this).hasClass("reason8")) { B = 8 } else { if ($(this).hasClass("reason9")) { B = 9 } } } } } var A = $(".hideId").val(); $.ajax({ type: "POST", url: "http://www.dopic.net/index.php?m=inform&a=addinform", data: { id: A, reason: B }, dataType: "json", success: function(C) { if (C.status === 1) { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report2").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report2").hide(); $("#tb_bj").hide() }, 2e3) } else { if (C.status === 3) { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report2").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report2").hide(); $("#tb_bj").hide() }, 2e3) } else { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report3").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report3").hide(); $("#tb_bj").hide() }, 2e3) } } } }) }); $(".submit_report").click(function() { var C = $.trim($("#report_reason").val()); if (C == "其他" || C.length == 0) { alert("請?zhí)顚懪e報原因!"); return false } var A = 10; var B = $(".hideId").val(); $.ajax({ type: "POST", url: "http://www.dopic.net/index.php?m=inform&a=addinform", data: { id: B, reason: A, detail: C }, dataType: "json", success: function(D) { if (D.status === 1) { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report2").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report2").hide(); $("#tb_bj").hide() }, 2e3) } else { if (D.status === 3) { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report2").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report2").hide(); $("#tb_bj").hide() }, 2e3) } else { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $(".js_report3").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); setTimeout(function() { $(".js_report3").hide(); $("#tb_bj").hide() }, 2e3) } } } }) }); $("#report_reason").focus(function() { if ($.trim($(this).val()) == "其他") { $(this).val("") } }).blur(function() { if ($.trim($(this).val()) == "") { $(this).val("其他") } }); $(".report_img,.report_imgv").click(function() { $("#report_reason").val("其他"); $(".pic_report_div").css({ display: "block", left: ($(window).width() - 420) / 2 + "px", top: 245 + "px" }); $("#tb_bj").css({ display: "block", height: $(document).height() }) }); $(".report_close_a").click(function() { $("#report_reason").val("其他"); $(".pic_report_div").hide(); $("#tb_bj").hide(); $(".js_report3").hide(); $(".js_report2").hide() }); $(".vip_vexp_right").click(function() { $(".bg,.vip_vexp").hide() }) }); function openLoginWindow(type) { var iframe = 'iframe style="width:100%;height:100%;" src="' + type + '"> </iframe'; $(".window-body").html(iframe); $("#qq-login-window").css("left", ($(window).width() - $("#qq-login-window").width()) / 2 + "px").show() } function close() { $(".bg,.weiShare").hide(); clearInterval(time); var t = new Date().getTime(); var id = $("#h_id").val(); $.get("http://www.dopic.net/index.php?m=ajax&a=delWeixinShare&id=" + id + "&t=" + t, function() {}) } function height() { var A = 0; if (window.innerHeight) { A = window.pageYOffset } else { if (document.documentElement && document.documentElement.scrollTop) { A = document.documentElement.scrollTop } else { if (document.body) { A = document.body.scrollTop } } } return A } function getUid() { var O = cookie("auth_id"); O = O.replace(/\"/g, ""); var _temp = O.split("|"); return _temp[0] } function weixinCode() { var id = $("#h_id").val(); var kid = $("#kid").val(); var uid = getUid(); var M = 3600 * 1e3; var G = new Date().getTime(); if (!id || !kid || !uid) return false; var W = '<div class="weiShare" style="display:none;"><div class="bd_weixin_head"><span>分享到微信朋友圈</span> <a href="javascript:close();" class="weixin_close">×</a></div>\n<div class="weixincode"> <img src="http://www.dopic.net/index.php?m=show&a=renderQR&id=' + id + "&kid=" + kid + "&uid=" + uid + '" /></div> <div class="bd_weixin_foot">打開微信,點(diǎn)擊底部的“發(fā)現(xiàn)”,<br>使用“掃一掃”即可將網(wǎng)頁分享至朋友圈。</div> <div class="success" style="display:none;"></div></div>'; $("body").append(W); $(".bg,.weiShare").show(); $(".bg").css({ height: height() + $(window).height() + "px", width: "100%" }); $(".weiShare").css({ left: ($(window).width() - 261) / 2 + "px", top: ($(window).height() - 296) / 2 + height() + "px" }); time = setInterval(function() { var N = new Date().getTime(); var text; if (N - G < M) { $.get("http://www.dopic.net/index.php?m=ajax&a=getWeixinShare&id=" + id + "&t=" + N, function(d) { var dataJson = eval("(" + d + ")"); if (dataJson.data == 1 || dataJson.data == 2) { clearInterval(time); setTimeout(function() { $(".bd_weixin_foot").hide(); if (dataJson.status == 1 && dataJson.data == 1) { text = "分享成功,當(dāng)天增加1次下載" } else if (dataJson.status == 1 && dataJson.data == 2) { text = "分享成功,增加1天VIP" } else { text = "分享成功" } $(".success").empty().text(text).show() }, 6e4) } }) } }, 2e3) }
微信分享
function openLoginWindow(type) { var iframe = 'iframe style="width:100%;height:100%;" src="' + type + '"> </iframe'; $(".window-body").html(iframe); $("#qq-login-window").css("left", ($(window).width() - $("#qq-login-window").width()) / 2 + "px").show() } function close() { $(".bg,.weiShare").hide(); clearInterval(time); var t = new Date().getTime(); var id = $("#h_id").val(); $.get("http://www.dopic.net/index.php?m=ajax&a=delWeixinShare&id=" + id + "&t=" + t, function() {}) } function height() { var A = 0; if (window.innerHeight) { A = window.pageYOffset } else { if (document.documentElement && document.documentElement.scrollTop) { A = document.documentElement.scrollTop } else { if (document.body) { A = document.body.scrollTop } } } return A } function getUid() { var O = cookie("auth_id"); O = O.replace(/\"/g, ""); var _temp = O.split("|"); return _temp[0] } function weixinCode() { var id = $("#h_id").val(); var kid = $("#kid").val(); var uid = getUid(); var M = 3600 * 1e3; var G = new Date().getTime(); if (!id || !kid || !uid) return false; var W = '<div class="weiShare" style="display:none;"><div class="bd_weixin_head"><span>分享到微信朋友圈</span> <a href="javascript:close();" class="weixin_close">×</a></div>\n<div class="weixincode"> <img src="http://www.dopic.net/index.php?m=show&a=renderQR&id=' + id + "&kid=" + kid + "&uid=" + uid + '" /></div> <div class="bd_weixin_foot">打開微信,點(diǎn)擊底部的“發(fā)現(xiàn)”,<br>使用“掃一掃”即可將網(wǎng)頁分享至朋友圈。</div> <div class="success" style="display:none;"></div></div>'; $("body").append(W); $(".bg,.weiShare").show(); $(".bg").css({ height: height() + $(window).height() + "px", width: "100%" }); $(".weiShare").css({ left: ($(window).width() - 261) / 2 + "px", top: ($(window).height() - 296) / 2 + height() + "px" }); time = setInterval(function() { var N = new Date().getTime(); var text; if (N - G < M) { $.get("http://www.dopic.net/index.php?m=ajax&a=getWeixinShare&id=" + id + "&t=" + N, function(d) { var dataJson = eval("(" + d + ")"); if (dataJson.data == 1 || dataJson.data == 2) { clearInterval(time); setTimeout(function() { $(".bd_weixin_foot").hide(); if (dataJson.status == 1 && dataJson.data == 1) { text = "分享成功,當(dāng)天增加1次下載" } else if (dataJson.status == 1 && dataJson.data == 2) { text = "分享成功,增加1天VIP" } else { text = "分享成功" } $(".success").empty().text(text).show() }, 6e4) } }) } }, 2e3) }