-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaobaoUrl.js
164 lines (119 loc) · 4.69 KB
/
taobaoUrl.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
// ==UserScript==
// @name 获取淘宝商品链接
// @version v1.0
// @namespace Violentmonkey Scripts
// @description 通过关键词搜索出来的商品列表,点击某个商品的添加按钮,添加到右侧的链接列表,支持一键复制所有链接,并支持导出链接列表文件
// @author Finn
// @license MIT
// @match https://s.taobao.com/search
// @require https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
// ==/UserScript==
;(function () {
'use strict';
var urlList = [];
var txtbox = document.getElementsByClassName('grid-left');
var newTxtBox = document.createElement('div');
var newTxtBoxTitle = document.createElement('p');
var oneClickCopy = document.createElement('a');
setTimeout(function(){
newTxtBox.class = "myNewTxtBox";
newTxtBox.style = "width:200px;min-height:50px;max-height:500px;position:fixed;background:#f5f5f5;border-radius:4px;padding:10px;overflow:auto;top:10%;right:20px";
newTxtBoxTitle.innerHTML = "商品URL列表:";
newTxtBoxTitle.style = "font-weight:bold;"
oneClickCopy.innerHTML = "一键复制";
oneClickCopy.style = "width:60px;height:25px;line-height:25px;text-align:center;display:block;position:fixed;background:#f5f5f5;border-radius:4px;top:7%;right:20px;cursor:pointer;";
oneClickCopy.id = "copyBtn"
oneClickCopy.addEventListener('click',copyClick);
newTxtBox.appendChild(newTxtBoxTitle);
txtbox[1].appendChild(newTxtBox);
txtbox[1].appendChild(oneClickCopy);
console.log("加载成功");
},500);
$(function (){
getCommoditiesList();
monitorJump();
})
function getCommoditiesList() {
var list = document.getElementsByClassName('row row-2 title');
setTimeout(function(){
for(var i=1; i<=list.length-1; i++){
var newnode = document.createElement("b");
newnode.innerHTML = "添加";
newnode.class = "myAddButton";
newnode.style = "width: 50px;height: 30px;display: block;position: absolute;background: #ccc;text-align: center;line-height: 30px;border-radius: 4px;margin-top: -24px;margin-left: 70px;cursor: pointer;user-select: none;";
newnode.id=i;
var sb = list[i].parentNode;
sb.appendChild(newnode);
sb.onclick = function(e){
urlList.push(e.target.parentNode.children[1].children[0].href);
adddTxtBox(e.target.parentNode.children[1].children[0].href);
}
}
},1000)
}
function addTxtBox(){
var test = document.getElementsByClassName('myNewTxtBoxP');
for(var i=0;i<urlList.length;i++){
var newTxtBoxP = document.createElement('p');
newTxtBoxP.class = "myNewTxtBoxP";
newTxtBoxP.id = i;
newTxtBoxP.innerHTML = urlList[i];
newTxtBox.appendChild(newTxtBoxP);
}
}
function adddTxtBox(str){
var newTxtBoxP = document.createElement('p');
newTxtBoxP.class = "myNewTxtBoxP";
newTxtBoxP.style = "width:100%;min-height:30px;border-bottom:1px solid red;";
newTxtBoxP.id = i;
newTxtBoxP.innerHTML = str;
newTxtBox.appendChild(newTxtBoxP);
}
function dataToTxt(exportData){
var w = window.open("about:blank","导出","height=0,width=0,toolbar=no,menubar=no,scrollbars=no,resizable=on,location=no,status=no");
var dt = new Date();
w.document.write(exportData);
try {
w.document.charset = "GB2312";
} catch (err) {
console.log(err);
}
w.document.execCommand(
"SaveAs",
false,
dt.getFullYear() +
"-" +
(dt.getMonth() + 1) +
"-" +
dt.getDate() +
"-" +
dt.getTime() +
".txt"
);
w.close();
}
function btnClick(){
getCommoditiesList();
monitorJump();
}
function monitorJump(){
setTimeout(function(){
var mybtnJump = document.getElementsByClassName('inner clearfix');
mybtnJump[0].addEventListener('click',btnClick);
},600);
}
function copyClick(){
const textarea = document.createElement('textarea');
document.body.appendChild(textarea);
var str = new String;
for(var i = 0;i < urlList.length;i++){
textarea.innerHTML += urlList[i] + "\n";
}
textarea.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
alert("复制成功");
}
document.body.removeChild(textarea);
}
})();