-
-
Save devxan/3ebe278b8dd0194414ad8f986866fbe3 to your computer and use it in GitHub Desktop.
Copy Scratch comment links
This file contains hidden or 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
// ==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> '; | |
content.innerHTML += '| <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