Skip to content

Commit

Permalink
Merge pull request #92 from TheM1984/feature/userscript.js-download-i…
Browse files Browse the repository at this point in the history
…nstead-of-textarea

Added download dialog to replace the textarea block
  • Loading branch information
stephangroen authored Dec 30, 2016
2 parents ab621e8 + 1e23e3c commit 744212a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
// ==/UserScript==

(function() {
var instant_download = false;

/** Add textarea to display php code **/
// Push current content to the left.
$('body > form').css('float', 'left');
$('body > form').css('width', '50%');
$('body > form').css('overflow', 'auto');

// Add textarea to body, css might need some work.
$('<a />', {
id : 'php_download',
text: 'Download Code',
style: 'margin: 10px; padding: 10px; color: white; background-color: red'
}).appendTo('body');

$('<br /><br />').appendTo('body');

$('<textarea/>', {
id : 'php',
style: 'min-height:800px; width: 47%; margin-left:10px;'
Expand Down Expand Up @@ -69,4 +79,17 @@
// Display php code
$('#php').text(phptxt);

})();
// Present the php code as a download
$('#php_download').attr("href",
URL.createObjectURL(
new Blob([phptxt], {
type: "text/plain"
})
)
).attr('download', classname + '.php');

if (instant_download)
{
$('#php_download')[0].click();
}
})();

0 comments on commit 744212a

Please sign in to comment.