-
Notifications
You must be signed in to change notification settings - Fork 2
/
Esty UK Product Data.user.js
113 lines (91 loc) · 4.02 KB
/
Esty UK Product Data.user.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
// ==UserScript==
// @name Etsy UK Product data
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Download product info from etsy
// @author Kowshika
// @match https://www.etsy.com/uk/listing
// @match https://www.etsy.com/uk/listing/*
// @match https://www.etsy.com/uk/shop/
// @match https://www.etsy.com/uk/shop/*
// @include https://www.etsy.com/uk/listing*
// @runat document-end
// @grant none
// ==/UserScript==
function has(String, search) { try { if (String.indexOf(search) > -1) { return true; } } catch (err) {} return false; }
function waitForElementToDisplay(selector, time) {
if(document.querySelector(selector) != null) {
console.log(selector + ' found');
return;
}
else {
setTimeout(function() {
waitForElementToDisplay(selector, time);
}, time);
}
}
(function() {
var textData = "";
function saveText(filename, text) {
var tempElem = document.createElement('a');
tempElem.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
tempElem.setAttribute('download', filename);
tempElem.click();
console.log(filename + ' File downloaded');
}
function sleep(ms) { return new Promise(res => setTimeout(res, ms)); };
let sleepFunc = async function() { await sleep(3000); };
document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } };
sleepFunc();
document.onreadystatechange = function () {
if (document.readyState == "complete") {
waitForElementToDisplay('#content', 5000);
waitForElementToDisplay('#collage-footer', 5000);
$(window).on('load', function() {
if (has(window.location.href, '/listing/')){
var a = document.querySelector('script[type="application/ld+json"]');
var obj = JSON.parse(a.text);
var category = obj.category;
var shopname = obj.brand;
a = document.querySelector('meta[property="etsymarketplace:shop"]');
var shopurl = a.content;
console.log(obj);
textData += shopurl + " | "
textData += shopname
textData += " | "
textData += shopurl
textData += " | "
textData += category
textData += " | "
textData += window.location.href.split("?")[0] + " | "
if (textData.length > 10){
saveText("listingData.txt", textData);
} else {
console.log('No Data found.')
}
window.location.href = shopurl;
}
if (has(window.location.href, '/shop/')){
var owner = ""; var ownerurl = ""; var location = "";
try {owner = document.getElementByXPath("//h2[text()='Shop owner']//following::div[@data-editable-img='user-avatar']//a/p").textContent; } catch(err) { }
try {ownerurl = document.getElementByXPath("//h2[text()='Shop owner']//following::div[@data-editable-img='user-avatar']//a").href; } catch(err) { }
try {location = document.getElementByXPath("//*[@data-key='user_location']").textContent; } catch(err) { }
console.log(owner);
textData += window.location.href.split("?")[0] + " | "
textData += owner
textData += " | "
textData += ownerurl
textData += " | "
textData += location
textData += " | "
if (textData.length > 10){
saveText("ShopData.txt", textData);
} else {
console.log('No Data found.')
}
}
});
}
}
console.log('Page loaded');
})();