Java Can JavaScript Bookmarklets Modify Text Selections and Clipboard Contents?

  • Thread starter Thread starter granpa
  • Start date Start date
  • Tags Tags
    Javascript
AI Thread Summary
The discussion centers on creating a JavaScript bookmarklet that can print a single Unicode character, such as a smiley face or a math symbol, directly to the clipboard or at the cursor position in a text area. One proposed method involves copying a specific string (like (SUB)), appending any highlighted text, and then adding a closing tag (/SUB) before pasting it into the current text area. A reference is made to a code snippet that demonstrates inserting text at the cursor location using JavaScript, although it is noted that the code may be complex for some users. Additionally, a JavaScript function is provided that replaces selected text with its ROT13 equivalent, showcasing how to manipulate text nodes within a selection. This highlights the potential for bookmarklets to enhance text editing capabilities in web applications.
granpa
Messages
2,268
Reaction score
7
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:
Technology news on Phys.org
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
4K
Replies
3
Views
2K
Replies
17
Views
319K
Replies
10
Views
10K
Replies
7
Views
3K
Replies
9
Views
3K
Back
Top