-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkitty.js
More file actions
180 lines (129 loc) · 5.23 KB
/
kitty.js
File metadata and controls
180 lines (129 loc) · 5.23 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
console.log("kitty");
$(function () {
/*
$.getScript("https://www.parsecdn.com/js/parse-1.2.18.min.js", function () {
// setTimeout (function () {
// google.load("search", "1");
// }, 1000);
console.log('loaded parse');
Parse.initialize("sKVxInRYIY3tRWXF6JWu8XuD5zLrtokBQO7i4V6X", "8AyKwmtCy6ByEYv96snwdDZzL3GftwzuJGlfDvWS");
var TestObject = Parse.Object.extend("TestObject");
var testObject = new TestObject();
testObject.save({foo: "bar"}).then(function(object) {
alert("yay! it worked");
});
*/
//Parse.initialize("sKVxInRYIY3tRWXF6JWu8XuD5zLrtokBQO7i4V6X", "8AyKwmtCy6ByEYv96snwdDZzL3GftwzuJGlfDvWS");
});
document.onkeydown = function(event) {
//console.log(google.load);
// NOTE: the close curly brace is key 221
setTimeout(function( ) {
if (event.keyCode === 221) {
scan();
}
}, 100);
};
function replaceTargetWith(elt, html){
/// find our target
// var i, div, elm, last, target = document.getElementById(targetID);
// /// create a temporary div
// div = document.createElement('div');
// /// fill that div with our html, this generates our children
// div.innerHTML = html.replace(/"/g, "");
// /// step through the temporary div's children and insertBefore our target
// i = div.childNodes.length;
// /// the insertBefore method was more complicated than I first thought so I
// /// have improved it. Have to be careful when dealing with child lists as they
// /// are counted as live lists and so will update as and when you make changes.
// /// This is why it is best to work backwards when moving children around,
// /// and why I'm assigning the elements I'm working with to `elm` and `last`
// last = target;
// while(i--){
// target.parentNode.insertBefore((elm = div.childNodes[i]), last);
// last = elm;
// }
/// remove the target.
// elt.parent().append($("<img src='http://4.bp.blogspot.com/_naR8H83E0A4/TJ1Q9zZuAfI/AAAAAAAAAFA/bfbzLBJ7RQ0/s1600/kitty1-922835.jpeg'></img>"));
console.log('not removing shit');
var parent = elt.parent();
// console.log(elt);
console.log(elt.first());
console.log($(elt.first()).text());
console.log(/{{.+}}/.exec(elt.first().text()));
//document.getElementByClassName
// elt.first().val('cock');
// elt.prepend("<img src='http://4.bp.blogspot.com/_naR8H83E0A4/TJ1Q9zZuAfI/AAAAAAAAAFA/bfbzLBJ7RQ0/s1600/kitty1-922835.jpeg' />");
// elt.parentNode.removeChild(target);
}
function grabImageUrl (queryString, callback) {
console.log('kjfsdkjfhskdjhfjkshdkfhksdhfksd')
queryString = 'purple monkey'
$.get("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=monkey").done(function(data) {
//console.log(data);
console.log(JSON.parse(data['responseData']['results'][0]).responseText);
var imageData = data['responseData']['results'][0].responseText;
//console.log(imageData);
var imageUrl = imageData['url'];
callback(imageUrl);
//console.log(imageUrl);
callback(imageUrl);
}).error(function (data) {
var results = JSON.parse(data.responseText);
console.log(data.responseText);
var imageData = results['responseData']['results'][0];
//console.log(imageData);
var imageUrl = imageData['url'];
callback(imageUrl);
console.log(imageUrl);
});
//console.log(window.google);
// google.load("search", "1");
//console.log(google.load);
//searches google for the url of the first image returned when you search this string
setTimeout(function() {
callback('https://4.bp.blogspot.com/_naR8H83E0A4/TJ1Q9zZuAfI/AAAAAAAAAFA/bfbzLBJ7RQ0/s1600/kitty1-922835.jpeg');
}, 0);
}
var getTextNodesIn = function(el) {
return $(el).find(":not(iframe)").addBack().contents().filter(function() {
return this.nodeType == 3;
});
};
function getDeepestElement (cb) {
$(".editable").each(function(index) {
that = this;
getTextNodesIn($(this)).each(function(childindex) {
if(/{{.+}}/.exec($(this).text())) {
//console.log($(this));
var blah = $(this).text();
var blah2 = blah.replace(/{{.+}}/, "");
$(this).text(blah2);
that.replaceChild(document.createTextNode(blah2), this);
grabImageUrl("kittycat", function(image) {
console.log('adding kitty');
var img = document.createElement('img');
/// fill that div with our html, this generates our children
img.src = image;
$(that).append(img);
});
// cb($(this));
}
});
});
}
function scan() {
console.log('scanning');
//locate targetID of the double bracket value shit
//call the html function on that shit
getDeepestElement(function(elt) {
console.log(elt);
replaceTargetWith(elt,"<img src='https://4.bp.blogspot.com/_naR8H83E0A4/TJ1Q9zZuAfI/AAAAAAAAAFA/bfbzLBJ7RQ0/s1600/kitty1-922835.jpeg'></img>");
});
}
// returns the string without the text found in
// the curly braces. NOTE: You may get a couple of
// extra spaces because of this function. #YOLO
function stripString(string) {
//return x.replace(/{{(.*?)}}/, "");
}