Can JavaScript Bookmarklets Modify Text Selections and Clipboard Contents?

  • Java
  • Thread starter granpa
  • Start date
  • Tags
    Javascript
In summary, JavaScript bookmarklets have the capability to modify text selections and clipboard contents. This feature allows users to easily manipulate text on a webpage, such as changing its font or applying formatting. Additionally, bookmarklets can also copy selected text to the clipboard, making it easier to paste elsewhere. This functionality is particularly useful for web developers and power users who want to customize their browsing experience and streamline their workflow. However, it is important to note that JavaScript bookmarklets may not work on all websites due to security restrictions.
  • #1
granpa
2,268
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
  • #3
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:

What is a javascript bookmark?

A javascript bookmark is a small piece of code written in the javascript programming language that can be saved in a web browser to perform a specific task or function when clicked. This allows users to easily access and execute the code on any webpage they are currently viewing.

How do I create a javascript bookmark?

To create a javascript bookmark, you need to first open your web browser and navigate to the webpage where you want to save the bookmark. Then, you can right-click on your browser's bookmarks bar and select "Add Page" or "Add Bookmark". In the "URL" or "Location" field, you can enter the javascript code you want to save. Finally, click "Save" to create the bookmark.

What are some common uses for javascript bookmarks?

Javascript bookmarks can be used for a variety of purposes, such as automating tasks, modifying webpage content, or creating shortcuts for frequently used functions. For example, you can create a javascript bookmark to automatically fill in a form, highlight specific text on a webpage, or redirect to a different website.

Can I edit or delete a javascript bookmark?

Yes, you can edit or delete a javascript bookmark just like any other bookmark in your web browser. To edit a bookmark, you can right-click on it and select "Edit" or "Properties" to make changes to the code or URL. To delete a bookmark, you can right-click on it and select "Delete" or "Remove".

Is it safe to use javascript bookmarks?

Like any other piece of code, it is important to use caution when using javascript bookmarks. It is recommended to only use bookmarks from trusted sources and to thoroughly understand the code before saving it. Additionally, make sure to regularly update your bookmarks and delete any that are no longer needed to avoid potential security risks.

Similar threads

  • Feedback and Announcements
Replies
3
Views
852
  • Sticky
  • Engineering and Comp Sci Homework Help
Replies
1
Views
13K
  • Programming and Computer Science
Replies
4
Views
15K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
265
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
17
Views
316K
  • Computing and Technology
Replies
1
Views
7K
Back
Top