Skip to content

Instantly share code, notes, and snippets.

@Kenny2github
Last active August 2, 2020 18:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kenny2github/a25dff9c52c90d6f062209df43ef0200 to your computer and use it in GitHub Desktop.
Save Kenny2github/a25dff9c52c90d6f062209df43ef0200 to your computer and use it in GitHub Desktop.
Copy Scratch comment links
// ==UserScript==
// @name Comment IDs
// @version 0.1
// @description Get Scratch comment IDs
// @author Kenny2github
// @match https://scratch.mit.edu/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @updateURL https://gist.githubusercontent.com/Kenny2github/a25dff9c52c90d6f062209df43ef0200/raw/copy-comment.user.js
// ==/UserScript==
function copyText(text) {
var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = 0;
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}
waitForKeyElements('.comment[id]', function(comment){
comment = comment.get(0);
var content = comment.querySelector('.content, .comment-content');
content.innerHTML += '<hr/>';
content.innerHTML += '(<a>Comment ID: ' + (comment.dataset.commentId || comment.id.substr(9)) + '</a>&nbsp;';
content.innerHTML += '|&nbsp;<a onclick="var text = \'' + window.location.origin + window.location.pathname + '#comments-' + (comment.dataset.commentId || comment.id.substr(9)) + '\';' + ('' + copyText).substring(25, 793) + '">Copy Link</a>)';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment