Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name attributator
- // @namespace vVLA3S35ghTzQQfSakBFw2kF
- // @include *
- // ==/UserScript==
- /*usage:
- - install as a greasemonkey script (rename it attributator.user.js)
- - select some text
- - press a key while the text is selected
- - ctrl-c or cmd-c from the prompt
- */
- var attributator = {
- scriptRunner:function(){
- /*
- function GetKeyPressed(e){
- var evtobj=window.event? event : e;
- var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
- var actualkey=String.fromCharCode(unicode);
- return actualkey;
- } */
- function GetSelectedText(){
- var txt = '';
- if (window.getSelection) {
- txt = window.getSelection();
- }
- else if (document.getSelection){
- txt = document.getSelection();
- }
- else if (document.selection){
- txt = document.selection.createRange().text;
- }
- else{
- return null;
- }
- return txt;
- }
- function GetCurrentURL(){
- return window.location.host + "/" + window.location.pathname;
- }
- window.addEventListener('mouseup', function(e){
- var st = String(GetSelectedText());
- var url = GetCurrentURL();
- document.onkeypress = function(){
- if(st.length > 1){
- /*
- var kp = GetKeyPressed(e);
- alert(kp);
- if(kp == 'q'){
- var cite = st+' (via: '+url+')';
- window.prompt ("Copy to clipboard: Ctrl+C/Cmd-C, Enter", cite);
- } */
- var cite = st+' (via: '+url+')';
- window.prompt ("Copy to clipboard: Ctrl+C/Cmd-C, Enter", cite);
- }
- }
- },
- false);
- },
- init: function(){
- var script = document.createElement("script");
- script.textContent = "(" + this.scriptRunner + ")();";
- document.body.appendChild(script);
- return true;
- }
- }.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement