-
-
Save paulroub/c87f30e2aaad9cbdec6d to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name CodePen from Snippet | |
// @namespace http://roub.net/cpfs | |
// @version 0.3 | |
// @description adds a button to SO snippets to forward the snippet data to CodePen | |
// @author Paul Roub <paul@roub.net> | |
// @match http://stackoverflow.com/questions/* | |
// @grant none | |
// ==/UserScript== | |
function setUpButtons() { | |
$('.copySnippet').each( | |
function() { | |
var btn = $(this); | |
var ctr = btn.closest('.snippet-code'); | |
var html = ctr.children('.snippet-code-html').text(); | |
var js = ctr.children('.snippet-code-js').text(); | |
var css = ctr.children('.snippet-code-css').text(); | |
var datastr = JSON.stringify( | |
{ | |
'html': html, | |
'js': js, | |
'css': css, | |
'description': "Source: " + document.location.href, | |
'title': "Snippet from " + document.title | |
} | |
); | |
var form = $('<form action="http://codepen.io/pen/define" method="POST" target="_blank" style="display: inline-block">'); | |
$('<input type="hidden" name="data">'). | |
val(datastr). | |
appendTo(form); | |
$('<input class="cpSnippet" type="submit" value="Copy snippet to CodePen">'). | |
attr('style', btn.attr('style')). | |
appendTo(form); | |
form.insertAfter(btn); | |
} | |
) | |
} | |
setTimeout( setUpButtons, 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment