commit bde1492293821ac0f74fdd6325a5c25bc6aa9510
parent 1ad790a13d98e4b70b0afad2329e3b2c5a9fd04e
Author: Ryan Wolf <rwolf@borderstylo.com>
Date: Mon, 22 Feb 2010 16:57:20 -0800
PHP added, GM fantasy code altered to do a thing
Diffstat:
2 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/eensyweensy.php b/eensyweensy.php
@@ -0,0 +1,23 @@
+<?php
+// Copyright 2010 Ryan Wolf <rwolf@borderstylo.com>
+//
+// This file is part of eensyweensy and is released under the
+// Tumbolia Public License. See LICENSE for more details.
+
+if (!isset($_POST["data"])) {
+ echo "<pre>You need to feed me some DATA.\nDada Dada Dada.</pre>";
+ exit;
+}
+
+$data = json_decode(stripslashes($_REQUEST["data"]), true);
+$results = array();
+
+if (is_null($data["on_last_page"]) || !is_array($data["urls"])) {
+ $results["error"] = "validation error: missing on_last_page or urls";
+}
+else {
+ $results["error"] = "not really an error, success!";
+}
+
+echo json_encode($results);
+?>
diff --git a/eensyweensy.user.js b/eensyweensy.user.js
@@ -9,23 +9,22 @@
// Tumbolia Public License. See LICENSE for more details.
var Spider = function () {
+ // defaults
this.jquery = 'http://jquery.com/src/jquery-latest.js';
- this.home = 'http://google.com';
- this.grabber = function ($) {
- var data = { url: document.location.href; };
- return data;
- };
+ this.home = 'http://localhost/eensyweensy/eensyweensy.php';
+ this.grabber = function ($) {};
};
+
Spider.prototype.insert_jquery = function () {
/* source: http://joanpiedra.com/jquery/greasemonkey/ */
- var GM_JQ = doc.createElement('script');
- GM_JQ.src = this.;
+ var GM_JQ = document.createElement('script');
+ GM_JQ.src = this.jquery;
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
var that = this;
function GM_wait () {
if (typeof unsafeWindow.jQuery == 'undefined') {
- window.setTimeout(GM_wait,100);
+ window.setTimeout(GM_wait, 100);
}
else {
that.$ = unsafeWindow.jQuery;
@@ -34,29 +33,39 @@ Spider.prototype.insert_jquery = function () {
}
GM_wait();
};
+
Spider.prototype.grab_data = function ($) {
- var data = this.grabber(that.$);
+ var data = this.grabber(this.$);
this.phone_home(data);
};
+
Spider.prototype.phone_home = function (data) {
/* source: http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html */
GM_xmlhttpRequest({
method: 'POST',
- data: this.$.stringify(data),
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded"
+ },
+ data: "data=" + JSON.stringify(data),
url: this.home,
onload: this.handle_results,
});
};
+
Spider.prototype.handle_results = function (response) {
- alert(response.responseText);
+ var data = JSON.parse(response.responseText);
+ if (data.error) {
+ alert(data.error);
+ return;
+ }
};
+
Spider.prototype.go = function () {
this.insert_jquery();
};
-/* our fun starts here */
+// our particular spider
var spider = new Spider();
-spider.home = 'http://localhost/borderstylo_grabber.php'
spider.grabber = function ($) {
var urls = [];
$('.post-footer > a:nth-child(2)').each(function (i, node) {