Advertisement
Guest User

Untitled

a guest
Mar 5th, 2012
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           attributator
  3. // @namespace      vVLA3S35ghTzQQfSakBFw2kF
  4. // @include        *
  5. // ==/UserScript==
  6.  
  7. /*usage:
  8.     - install as a greasemonkey script (rename it attributator.user.js)
  9.     - select some text
  10.     - press a key while the text is selected
  11.     - ctrl-c or cmd-c from the prompt
  12. */
  13.  
  14.  
  15. var attributator = {
  16.    
  17.     scriptRunner:function(){
  18.    
  19.         /*
  20.         function GetKeyPressed(e){
  21.             var evtobj=window.event? event : e;
  22.             var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
  23.             var actualkey=String.fromCharCode(unicode);
  24.             return actualkey;
  25.         } */
  26.  
  27.         function GetSelectedText(){
  28.             var txt = '';
  29.              if (window.getSelection)    {
  30.                 txt = window.getSelection();
  31.             }
  32.             else if (document.getSelection){
  33.                 txt = document.getSelection();
  34.             }
  35.             else if (document.selection){
  36.                 txt = document.selection.createRange().text;
  37.             }
  38.             else{
  39.                 return null;
  40.             }
  41.             return txt;
  42.         }
  43.        
  44.         function GetCurrentURL(){
  45.             return  window.location.host + "/" + window.location.pathname;
  46.         }
  47.        
  48.         window.addEventListener('mouseup', function(e){
  49.             var st = String(GetSelectedText());
  50.             var url = GetCurrentURL();
  51.             document.onkeypress = function(){
  52.                 if(st.length > 1){
  53.                     /*
  54.                     var kp = GetKeyPressed(e);
  55.                     alert(kp);
  56.                     if(kp == 'q'){
  57.                         var cite = st+' (via: '+url+')';
  58.                         window.prompt ("Copy to clipboard: Ctrl+C/Cmd-C, Enter", cite);
  59.                     } */
  60.                    
  61.                     var cite = st+' (via: '+url+')';
  62.                     window.prompt ("Copy to clipboard: Ctrl+C/Cmd-C, Enter", cite);
  63.                 }
  64.             }
  65.            
  66.             },
  67.         false);
  68.        
  69.     },
  70.    
  71.     init: function(){
  72.         var script = document.createElement("script");
  73.         script.textContent = "(" + this.scriptRunner + ")();";
  74.         document.body.appendChild(script);
  75.         return true;
  76.     }
  77.    
  78. }.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement