Skip to content

Commit

Permalink
Added word deletion spoof
Browse files Browse the repository at this point in the history
  • Loading branch information
w-shackleton committed May 12, 2014
1 parent 6ea17e7 commit 031d5f4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
18 changes: 18 additions & 0 deletions res/raw/js_removewords
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
allTextNodes = $("body *").contents().filter(function() {
return this.nodeType == 3;
});

var changeText = function() {
var node = allTextNodes[Math.floor(Math.random() * allTextNodes.length)];
var words = node.nodeValue.split(" ");
words.splice(Math.floor(Math.random() * words.length),1);
node.nodeValue = words.join(" ");
setTimeout(changeText, "400");
};
setTimeout(changeText, "2000");
});
</script>
3 changes: 2 additions & 1 deletion res/values/spoofs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

<string name="spoof_content_flip">Flip content</string>
<string name="spoof_content_flip_description">Turn the content of all websites upside down</string>

<string name="spoof_gravity">Websites experience gravity</string>
<string name="spoof_gravity_description">All elements on websites fall to the bottom of the page</string>
<string name="spoof_delete">Delete random words</string>
<string name="spoof_delete_description">Words disappear from pages every second</string>
</resources>
13 changes: 8 additions & 5 deletions src/uk/digitalsquid/netspoofer/config/IOHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -40,12 +41,14 @@ private IOHelpers() {}
* @throws IOException
*/
public static final String readFileContents(InputStream is) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[256];
for (int n; (n = is.read(b)) != -1;) {
out.append(new String(b, 0, n));
StringWriter out = new StringWriter();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while((line = reader.readLine()) != null) {
out.append(line);
out.append('\n');
}
is.close();
reader.close();
return out.toString();
}

Expand Down
1 change: 1 addition & 0 deletions src/uk/digitalsquid/netspoofer/config/RunManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public ArrayList<Spoof> getSpoofList() {

spoofs.add(new ContentChange(context, ContentChange.MODE_FLIP));
spoofs.add(new ContentChange(context, ContentChange.MODE_GRAVITY));
spoofs.add(new ContentChange(context, ContentChange.MODE_DELETE));

Collections.sort(spoofs);

Expand Down
39 changes: 35 additions & 4 deletions src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
package uk.digitalsquid.netspoofer.spoofs;

import java.io.IOException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;

import uk.digitalsquid.netspoofer.R;
import uk.digitalsquid.netspoofer.config.IOHelpers;
import uk.digitalsquid.netspoofer.config.Lists;
import uk.digitalsquid.netspoofer.config.LogConf;
import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.util.Log;

public class ContentChange extends HtmlEditorSpoof {
public class ContentChange extends HtmlEditorSpoof implements LogConf {

private static final long serialVersionUID = 792590861534877480L;
public static final int MODE_FLIP = 1;
public static final int MODE_GRAVITY = 2;
public static final int MODE_DELETE = 3;

private static String getTitle(Context context, int mode) {
switch(mode) {
case MODE_FLIP:
return context.getResources().getString(R.string.spoof_content_flip);
case MODE_GRAVITY:

return context.getResources().getString(R.string.spoof_gravity);
case MODE_DELETE:
return context.getResources().getString(R.string.spoof_delete);
default:
return "Unknown image spoof";
}
Expand All @@ -32,16 +40,38 @@ private static String getDescription(Context context, int mode) {
return context.getResources().getString(R.string.spoof_content_flip_description);
case MODE_GRAVITY:
return context.getResources().getString(R.string.spoof_gravity_description);
case MODE_DELETE:
return context.getResources().getString(R.string.spoof_delete_description);
default:
return "";
}
}

private final int mode;

private final String js;

public ContentChange(Context context, int mode) {
super(getTitle(context, mode), getDescription(context, mode));
this.mode = mode;
switch(mode) {
default:
case MODE_GRAVITY:
js = "<script src=\"http://gravityscript.googlecode.com/svn/trunk/gravityscript.js\"></script>";
break;
case MODE_DELETE:
String payload = "";
try {
payload = IOHelpers.readFileContents(
context.getResources().openRawResource(R.raw.js_removewords));
} catch (NotFoundException e) {
Log.w(TAG, "Failed to load js_removewords payload", e);
} catch (IOException e) {
Log.w(TAG, "Failed to load js_removewords payload", e);
}
js = payload;
break;
}
}

@Override
Expand All @@ -51,9 +81,10 @@ protected void modifyDocument(Document document, Element body) {
modifyElement(body);
break;
case MODE_GRAVITY:
document.select("head").append(
"<script src=\"http://gravityscript.googlecode.com/svn/trunk/gravityscript.js\"></script>");
case MODE_DELETE:
document.select("head").append(js);
break;

}
}

Expand Down

0 comments on commit 031d5f4

Please sign in to comment.