Skip to content

Instantly share code, notes, and snippets.

@pagetronic
Last active May 18, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pagetronic/f65aa82d82964f2b7757077063f05437 to your computer and use it in GitHub Desktop.
Save pagetronic/f65aa82d82964f2b7757077063f05437 to your computer and use it in GitHub Desktop.
Add source link to copy/paste copyfuckers
var copy = function () {
var article = document.getElementById('article');
if (article != null) {
article.addEventListener('copy', function (e) {
e.preventDefault();
try {
var selection = window.getSelection();
e.clipboardData.setData('text/plain', $('<div/>').html(selection + "").text() + "\n\n" + 'Source: ' + document.location.href);
e.clipboardData.setData('text/html', selection + '<br /><br />Source: <a href="' + document.location.href + '">' + document.title + '</a>');
} catch (err) {
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment