diff --git a/res/values/spoofs.xml b/res/values/spoofs.xml index 22e2efd..869f06b 100644 --- a/res/values/spoofs.xml +++ b/res/values/spoofs.xml @@ -55,4 +55,7 @@ All elements on websites fall to the bottom of the page Delete random words Words disappear from pages every second + + Change text + Replace words with others diff --git a/src/uk/digitalsquid/netspoofer/config/RunManager.java b/src/uk/digitalsquid/netspoofer/config/RunManager.java index 2a591aa..55ab41e 100644 --- a/src/uk/digitalsquid/netspoofer/config/RunManager.java +++ b/src/uk/digitalsquid/netspoofer/config/RunManager.java @@ -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; @@ -70,6 +71,8 @@ public ArrayList 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)); diff --git a/src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java b/src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java index 899b6c0..1e72b6b 100644 --- a/src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java +++ b/src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java @@ -47,7 +47,7 @@ private static String getDescription(Context context, int mode) { } } - private final int mode; + protected final int mode; private final String js; @@ -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; @@ -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 = diff --git a/src/uk/digitalsquid/netspoofer/spoofs/CustomTextChange.java b/src/uk/digitalsquid/netspoofer/spoofs/CustomTextChange.java index 9b56c2a..6266107 100644 --- a/src/uk/digitalsquid/netspoofer/spoofs/CustomTextChange.java +++ b/src/uk/digitalsquid/netspoofer/spoofs/CustomTextChange.java @@ -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; @@ -43,12 +42,14 @@ * @author Will Shackleton * */ -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 changeValues = new HashMap(8); @@ -134,14 +135,19 @@ public void onClick(DialogInterface dialog, int which) { } @Override - public Map 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; } } }