Skip to content

Commit

Permalink
Added a couple of remaining missing spoofs
Browse files Browse the repository at this point in the history
  • Loading branch information
w-shackleton committed May 12, 2014
1 parent 031d5f4 commit 9a33d95
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
3 changes: 3 additions & 0 deletions res/values/spoofs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@
<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>

<string name="spoof_textchange">Change text</string>
<string name="spoof_textchange_description">Replace words with others</string>
</resources>
3 changes: 3 additions & 0 deletions src/uk/digitalsquid/netspoofer/config/RunManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import uk.digitalsquid.netspoofer.proxy.NSProxy;
import uk.digitalsquid.netspoofer.spoofs.ContentChange;
import uk.digitalsquid.netspoofer.spoofs.CustomGalleryImageChange;
import uk.digitalsquid.netspoofer.spoofs.CustomTextChange;
import uk.digitalsquid.netspoofer.spoofs.ImageSpoof;
import uk.digitalsquid.netspoofer.spoofs.MultiSpoof;
import uk.digitalsquid.netspoofer.spoofs.NullSpoof;
Expand Down Expand Up @@ -70,6 +71,8 @@ public ArrayList<Spoof> getSpoofList() {
spoofs.add(new VideoChange(context, true));
spoofs.add(new VideoChange(context, false));

spoofs.add(new CustomTextChange(context));

spoofs.add(new RedirectSpoof(context, RedirectSpoof.MODE_BLUEBALL));
spoofs.add(new RedirectSpoof(context, RedirectSpoof.MODE_CUSTOM));

Expand Down
17 changes: 15 additions & 2 deletions src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static String getDescription(Context context, int mode) {
}
}

private final int mode;
protected final int mode;

private final String js;

Expand All @@ -73,10 +73,23 @@ public ContentChange(Context context, int mode) {
break;
}
}

/**
* If using a custom mode it MUST NOT collide with existing modes.
* @param title
* @param description
* @param mode
*/
protected ContentChange(String title, String description, int mode) {
super(title, description);
js = "";
this.mode = mode;
}

@Override
protected void modifyDocument(Document document, Element body) {
switch(mode) {
default: // To allow custom implementations to pass through
case MODE_FLIP:
modifyElement(body);
break;
Expand All @@ -102,7 +115,7 @@ private void modifyElement(Element element) {
}
}

private void modifyTextNode(TextNode node) {
protected void modifyTextNode(TextNode node) {
switch(mode) {
case MODE_FLIP:
String reversed =
Expand Down
34 changes: 20 additions & 14 deletions src/uk/digitalsquid/netspoofer/spoofs/CustomTextChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import java.util.HashMap;
import java.util.Map;

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

import uk.digitalsquid.netspoofer.R;
import android.app.AlertDialog;
Expand All @@ -43,12 +42,14 @@
* @author Will Shackleton <[email protected]>
*
*/
public class CustomTextChange extends HtmlEditorSpoof {
public class CustomTextChange extends ContentChange {
private static final long serialVersionUID = 8490503138296852028L;

private static final int MODE = 1005;

public CustomTextChange() {
// TODO: Localise
super("Text change", "Change all text on all websites");
public CustomTextChange(Context context) {
super(context.getResources().getString(R.string.spoof_textchange),
context.getResources().getString(R.string.spoof_textchange_description), MODE);
}

private final Map<String, String> changeValues = new HashMap<String, String>(8);
Expand Down Expand Up @@ -134,14 +135,19 @@ public void onClick(DialogInterface dialog, int which) {
}

@Override
public Map<String, String> getCustomEnv() {
return changeValues;
}

@Override
protected void modifyDocument(Document document, Element body) {
if(body != null) {

protected void modifyTextNode(TextNode node) {
super.modifyTextNode(node);
switch(mode) {
case MODE:
String text = node.text();
for(int i = 0 ; i < 8; i++) {
String from = changeValues.get(String.format("TEXT%dOLD", i));
String to = changeValues.get(String.format("TEXT%dNEW", i));
if(from != null && to != null)
text = text.replace(from, to);
}
node.text(text);
break;
}
}
}

0 comments on commit 9a33d95

Please sign in to comment.