-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelcro-detector.js
92 lines (87 loc) · 3.17 KB
/
velcro-detector.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
// ==UserScript==
// @name Velcro Detector
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Velcro detector in Amazon for item name, bullets and description
// @author Josh
// @match https://www.amazon.com/dp/*
// @match https://www.amazon.com/gp/*
// @match https://www.amazon.com/*/gp/*
// @match https://www.amazon.com/*/dp/*
// @match https://www.amazon.com/product/*
// @grant GM_notification
// @grant GM_addStyle
// @run-at document-end
// ==/UserScript==
let findText = "Velcro";
let vText = new RegExp('(\\w*' + findText + '\\w*)','gi');
let counter = 0;
let elementArray = ["productTitle","feature-bullets","productDescription","olpProductDetails", "aplus3p_feature_div"];
let pageDetails = "";
(function() {
'use strict';
for(var i=0; i<elementArray.length;i++){
if(document.body.contains(document.getElementById(elementArray[i]))){
executeVelcroFinder(elementArray[i]);
}
}
if(counter>0){
console.log("Found Velcro on Amazon.");
document.title = "Velcro Found!";
let options = {
title: "Warning",
text: "Found Velcro on Amazon. Please check the " + pageDetails.substr(0,pageDetails.length-2) + "!",
timeout: 5000,
image: "https://png.icons8.com/color/64/000000/high-priority.png"
}
GM_addStyle(".velcroText { background-color: yellow; color: red; font-weight: bold; }");
GM_notification(options,null);
errorIcon();
//addFavicon();
counter = 0; //set counter back to zero
}else{
successIcon();
console.log("No Velcro found on Amazon!");
}
})();
function executeVelcroFinder(elementID){
var elementText = this.document.getElementById(elementID).innerHTML.match(vText);
if(elementText != null){
document.getElementById(elementID).innerHTML = this.document.getElementById(elementID).innerHTML.replace(vText, "<span class='velcroText'>Velcro</span>");
pageDetails = pageDetails + getDetail(elementID) + ", ";
counter++;
}
}
function getDetail(elementID){
if(elementID=="productTitle"){
return "Title";
}else if(elementID=="feature-bullets"){
return "Bullets";
}else if(elementID=="productDescription"){
return "Description";
}else if(elementID=="aplus3p_feature_div"){
return "EBC";
}else{
return "Offer Listing Details"
}
}
function errorIcon(){
var favicon_link_html = document.createElement('link');
favicon_link_html.rel = 'icon';
favicon_link_html.href = 'https://png.icons8.com/color/64/000000/high-priority.png';
favicon_link_html.type = 'image/png';
try {
document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
}
catch(e) { }
}
function successIcon(){
var favicon_link_html = document.createElement('link');
favicon_link_html.rel = 'icon';
favicon_link_html.href = 'https://png.icons8.com/color/64/000000/ok.png';
favicon_link_html.type = 'image/png';
try {
document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
}
catch(e) { }
}