-
-
Save nes1983/6659301 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Reverse Web | |
// @namespace http://www.example.com | |
// @grant | |
// ==/UserScript== | |
function reverseWordButKeepCase(str) { | |
var buffer = ""; | |
for (var i = 0, j = str.length - 1; i < str.length; i++, j--) { | |
if (str.charAt(i) == str.charAt(i).toUpperCase()) { | |
buffer += str.charAt(j).toUpperCase(); | |
} | |
else { | |
buffer += str.charAt(j).toLowerCase(); | |
} | |
} | |
return buffer; | |
} | |
function reverseText(str) { | |
return str.replace(/\w+/g,reverseWordButKeepCase) | |
} | |
var path = "//text()[not(ancestor::script or ancestor::style)]" | |
var arr = document.evaluate(path, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0; i < arr.snapshotLength; i++) { | |
var each = arr.snapshotItem(i) | |
each.textContent = reverseText(each.textContent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment