-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from w-shackleton/html
HTML manipulation features
- Loading branch information
Showing
9 changed files
with
216 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/uk/digitalsquid/netspoofer/spoofs/ContentChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
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 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"; | ||
} | ||
} | ||
private static String getDescription(Context context, int mode) { | ||
switch(mode) { | ||
case MODE_FLIP: | ||
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 ""; | ||
} | ||
} | ||
|
||
protected 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; | ||
} | ||
} | ||
|
||
/** | ||
* 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; | ||
case MODE_GRAVITY: | ||
case MODE_DELETE: | ||
document.select("head").append(js); | ||
break; | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Recursively modifies an element according to mode. | ||
* @param element | ||
*/ | ||
private void modifyElement(Element element) { | ||
for(Node node : element.childNodes()) { | ||
if(node instanceof TextNode) { | ||
modifyTextNode((TextNode) node); | ||
} else if(node instanceof Element) { | ||
modifyElement((Element) node); | ||
} | ||
} | ||
} | ||
|
||
protected void modifyTextNode(TextNode node) { | ||
switch(mode) { | ||
case MODE_FLIP: | ||
String reversed = | ||
new StringBuilder(node.text()).reverse().toString(); | ||
node.text(Lists.map(TitleChange.upsideDown, reversed)); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[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); | ||
|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters