-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotesearch-test.html
59 lines (54 loc) · 1.59 KB
/
quotesearch-test.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="post_body_html">
<blockquote>
no support sample text
</blockquote>
as per this
</div>
<div class="post_body_html">
<blockquote>
i am a potato fear me rawr
</blockquote>
wat
</div>
<p id="msg"></p>
</body>
<script type="text/javascript" id="test">
// TESTING PURPOSES ONLY, NOT OFFICIAL CODE
function test() {
var results = [];
var posts = document.getElementsByClassName("post_body_html");
for (var post, text, regex, test, i = 0; i < posts.length; i++) {
post = posts[i];
console.log("BEFORE SEARCH: "+post);
text = quotesearch(post);
console.log("AFTER SEARCH: "+text);
regex = /((?!you(?:'re|r)? )(?:not?|don'?t) )?(support|62807079593)(?!(?!.*[;:,.!]).*\?)/gi;
test = regex.exec(text);
console.log(test);
results.push(text);
}
document.getElementById("msg").innerHTML = "Test results:\n" + results.join("\n");
}
function quotesearch(post) {
var regex = /^(as per this|(?:i )?agreed?|\^+|\+\d+)$/gi;
var text = justtextpls(post).trim() || post.innerHTML;
var quotes = post.getElementsByTagName("blockquote");
while (quotes.length && (text=="" || regex.test(text))) {
post = quotes[0];
text = justtextpls(post).trim();
quotes = post.getElementsByTagName("blockquote");
}
return text;
}
function justtextpls(element) {
return element.cloneNode(false).innerHTML;
}
test();
</script>
</html>