-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLDJSON Product Scripting helper.js
More file actions
37 lines (35 loc) · 1.07 KB
/
Copy pathLDJSON Product Scripting helper.js
File metadata and controls
37 lines (35 loc) · 1.07 KB
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
// ==UserScript==
// @name LDJSON Product Scripting helper
// @namespace https://github.com/erfanva/
// @version 0.2
// @description try to take over the world!
// @author erfanva
// @match *://*/*
// @grant none
// @updateURL https://github.com/erfanva/Tools/raw/master/LDJSON%20Product%20Scripting%20helper.js
// ==/UserScript==
(function() {
'use strict';
// search ldJsons for Product
var ldJsons = document.querySelectorAll(
'script[type="application/ld+json"]'
);
var data = null;
ldJsons.forEach(function (item) {
try {
item = JSON.parse(item.innerText);
if (item['@type'] == 'Product') data = item;
else if (item['@graph']) {
item = item['@graph']
}
if(Array.isArray(item)) {
item.forEach(function (graph) {
if (graph['@type'] == 'Product') data = graph;
});
}
} catch (e) {
return null;
}
});
console.log(data || ldJsons);
})();