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

82 lines
2.9 KiB
HTML
Raw Permalink Normal View History

2018-10-18 04:14:24 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tweet in a sign</title>
2018-10-18 15:05:12 +00:00
<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>
2018-10-18 04:14:24 +00:00
</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 = '''| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
{}
|___________|
2018-10-19 04:49:08 +00:00
\\ (•◡•) /
\\ /
| |'''.format(result)
2018-10-18 04:14:24 +00:00
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;
2018-10-18 04:44:29 +00:00
scriptFile.src = '//platform.twitter.com/widgets.js';
2018-10-18 04:14:24 +00:00
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptFile, s);
},
function(err) {
console.log(err.toString());
});
}
</script>
2018-10-18 15:07:02 +00:00
<input id="text" type="text"><button onclick="runit()">SIGN!!</button>
2018-10-18 04:14:24 +00:00
<br>
<textarea name="" id="output" cols="30" rows="10"></textarea>
2018-10-18 04:44:29 +00:00
<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>
2018-10-18 04:14:24 +00:00
</body>
</html>