Posted By

noah on 05/01/07


Tagged

javascript text copy clipboard bookmarklets paste bookmarking javascript-pseudo-protocol


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mikegreen


Summarize Web page bookmarklet


 / Published in: JavaScript
 

Grabs the URL, TITLE, and selected text (if any) from the current page. Then makes a new window with a TEXTAREA and pastes the text into the new window.

This version was designed to work with a client's Jira installation, so it filters the identifying string off the end of titles.

In practice this bookmarklet will work on any Web page.

  1. //url-escaped, ready for use:
  2. javascript:function%20userSel()%7Bif%20(window.getSelection)%7Btxt%20=%20window.getSelection();%7Delse%20if%20(document.getSelection)%20%20%20%20%7Btxt%20=%20document.getSelection();%7Delse%20if%20(document.selection)%7Btxt%20=%20document.selection.createRange().text;%7Delse%20return;%20%20return%20txt;%7Dfunction%20add(h)%7Bb.appendChild(h);%7Dfunction%20makeTag(t)%7Breturn%20document.createElement(t);%7Dfunction%20makeText(tag,text)%7Bt=makeTag(tag);%20t.appendChild(document.createTextNode(text));%20return%20t;%7Dp=document.location;%20q=document.title.replace(/%5C[[%5E%5C]]*%5C](.*)%20-%20JAG%20JIRA/,%20'$1');%20d=window.open().document;%20d.open();%20d.close();%20b=d.body;%20d.title%20=%20q%20+%20'%20:%20summary%20:%20JIRA';%20u=p+'%5Cn'+q+'%5Cn'+userSel();%20add(makeText('style',%20'textarea%7Bwidth:100%;height:100%;%7D'));%20add(makeText('textarea',%20u));%20void%200
  3.  
  4.  
  5. //unescaped, with line breaks
  6. javascript: function userSel() {
  7. if (window.getSelection) {
  8. txt = window.getSelection();
  9. } else if (document.getSelection) {
  10. txt = document.getSelection();
  11. } else if (document.selection) {
  12. txt = document.selection.createRange().text;
  13. } else return;
  14. return txt;
  15. }
  16. function add(h) {
  17. b.appendChild(h);
  18. }
  19. function makeTag(t) {
  20. return document.createElement(t);
  21. }
  22. function makeText(tag, text) {
  23. t = makeTag(tag);
  24. t.appendChild(document.createTextNode(text));
  25. return t;
  26. }
  27. p = document.location;
  28. q = document.title.replace(/\[[^\]]*\](.*) - JAG JIRA/, '$1');
  29. d = window.open().document;
  30. d.open();
  31. d.close();
  32. b = d.body;
  33. d.title = q + ' : summary : JIRA';
  34. u = p + '\n' + q + '\n' + userSel();
  35. add(makeText('style', 'textarea{width:100%;height:100%;}'));
  36. add(makeText('textarea', u));
  37. void 0;

Report this snippet  

You need to login to post a comment.