-
Notifications
You must be signed in to change notification settings - Fork 0
/
28082018index.js
executable file
·98 lines (79 loc) · 3.48 KB
/
28082018index.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
var tagSearchForArray = ['a', 'p'];
var attrInfo = document.querySelectorAll("a[href^='tel:']");
var elementsForSearch;
var pattern = /\D?[0-9]{3}\D?\s?[0-9]{3}\D?\s?[0-9]{4}/g;
var n = [];
for (var i = 0; i < tagSearchForArray.length; i++) {
elementsForSearch = document.getElementsByTagName(tagSearchForArray[i]);
for (var j = 0; j < elementsForSearch.length; j++) {
if (elementsForSearch[j].innerText.toLowerCase().match(pattern) != null) {
for (let value of elementsForSearch[j].innerText.toLowerCase().match(pattern)) {
// value = value.trim().replace(/[^\d\+]/g,"");
value = value.trim();
if (n.indexOf(value) == -1) {
n.push(value);
}
}
}
}
}
for(let key in attrInfo){
if(typeof attrInfo[key].href != "undefined" && attrInfo[key].href != "undefined"){
var ret = attrInfo[key].href.replace('tel:','');
// ret = ret.trim().replace(/[^\d\+]/g,"");
ret = ret.trim();
if(n.indexOf(ret) === -1){
n.push(ret);
}
}
}
function changeNumberOnDom(replaceNumberArr){
for(let key in replaceNumberArr){
var swap_targets = replaceNumberArr[key].swap_targets[0];
var trackingNumber = replaceNumberArr[key].number.national;
// var trackingNumber = replaceNumberArr[key].number.national_string;
// console.log("swap_targets::",swap_targets);
// console.log("trackingNumber::",trackingNumber);
// document.body.innerHTML = document.body.innerHTML.split(key).join(replaceNumberArr[key]);
document.body.innerHTML = document.body.innerHTML.split(swap_targets).join(trackingNumber);
}
}
function loadDoc() {
var xhttp = new XMLHttpRequest();
// xhttp.open("GET", "http://localhost:1337/number/swap?number="+n, true);
xhttp.open("GET", "http://18.208.54.106:1337/number/swap?number="+n, true);
xhttp.send(n.toString());
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(JSON.parse(this.responseText));
changeNumberOnDom(JSON.parse(this.responseText).data);
}
};
}
loadDoc();
// old code
// var tempObj = {
// "928-445-9233":"928-123-4567",
// "(928)-123-4567":"(928)-198-7654",
// "132-456-7890":"098-765-4321"
// }
// function changeNumberOnDom(replaceNumberObj){
// for(let key in replaceNumberObj){
// document.body.innerHTML = document.body.innerHTML.split(key).join(replaceNumberObj[key]);
// }
// }
// // allNumberPatterns();
// function loadDoc() {
// console.log("update data");
// changeNumberOnDom(tempObj);
// var xhttp = new XMLHttpRequest();
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// console.log("this.responseText::",this.responseText);
// // document.getElementById("replaceme").innerHTML = this.responseText;
// changeNumberOnDom(tempObj);
// }
// };
// xhttp.open("GET", "https://f3ad67de.ngrok.io/auth/sampleScrapApi?url="+window.location.href, true);
// xhttp.send();
// }