tweet-in-a-sign/public/index.html

82 lines
2.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tweet in a sign</title>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="skulpt.min.js" type="text/javascript"></script>
<script src="skulpt-stdlib.js" type="text/javascript"></script>
<style>
textarea {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">
var cont = 0;
function outf(text) {
console.log(text);
var mypre = document.getElementById("output");
mypre.innerHTML = mypre.innerHTML + text;
}
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
throw "File not found: '" + x + "'";
return Sk.builtinFiles["files"][x];
}
function runit() {
var text = document.getElementById("text").value;
var prog = `
text = "${text}"
items = text.split()
parts = []
part = ""
for x, item in enumerate(items):
if len(part + " " + item) > 18:
parts.append(part.center(22).rstrip())
part = ""
part = part + " " + item
parts.append(part.center(22).rstrip())
result = "\\n".join(parts)
figure = '''| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
{}
|___________|
\\ (•◡•) /
\\ /
| |'''.format(result)
print(figure)`;
var mypre = document.getElementById("output");
mypre.innerHTML = '';
Sk.pre = "output";
Sk.configure({output:outf, read:builtinRead});
var myPromise = Sk.misceval.asyncToPromise(function() {
return Sk.importMainWithBody("<stdin>", false, prog, true);
});
myPromise.then(function(mod) {
console.log('success');
document.getElementById("twitter-widget-"+cont).remove();
cont++;
document.body.innerHTML = document.body.innerHTML + '<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" id="tweet" data-text="'+document.getElementById("output").innerHTML+'" data-show-count="false">Tweet</a>';
var scriptFile = document.createElement('script');
scriptFile.type = 'text/javascript';
scriptFile.async = true;
scriptFile.src = '//platform.twitter.com/widgets.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptFile, s);
},
function(err) {
console.log(err.toString());
});
}
</script>
<input id="text" type="text"><button onclick="runit()">SIGN!!</button>
<br>
<textarea name="" id="output" cols="30" rows="10"></textarea>
<a href="//twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" id="tweet" data-text="nothing" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</body>
</html>