The following is the JS Code for Xiaomi flash sales. After analyzing the code, you can use it to implement a Red Rice flash sales software. You can use this code to implement the desired function!
Copy codeThe Code is as follows:
Hdcontrol ({"stime": 1381645438, "status": {"allow": false, "miphone": {"hdstart": false, "hdstop": false, "hdurl": "", "duration": null}, "mibox": {"hdstart": false, "hdstop": false, "hdurl ":"", "duration": null }}})
Copy codeThe Code is as follows:
Function forNum (){
Return 10>? "0" + a:
}
Function countdown (a, B ){
Varc = newDate (B). getTime ()/1e3,
D = c-,
E = parseInt (d % 60 ),
F = parseInt (d/60% 60), g = parseInt (d/3600% 24 ),
H = parseInt (d/3600/24 ),
I = [e. toString (),
F. toString (),
G. toString ()];
Return0> = d? ["00 hours, 00 minutes, 00 seconds ",! 0]: h> 0? (Window. _ timestr = h + "day" + forNum (I [2]) + "Hour" + forNum (I [1]) + "Minute" + forNum (I [0]) + "seconds", [h + "<span> day </span>" + forNum (I [2]) + "<span> hour </span>" + forNum (I [1]) + "<span> minute </span>" + forNum (I [0]) + "<span> seconds </span> ",! 1]) :( window. _ timestr = forNum (I [2]) + "Hour" + forNum (I [1]) + "Minute" + forNum (I [0]) + "second ", [forNum (I [2]) + "<span> hour </span>" + forNum (I [1]) + "<span> minute </span>" + forNum (I [0]) + "<span> second </span> ",! 1])}
FunctionWebEventTrigger (a, B ){
Try {
If (WE & WE. trigger)
Return "string "! = Typeofb & (B = JSON. stringify (B), WE. trigger (a, B)
} Catch (c ){}
Return! 1
}
FunctionisApp (){
Try {
If (WE) return! 0
} Catch (){}
Return! 1
}
VarquickBuy = {init: function (){
Vara = this;
This. config = {},
This. config. hdurl = {miphone: "m3/movie/tip_SaledOverAll.html", mibox: "TV/movie/tip_SaledOverAll.html"
},
This. config. mode = "",
This. mode = {miphone :! 1, mibox :! 1 },
This. modeModals = {miphone: "# modal_miphone", mibox: "# modal_mibox "},
This. modeCookies = {miphone: "xm_hd_so_phone", mibox: "xm_hd_so_box "},
This. config. startDate = + newDate ("10/15/201312: 00: 00 "),
This. maskLoad = $ ("# maskLoad "),
This. config. minSignTime = 120,
This. results = null,
This. timer = null,
This. timeCount = Math. floor (Math. abs (10 * Math. random ()-5) + 5;
Varb =! 0;
For (varcinthis. mode)
$. Cookie (this. modeCookies [c]) | (B =! 1), $. cookie (this. modeCookies [c]) & this. saleOut ();
B | ($. cookie ("xm_diff_hd ")? (This. config. serverTime = this. localTime () + parseInt ($. cookie ("xm_diff_hd"), 10), this. config. serverTime> = parseInt (this. config. startDate/1e3, 10 )? $. Cookie ("xm_hd_so_phone") & $. cookie ("xm_hd_so_box") | this. getData (! 0, function () {a. goBuy ()}): this. launch (): this. getData ()}, getData: function (a, B ){
Varc = this, a = a | null;
B & (B = B ),
$. Ajax ({
Url: "http://tc.hd.xiaomi.com/hdget ",
DataType: "jsonp ",
JsonpCallback: "hdcontrol ",
Timeout: 7e3,
BeforeSend: function (){
C.maskLoad.css ("display", "block ")},
Error: function (){
C.maskLoad.css ("display", "none "),
Alert ("the server is under heavy pressure. Please refresh the page again! ")
},
Success: function (d ){
If(c.maskLoad.css ("display", "none"), "undefined" = typeofd)
Returnalert ("the server is under heavy pressure. Please refresh the page again! "),
Void0;
If (c. results = d, a | (c. config. serverTime = c. results. stime ),! $. Cookie ("xm_diff_hd ")){
Vare = parseInt (c. config. serverTime-c.localTime (), 10 );
$. Cookie ("xm_diff_hd", e ,{
Path :"/",
Domain: ".xiaomi.com ",
Expires: 1
})
}
If (){
C. initialData ();
For (varfinc. mode)
If (c. config [f]. hdstart =! 1 & c. config [f]. hdstop =! 0 ){
Varg = c. modeCookies [f];
$. Cookie (g, 1, {path: "/", domain: ".xiaomi.com", expires: 1 }),
C. saleOut ()
} Elseb & B. call ()
}
A | c. launch ()
}})},
InitialData: function (){
This. config. allow = this. results. status. allow,
This. config. mibox = this. results. status. mibox,
This. config. miphone = this. results. status. miphone
},
Launch: function (){
This. timeStart (),
This. countdown ()
},
TimeStart: function (){
Vara = this,
B = 1e3 * a. config. serverTime,
C = a. config. startDate,
D = c-1e3 * 60 * a. config. minSignTime;
B> = d & c> B &&! IsApp ()?
$. Cookie ("userId ")?
($ ("# View_button" ).css ("visibility", "hidden "),
$ ("# Purchase_btn_1" shopping .html ('<aclass = "btn_buy" href = "http://bbs.xiaomi.cn/thread-8205768-1-1.html"> activity details </a> '),
$ ("# Purchase_btn_2" ).html ('<aclass = "btn_buybtn_02" href = "javascript:;"> logged on </a>'):. toLogin (): B> = c &. toBuy ()
},
ToLogin: function (){
$ ("# View_button" ).css ("visibility", "hidden "),
$ ("# Purchase_btn_1" shopping .html ('<aclass = "btn_buy" href = "http://bbs.xiaomi.cn/thread-8205768-1-1.html"> activity details </a> '),
$ ("# Purchase_btn_2" ).html ('<aclass = "btn_buybtn_02" href = "javascript:;"> early logon </a> '),
$ ("# Purchase_btn_2"). find (". btn_02"). on ("click", function (){
WebEventTrigger ("login", null) | (window. location. href = "http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso? Client_id = 180100031013 & callback = "+ encodeURIComponent (window. location. href ))}
)},
Countdown: function (){
Vara = this,
B = null,
C = a. config. startDate;
B = a. config. serverTime? A. config. serverTime: parseInt (+ newDate/1e3, 10 );
Vard = c-1e3 * 60 * a. config. minSignTime,
E = setInterval (function (){
Varf = countdown (B, c );
F [1]? (ClearInterval (e), $ ("# countdown" ).css ("display", "none"), a. toBuy () :( 1e3 * B! = D | isApp () | ($. cookie ("userId ")? ($ ("# View_button" ).css ("visibility", "hidden "),
$ ("# Purchase_btn_1" shopping .html ('<aclass = "btn_buy" href = "http://bbs.xiaomi.cn/thread-8205768-1-1.html"> activity details </a> '),
$ ("# Purchase_btn_2" ).html ('<aclass = "btn_buy" href = "javascript:;"> logged on </a>'):. toLogin (), B ++ ),
$ ("# Countdown" ).html (f [0])}, 1e3 )},
ToBuy: function (){
Vara = this;
A. goBuy ();
Varb = a. modeModals [a. config. mode];
$ (B). find (". close"). on ("click", function (){
(( B ).css ("display", "none "),
Window. clearTimeout (a. timer ),
A. timer = null })},
SaleOut: function (){
Vara = {miphone: "# purchase_btn_2", mibox: "# purchase_btn_1 "},
B = {miphone: "http://t.hd.xiaomi.com/r? _ A = payment_check & _ m = 1 ", mibox:" http://m.xiaomi.com/index.html#ac=home&op=addcart&product_id=2505 "},
C = {miphone: "Payment Xiaomi phone 3", mibox: "Payment Xiaomi TV "};
For (vardinthis. mode)
Round ('<aclass = "btn_buy" href = "' + B [d] + '">' + c [d] + "</a> "),
$ (This. modeModals [d]). is (": visible") & $ (this. modeModals [d]). find (". close "). click ())},
LocalTime: function (){
Vara = parseInt (+ newDate/1e3, 10 );
Returna
},
ToProcess: function (){
Varb = this,
C = B. timer,
D = B. timeCount | 10, e = $ (B. modeModals [a]). find (". re_countdown "),
F = $ (B. modeModals [a]). find (". modal_btn "),
G = function () {0 = d? (F.html ('<aclass = "into_buy_btn" href = "javascript:;"> enter activity </a> '),
B. toBuyGo (B. config. mode ),
C & window. clearTimeout (c ),
C = null) :( e.html ("(" + d + ")"),
D --,
B. timer = window. setTimeout (function () {g ()}, 1e3 ))};
C & window. clearTimeout (c), g ()},
GoBuy: function (){
Vara = this,
B = {miphone: "buy Xiaomi Mobile Phone 3", mibox: "buy Xiaomi TV "},
C = {miphone: "# purchase_btn_2", mibox: "# purchase_btn_1 "};
For (vardina. mode)
$. Cookie (. modeCookies [d]) | ($(c%d%).html ('<aclass = "btn_buybtn_buy_go" data-type = "' + d + '" href = "javascript :; "> '+ B [d] +" </a> "),
$ (C [d]). is (": hidden" )&&((c?d=).css ("display", "block "));
$ ("# Open_button "). find (". btn_buy_go "). on ("click", function () {. mode [$ (this ). attr ("data-type")] =! 0;
Varb = a. config. mode = $ (this). attr ("data-type ");
If ($. cookie ("userId") a. getData (! 0, function (){
Certificate (a.modemodals% B %%%.css ("display", "block "),
$ (A. modeModals [B]). find (". close"). on ("click", function (){
Vertex (a.modemodals% B %%%.css ("display", "none"), window. clearTimeout (a. timer), a. timer = null}), a. toProcess (B )});
Else {if (WebEventTrigger ("login", null) return;
Window. location. href = "http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso? Client_id = 180100031013 & callback = "+ encodeURIComponent (window. location. href )}})},
ToBuyGo: function (){
Varb = this;
Window. clearTimeout (B. timer ),
B. timer = null,
$ (B. modeModals [a]). find (". modal_btn "). find (". into_buy_btn "). on ("click", function (c) {c. preventDefault (), B. getData (! 0, function (){
If((( B .modemodals[a]).css ("display", "block"), B. config. allow) if (B. config [a]. hdurl ){
Varc = "http://t.hd.xiaomi.com/s/" + B. config [a]. hdurl + "& _ m = 1 ";
Windows. setTimeout (function () {window. location. href = c}, 500)
} Else {
Vard = "http://p.www.xiaomi.com/m/activities/open/" + B. config. hdurl [a];
Window. setTimeout (function () {window. location. href = d}, 500)
} Elseif (
B. config [a]. hdstart =! 1 & B. config [a]. hdstop =! 0 ){
Vard = "http://p.www.xiaomi.com/m/activities/open/" + B. config. hdurl [a];
Window. setTimeout (function () {window. location. href = d}, 500)
} Else $ (B. modeModals [a]). find (". modal_btn ").html ('<aclass =" re_enter "href =" javascript:; "> re-enter </a> '),
B. toProcess ()
})})}};