Last active
August 29, 2015 14:25
-
-
Save emulsion-io/02549698af4a64419867 to your computer and use it in GitHub Desktop.
Ajoute du texte a la fin d'un c/c sur une page web avec possibilité d'envoyer la valeur c/c en ajax sur une api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) | |
{ | |
function CopyPasta() | |
{ | |
var commentaire = " : coucou : "; | |
var url = window.location.href; | |
var copy = window.getSelection(); | |
var brut = copy.toString(); | |
var divPaste = document.createElement('div'); | |
divPaste.style.display='none'; | |
divPaste.id ='CopyPast'; | |
$(divPaste).appendTo('body'); | |
divPaste.innerHTML = copy + commentaire + url; // On récupère la sélection et la source dans un div créé dans le body | |
copy.selectAllChildren(divPaste); | |
setTimeout(function(){ $('#CopyPast').remove(); }, 100); | |
$.ajax({ | |
type: "POST", | |
url: 'http://.../api/paste', | |
data: brut.toString(), | |
success: function(data, retour, xhr){ | |
// action si ok | |
}, | |
dataType: 'text' | |
}); | |
} | |
document.oncopy = CopyPasta; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment