Jump to content

Having trouble getting this to work properly


Guest Russ V
 Share

Recommended Posts

Guest Russ V

Right now I am trying to figure out why its only opening a blank window and not displaying the select text that is translated into base64. It's just blank. Any help is appreciated I dont know where else to go to get help. I am currently using Google Chrome.Is there something wrong or am I using something not supported by chrome?

javascript : var input = document.selection?document.selection.createRange().text : window.getSelection().toString();if (!input) {    input = prompt("Input text to convert:", "");}if (input != null) {    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";}var output = "";var chr1, chr2, chr3, enc1, enc2, enc3, enc;var i = 0;input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");do{    enc1 = keyStr.indexOf(input.charAt(i++));    enc2 = keyStr.indexOf(input.charAt(i++));    enc3 = keyStr.indexOf(input.charAt(i++));    enc4 = keyStr.indexOf(input.charAt(i++));    chr1 = (enc1 << 2) | (enc2 >> 4);    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);    chr3 = ((enc3 & 3) << 6) | enc4;    output = output + String.fromCharCode(chr1);    if (enc3 != 64) {        output = output + String.fromCharCode(chr2);    }    if (enc4 != 64) {        output = output + String.fromCharCode(chr3);    }}while (i < input.length);void 0; msgWindow = window.open("", "", "location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=547,height=442");msgWindow.document.write(output);return;

This a example of what I would like it to do just cant figure this out. The example is a rot13 version that changes any text you have selected into rot13 and back w/o the popup window of course.

javascript : var coding = "abcdefghijklmnopqrstuvwxyzabcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM";function rot13(t) {    for (var r = "", i = 0; i < t.length; i++)     {        character = t.charAt(i);        position = coding.indexOf(character);        if (position > - 1) {            character = coding.charAt(position + 13);        }        r += character;    }    return r;}S = window.getSelection();function t(N) {    return N.nodeType == N.TEXT_NODE;}function r(N) {    if (t(N)) {        N.data = rot13(N.data);    }}for (j = 0; j < S.rangeCount; ++j) {    var g = S.getRangeAt(j), e = g.startContainer, f = g.endContainer, E = g.startOffset, F = g.endOffset,     m = (e == f);    if (!m || !t(e))     {        /* rot13 each text node between e and f, not including e and f. */        q = document.createTreeWalker(g.commonAncestorContainer, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,         null, false);        q.currentNode = e;        for (N = q.nextNode(); N && N != f; N = q.nextNode()) {            r(N);        }    }    if (t(f)) {        f.splitText(F);    }    if (!m) {        r(f);    }    if (t(e)) {        r(k = e.splitText(E));        if (m) {            f = k;        }        e = k;    }    if (t(f)) {        g.setEnd(f, f.data.length);    }}void 0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...