-
Notifications
You must be signed in to change notification settings - Fork 226
/
gwd-AC.js
309 lines (288 loc) · 10.3 KB
/
gwd-AC.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// ==UserScript==
// @name 购物党比价工具【精简优化版】
// @namespace none
// @version 2.2
// @description 【精简版】购物党,优化了页面的部分元素,减少页面弹窗和显示,保留菜单栏。购物党提供淘宝/京东/亚马逊/当当/苏宁/等百家商城的比价系统,能让你以较优惠的方式购买到你称心如意的商品,提供商品的历史价格情况,多种相似商品推荐,同款购买,降价提醒。PS:带有推广,介意勿装
// @author AC
// @antifeature referral-link 含有返利链接
// @include http*://item.taobao.com/*
// @include http*://cart.taobao.com/*
// @include http*://s.taobao.com/*
// @include http*://detail.tmall.com/item.htm*
// @include http*://detail.liangxinyao.com/item.htm*
// @include http*://chaoshi.detail.tmall.com/item.htm*
// @include http*://item.jd.com/*
// @include https://item.jd.hk/*
// @include https://detail.tmall.hk/*
// @include https://*.suning.com/*
// @note V2.2 修复可用性 & 替换地址
// @note V1.6 更换源地址为StaticFile
// @note V1.4 更换源地址为75团地址
// @note V1.2 修复部分多余的隐藏无效的问题 修复之前忘了【新增自己的附加脚本 如果介意的可以删除本脚本】【新增自己的附加脚本 如果介意的可以删除本脚本】【新增自己的附加脚本 如果介意的可以删除本脚本】
// @grant GM_xmlhttpRequest
// @connect open.lesiclub.cn
// @connect api.ntaow.com
// @connect gwdang.com
// @connect alicdn.com
// @run-at document-start
// @license GPL-3.0-only
// @require https://greasyfork.org/scripts/34606-ac-%E7%8B%AC%E5%AE%B6-%E6%B7%98%E5%AE%9D%E5%A4%A9%E7%8C%AB%E4%BC%98%E6%83%A0%E5%88%B8%E6%9F%A5%E8%AF%A2%E9%A2%86%E5%8F%96-%E5%A4%A7%E9%A2%9D%E4%BC%98%E6%83%A0%E5%88%B8-100%E5%85%83%E8%B4%AD%E7%89%A9%E7%A5%9E%E5%88%B8-%E7%9C%81%E9%92%B1%E8%B4%AD%E7%89%A9-%E9%A2%86%E5%88%B8%E8%B4%AD%E4%B9%B0%E6%9B%B4%E4%BC%98%E6%83%A0-%E5%B9%B3%E5%9D%87%E4%BC%98%E6%83%A020/code/AC-%E7%8B%AC%E5%AE%B6-%E6%B7%98%E5%AE%9D%E5%A4%A9%E7%8C%AB%E4%BC%98%E6%83%A0%E5%88%B8%E6%9F%A5%E8%AF%A2%E9%A2%86%E5%8F%96,%E5%A4%A7%E9%A2%9D%E4%BC%98%E6%83%A0%E5%88%B8,%E3%80%90100%E5%85%83%E8%B4%AD%E7%89%A9%E7%A5%9E%E5%88%B8%E3%80%91,%E7%9C%81%E9%92%B1%E8%B4%AD%E7%89%A9,%E9%A2%86%E5%88%B8%E8%B4%AD%E4%B9%B0%E6%9B%B4%E4%BC%98%E6%83%A0,%E5%B9%B3%E5%9D%87%E4%BC%98%E6%83%A020%25.user.js
// ==/UserScript==
(function () {
const goodId = getUrlAttribute("id")
// 提取url中的参数
function getUrlAttribute(attribute, needDecode) {
const searchValue = (window.location.search.substr(1) + "").split("&");
for (let i = 0; i < searchValue.length; i++) {
const key_value = searchValue[i].split("=");
const reg = new RegExp("^" + attribute + "$");
if (reg.test(key_value[0])) {
const searchWords = key_value[1];
return needDecode ? decodeURIComponent(searchWords) : searchWords;
}
}
}
function safeWaitFunc(selector, callbackFunc, time, notClear) {
time = time || 200;
notClear = notClear || false;
const doClear = !notClear;
const id = setInterval(function () {
let selectRes = document.querySelectorAll(selector);
if ((typeof (selector) == "string" && selectRes.length > 0)) {
if (doClear) clearInterval(id);
if (selectRes.length === 1) selectRes = selectRes[0];
callbackFunc(selectRes);
} else if ((typeof (selector) == "function" && selector().length > 0)) {
if (doClear) clearInterval(id);
callbackFunc(selector()[0]);
}
}, time);
}
function addStyle(css) { //添加CSS的代码--copy的--注意里面必须是双引号
var pi = document.createProcessingInstruction(
'xml-stylesheet',
'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent(css) + '"'
);
return document.insertBefore(pi, document.documentElement);
}
function addScript(src) {
let node = document.createElement("script");
node.src = src;
node.charset = "UTF-8";
document.head.appendChild(node);
}
function initGWD() {
let extName = "gwdv1.js";
let hideStyle = "";
if (location.host === "jd.com") {
extName = "gwdv2.js";
hideStyle = ".gwd-minibar-bg, #favor_box{display:none !important;}" +
"#gwdang_main > a.gwd-topbar-logo, #gwdang_main > div.gwd-topbar-right{display:none !important;}";
} else {
hideStyle = "#gwdang-main>div.logo, #gwdang-feed-close, #gwdang-history, #coupon_box, #bjd_yifenqian_detail{display:none !important}" +
"#favor_box{display:none !important;}#tb-amount .tb-count{font-weight:bold;margin:0 5px;}";
}
// addScript("https://cdn.jsdelivr.net/gh/chenzelin01/wechatproxy/public/" + extName);
addScript("https://browser.gwdang.com/get.js?f=/js/gwdang_extension.js");
addStyle(hideStyle);
}
function realTimeShowTBTitle(){
addStyle(".tshop-psm-shop-header,.ac-tophide{position: absolute;top: -500px;}.ac-topshow{position:relative;transition: all 1s cubic-bezier(0.4, 0, 1, 1);transform: translateY(500px);}");
let timer = setInterval(function(){
let node = document.querySelector(".tshop-psm-shop-header");
let addClassName = "ac-tophide";
if(node == null) return;
// 如果大于200,说明样式未加载
if(node.offsetHeight > 200 && !node.classList.contains(addClassName)){
node.classList.add(addClassName);
}
if(node.offsetHeight <= 200){
if(node.classList.contains(addClassName)){
node.classList.add("ac-topshow");
clearInterval(timer);
}else{
clearInterval(timer);
// 清空附加样式
addStyle(".tshop-psm-shop-header{position: relative;top: unset;}");
}
}
},150);
}
function init() {
function dealRes(json){
var allHide = "";
var yearHide = "";
var monthHide = "";
if (json.store[0].all_line == null) {
allHide = "style='display: none;'";
}
if (json.store[0].year_line == null) {
yearHide = "style='display: none;'";
}
if (json.store[0].month_line == null) {
monthHide = "style='display: none;'";
}
var ddata;
if (json.store.length > 1) {
ddata = json.store[1].all_line;
}
var ddata;
if (json.store.length > 1) {
ddata = json.store[1].all_line;
}
let pdata = json.store[0].all_line;
let pbeginTime = json.store[0].all_line_begin_time;
let picdata = ddata;
var hml = "<div style='margin-left:50px;margin-top:20px;display: block;'><a class='active-plot type-plot' " + allHide + " id='plotAll'>全部</a><a class='type-plot' " + yearHide + " id='plotYear'>年线</a><a class='type-plot' " + monthHide + " id='plotMonth'>月线</a>";
hml = hml + "<div id='hisprice' style='width: 720px;height:350px;margin: 0;padding: 0'></div>";
return `
<script src="https://cdn.staticfile.org/echarts/4.8.0/echarts.min.js"></script>
${hml}
<script>
var pChart = echarts.init(document.getElementById('hisprice'));
showPrice();
function showPrice() {
var data =[${pdata}];
var beginTime =${pbeginTime};
var picdata =[${picdata}];
var dt = [];
for (var i = 0; i < data.length; i++) {
var d = new Date(beginTime);
d.setDate(d.getDate() + i);
dt.push(d.toLocaleDateString());
}
// 指定图表的配置项和数据
var option = {
tooltip: {
enterable: true,
trigger: 'axis',
formatter: function (params) {
return params[0].axisValue + "<br/>" + params[0].data;
},
axisPointer: {
animation: false
}
},
legend: {
data: ['页面价', '到手价'],
selected: {
'页面价': true,
'到手价': true
}
},
xAxis: {
data: dt,
splitArea: { show: false },
boundaryGap: false,
splitLine: {
show: true,
},
axisLabel: {
interval: parseInt((data.length) / 10),
formatter: function (value) {
return value.substring(5);
}
},
},
yAxis: {
splitArea: { show: false },
splitLine: {
show: true,
}
},
series: [{
name: '页面价',
type: 'line',
data: data,
showSymbol: false,
hoverAnimation: false,
markPoint: {
symbol: 'pin',
data: [
{ type: 'max', name: '最大值' },
{ type: 'min', name: '最小值' }
]
},
markLine: {
data: [
{ type: 'average', name: '平均值' }
]
}
},
{
name: '到手价',
type: 'line',
data: picdata,
showSymbol: false,
hoverAnimation: false,
markPoint: {
symbol: 'pin',
data: [
{ type: 'max', name: '最大值' },
{ type: 'min', name: '最小值' }
]
},
markLine: {
data: [
{ type: 'average', name: '平均值' }
]
}
}
]
};
pChart.setOption(option);
};
</script>
`
}
function opWind(purl, pisweb, pname, phml) {
var url = purl;
var name = pname;
var iWidth = 800;
var iHeight = 450;
var iTop = (window.screen.height - 30 - iHeight) / 2;
var iLeft = (window.screen.width - 10 - iWidth) / 2;
// var OpenWindow = window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
// if (pisweb == 0) {
// OpenWindow.document.write(phml);
// OpenWindow.document.close();
// OpenWindow.focus();
// }
var insWind = document.createElement("iframe");
// insWind.src = "javascript:(function(){document.write("+insWind+")})()";
insWind.innerHTML = phml;
document.body.appendChild(insWind);
}
// localStorage.getItem("gwdang-fp") == null
if(true){
// 首次加载数据
initGWD();
}else{
// TODO 待完成,似乎这里不好处理
let qdata = "fp="+localStorage.getItem("gwdang-fp")+"&dfp="+localStorage.getItem("gwdang-dfp");
GM_xmlhttpRequest({
url: "https://browser.gwdang.com/extension/price_towards?ver=1&format=jsonp&&url=" + encodeURIComponent(location.href),
method: 'GET',
timeout: 10000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Cache-Control': 'public'
},
onload: function (res) {
const json = JSON.parse(res.responseText)
if (json.is_ban == null) {
console.log(json);
let data = dealRes(json);
opWind('', 0, '比价', data);
} else {
console.log(json.action.to);
opWind(json.action.to, '1', '请验证后刷新页面!', '');
}
}
});
}
}
init();
realTimeShowTBTitle();
})()