Guest User

Untitled

a guest
Dec 17th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. (function() {
  2. function convert(inText) {
  3. var outText = '';
  4. var t;
  5. for (i = 0; i < inText.length; i++) {
  6. t = inText.charCodeAt(i);
  7. if ((t > 64 && t < 78) || (t > 96 && t < 110)) {
  8. t += 13;
  9. } else if ((t > 77 && t < 91) || (t > 109 && t < 123)) {
  10. t -= 13;
  11. }
  12. outText += String.fromCharCode(t);
  13. }
  14. return outText;
  15. }
  16. var sel = window.getSelection().getRangeAt(0);
  17. if (sel == '') {
  18. var act = document.activeElement;
  19. if (act.type == "textarea") {
  20. var start = act.selectionStart,
  21. end = act.selectionEnd;
  22. if (start != end) {
  23. var prefix = act.value.substring(0, start);
  24. var middle = convert(act.value.substring(start, end));
  25. var suffix = act.value.substring(end);
  26. act.value = prefix;
  27. act.value += middle;
  28. void(act.value += suffix);
  29. }
  30. } else {
  31. void(inText = prompt('Phrase...', ''));
  32. if (inText) alert(convert(inText));
  33. }
  34. } else {
  35.  
  36. var S = window.getSelection();
  37.  
  38. function t(N) {
  39. return N.nodeType == N.TEXT_NODE;
  40. }
  41.  
  42. function r(N) {
  43. if (t(N)) {
  44. N.data = convert(N.data);
  45. }
  46. }
  47. for (j = 0; j < S.rangeCount; ++j) {
  48. var g = S.getRangeAt(j);
  49. var e = g.startContainer;
  50. var f = g.endContainer;
  51. var E = g.startOffset;
  52. var F = g.endOffset;
  53. var m = (e == f);
  54. if (!m || !t(e)) { /* rot13 each text node between e and f, not including e and f. */
  55. q = document.createTreeWalker(g.commonAncestorContainer, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, null, false);
  56. q.currentNode = e;
  57. for (N = q.nextNode(); N && N != f; N = q.nextNode()) r(N);
  58. }
  59. if (t(f)) {
  60. f.splitText(F);
  61. }
  62. if (!m) {
  63. r(f);
  64. }
  65. if (t(e)) {
  66. r(k = e.splitText(E));
  67. if (m) f = k;
  68. e = k;
  69. }
  70. if (t(f)) {
  71. g.setEnd(f, f.data.length);
  72. }
  73. }
  74.  
  75. }
  76. })();
  77.  
  78.  
  79. //minified and ready to be a bookmarklet
  80. javascript:(function(){function%20e(e){var%20t,n="";for(i=0;i<e.length;i++)(t=e.charCodeAt(i))>64&&t<78||t>96&&t<110?t+=13:(t>77&&t<91||t>109&&t<123)&&(t-=13),n+=String.fromCharCode(t);return%20n}function%20t(e){return%20e.nodeType==e.TEXT_NODE}function%20n(n){t(n)&&(n.data=e(n.data))}if(""==window.getSelection().getRangeAt(0)){var%20r=document.activeElement;if("textarea"==r.type){var%20a=r.selectionStart,o=r.selectionEnd;if(a!=o){var%20l=r.value.substring(0,a),u=e(r.value.substring(a,o)),d=r.value.substring(o);r.value=l,r.value+=u,r.value+=d}}else%20inText=prompt("Phrase...",""),inText&&alert(e(inText))}else{var%20s=window.getSelection();for(j=0;j<s.rangeCount;++j){var%20c=s.getRangeAt(j),f=c.startContainer,g=c.endContainer,v=c.startOffset,T=c.endOffset,E=f==g;if(!E||!t(f))for(q=document.createTreeWalker(c.commonAncestorContainer,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null,!1),q.currentNode=f,N=q.nextNode();N&&N!=g;N=q.nextNode())n(N);t(g)&&g.splitText(T),E||n(g),t(f)&&(n(k=f.splitText(v)),E&&(g=k),f=k),t(g)&&c.setEnd(g,g.data.length)}}})();
Add Comment
Please, Sign In to add comment