Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created June 21, 2009 12:19
Show Gist options
  • Save miya2000/133493 to your computer and use it in GitHub Desktop.
Save miya2000/133493 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<script>
window.onload = function () {
opera.io.webserver.addEventListener('download', download, false);
}
function download(e) {
var req = e.connection.request;
var res = e.connection.response;
if (req.queryItems && req.queryItems.url) {
var url = req.queryItems.url[0];
var x = new XMLHttpRequest();
x.open('GET', 'http://software.hixie.ch/utilities/cgi/data/data?type=text%2Fhtml&base64=1&uri=' + encodeURIComponent(url), false);
x.send(null);
try {
var dir = opera.io.filesystem.mountSystemDirectory('storage');
var stream = dir.open('/image_download/' + (url.slice(url.lastIndexOf('/') + 1) || 'hoge.png'), opera.io.filemode.WRITE);
stream.writeBase64(decodeURIComponent(x.responseText.replace(/[\s\S]*?base64,/m, '').replace(/["'][\s\S]*/m, '')));
stream.close();
}
catch (e) {
opera.postError(e);
}
}
res.write('<html><body>downloaded.</body></html>');
res.close();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment