亚马逊JS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ==UserScript==
// @name AMA
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.amazon.cn/gp/goldbox/*
// @require http://code.jquery.com/jquery-2.1.1.min.js
// @grant none
//@note https://www.amazon.cn/gp/goldbox/ref=gbps_ftr_s-5_1872_page_1?gb_f_GB-SUPPLE=sortOrder:BY_SCORE,enforcedCategories:658390051,dealStates:AVAILABLE%252CWAITLIST%252CWAITLISTFULL%252CUPCOMING&pf_rd_p=291691872&pf_rd_s=slot-5&pf_rd_t=701&pf_rd_i=gb_main&pf_rd_m=A1AJ19PSB66TGU&pf_rd_r=VPA5H61S9HHSGEP0S2QK
// ==/UserScript==


$ = $ || unsafeWindow.$;


(function () {
var floatDiv='<div id="pp_sc" style="position:absolute;z-index:9999; background-color: #888888;border-style:solid; border-width:1px; border-color:red" > '+
'<input style="padding: 0 40px;padding-top: 10px;height: 45px;text-transform: uppercase;font: bold 20px/22px Arial, sans-serif;" type="text" id="acVal" value=""/>'+

'<input style="padding: 0 40px;padding-top: 10px;height: 45px;text-transform: uppercase;font: bold 20px/22px Arial, sans-serif;" type="button" value="查询指定活动" id="checkAllAc"/>'+


'</div>';

var checkAcUrl = 'https://www.amazon.cn/gp/collect-coupon/handler/get_more_coupons.html?ref_=dp_apl_pc_pop&asin=BOOKCODE&cacheTime=1479098433112&merchantId=A1AJ19PSB66TGU&deviceType=web&dealOffer=0';
var acStr = "";


function checkAllAc() {


function getBookCode(bookUrl) {
var refIndex = bookUrl.indexOf("ref=");
var bookCode = bookUrl.substr(refIndex - 11, 10);
return bookCode;
}


$("div#widgetContent.a-row").find("#dealImage").each(function (index, domEle) {
console.info("index"+index);
var bookUrl = $(domEle).attr("href");
var bookCode = getBookCode(bookUrl);
var checkBookUrl = checkAcUrl.replace('BOOKCODE', bookCode);

$.get(checkBookUrl, function (response) {
if (response.indexOf(acStr) >= 0) {
$(domEle).parent().parent().parent().parent().css({background: "yellow"});
}
});
});
}

$("body").append(floatDiv);

$("#checkAllAc").on("click",function () {

acStr=$("#acVal").val();
checkAllAc();
});

function getScrollTop() {
var scrollPos;
if (window.pageYOffset) {
scrollPos = window.pageYOffset; }
else if (document.compatMode && document.compatMode != 'BackCompat')
{ scrollPos = document.documentElement.scrollTop; }
else if (document.body) { scrollPos = document.body.scrollTop; }
return scrollPos;
}

var temp=$(document).scrollTop();
$(window).scroll(function (){
var st=$(document).scrollTop();
if($(document).scrollTop()>temp){
offsetTop=300+ getScrollTop();
temp=$(document).scrollTop();
}else{
offsetTop=300- getScrollTop();
temp=$(document).scrollTop();
}
offsetTopStr=offsetTop+"px";
$("#pp_sc").animate({top : offsetTopStr },{ duration:500 , queue:false });
});
$(window).scroll();
// Your code here...
})();