Skip to content

Instantly share code, notes, and snippets.

@divanvisagie
Last active December 12, 2015 01:28
Show Gist options
  • Save divanvisagie/4690778 to your computer and use it in GitHub Desktop.
Save divanvisagie/4690778 to your computer and use it in GitHub Desktop.
Scours through http://tweetping.net/ when pasted into your devtools console with the help of this lib - https://github.com/PaulKinlan/observables-js and collects all tweets processed by the site that contain longer than 10 digit text ( aimed an phone numbers ) or *@* ( aimed at emails ) whens someone is twitty enough to post them.
/* This is the observables.js library for your convenience */
(function (exports) {
"use strict";
var Observable, OnAnyChange;
OnAnyChange = function(properties, callback) {
var listener, i, property;
listener = function(val) {
if (typeof(callback) === "function") {
callback(val);
}
};
for(i = 0; i < properties.length; i += 1) {
property = properties[i];
property.addChangeListener(listener);
}
};
Observable = function(propertyName, _this, fn) {
var value, changeListeners, oldValue, i;
this.changeListeners = [];
changeListeners = this.changeListeners;
_this.__defineGetter__(propertyName, function() {
return value;
});
_this.__defineSetter__(propertyName, function(newVal) {
oldValue = _this[propertyName] || newVal;
value = newVal;
for (i = 0; i < changeListeners.length; i += 1) {
changeListeners[i].call(_this, newVal, oldValue);
if (typeof(fn) === 'function') {
fn(newVal, oldValue);
}
}
});
};
Observable.prototype.addChangeListener = function(callback) {
this.changeListeners.push(callback);
};
Observable.prototype.removeChangeListener = function(callback) {
var i = this.changeListeners.indexOf(callback);
this.changeListeners = this.changeListeners.splice(i, 1);
};
exports.Observable = Observable;
exports.OnAnyChange = OnAnyChange;
}(window));
/* This is where my code begins */
var elem = document.querySelectorAll( '.txt' )[0];
var _locationObserver = new Observable("innerHTML", elem );
_locationObserver.addChangeListener(function(newVal, oldVal) {
function hasContact(s) { /* I'm a moron at regex */
if ( /\d{10}/.test(s) ) return true;
else if ( /\w@\w/.test(s) ) return true;
else return false;
}
if ( hasContact( newVal ) )
console.log( 'message: ' , newVal );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment