Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

JavaScript Write a javascript bookmark

  1. Sep 30, 2008 #1
    can one write a javascript bookmark that will print a single unicode character (like a smiley face or a math symbol) to the clipboard (or better still straight to the cursor position)?

    how about print something like (SUB) to the clipboard then append what is highlighted to the clipboard then append (/SUB) to it then paste the clipboard to the current text area?
     
    Last edited: Sep 30, 2008
  2. jcsd
  3. Sep 30, 2008 #2
  4. Sep 30, 2008 #3
    Re: javascript/clipboard

    http://www.sitepoint.com/article/bookmarklets/

    Replaces each letter in the selected text with its rot13 equivalent

    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
     
    Last edited: Sep 30, 2008
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook