-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguide.html
130 lines (81 loc) · 3.77 KB
/
guide.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<html>
<head>
<title>Query Making Guide</title>
<link rel="stylesheet" href="syntaxhighlighter_3.0.83/styles/shCore.css" type="text/css"/>
<link rel="stylesheet" href="syntaxhighlighter_3.0.83/styles/shThemeDefault.css" type="text/css"/>
<script type="text/javascript" src="syntaxhighlighter_3.0.83/scripts/shCore.js"></script>
<script type="text/javascript" src="syntaxhighlighter_3.0.83/scripts/shBrushJScript.js"></script>
</head>
<body>
<script type="text/javascript">SyntaxHighlighter.all()</script>
<h3>Query Making Guide</h3>
So here are some things you'll need.<br><br>
MESSAGES is an array containing all of the chat messages that have been sent.<br>
They're stored as objects (associative arrays) with three properties: text, time, and sender.<br>
<pre class="brush: js">/* messageText will be "what's up fagnuts" or something similar. */
var messageText = MESSAGES[0].text;
/* messageSender will be "Alan Turing", or someone else's name. */
var messageSender = MESSAGES[0].sender;
/* A date in the form of miliseconds from the epoch.
Can be fed to a Date object to get something actually readable. */
var readableDate = new Date(MESSAGES[0].time);</pre>
An alternative way to access message data is through the PROFILES object/associative array.<br>
At the index of each name, it stores an array of all of that user's messages.<br>
<pre class="brush: js">/* This is how to get a list of all messages I've sent. */
var allOfAnthonysMessages = PROFILES["Alan Turing"];
/* Extracting the text from one of my messages */
var singleMessageText = allOfAnthonysMessages[0].text;</pre>
If I wanted to get all the keys from PROFILES, I would do it like this:
<pre class="brush: js">/* Creating a list of everyone's names. */
var listOfAllNames = [];
for (var name in PROFILES) {
listOfAllNames.push(name);
}</pre>
Once you have a message, you can use a toString function I've provided to make it pretty:
<pre class="brush: js">/* Writes a beautiful message out to the console. */
console.log(toString(MESSAGES[0]));</pre>
<br>
<hr>
<br>
The main portion of the page you're going to want to modify with your queries<br>
(right of the sidebar) can be accessed like so:
<pre class="brush: js">/* Making the right part of the document easy to reach */
var queryArea = document.getElementById("text");</pre>
Here's an example query that modifies that section of the page.<br>
This particular example will write out all messages containing links I've ever posted.<br>
<pre class="brush: js">var allOfAnthonysMessages = PROFILES["Alan Turing"];
var anthonysLinks = [];
/* Separate the 'haves' from the 'have-nots' */
for (var i = 0; i < allOfAnthonysMessages.length; i++) {
/* evaluates to true if it finds http:// in the message */
if (allOfAnthonysMessages[i].text.indexOf("http://") != -1) {
anthonysLinks.push(allOfAnthonysMessages[i]);
}
}
/* Empty the page of any prior content. */
removeChildren(queryArea);
/* Add the messages to the document. */
for (var i = 0; i < anthonysLinks.length; i++) {
queryArea.appendChild(toString(anthonysLinks[i]));
}
</pre>
<!-- Here's all the code for the links query in one place:
var queryArea = document.getElementById("text");
var allOfAnthonysMessages = PROFILES["Alan Turing"];
var anthonysLinks = [];
/* Separate the 'haves' from the 'have-nots' */
for (var i = 0; i < allOfAnthonysMessages.length; i++) {
/* evaluates to true if it finds http:// in the message */
if (allOfAnthonysMessages[i].text.indexOf("http://") != -1) {
anthonysLinks.push(allOfAnthonysMessages[i]);
}
}
/* Empty the page of any prior content. */
removeChildren(queryArea);
/* Add the messages to the document. */
for (var i = 0; i < anthonysLinks.length; i++) {
queryArea.appendChild(toString(anthonysLinks[i]));
}
-->
</body>
</html>