Commit 8e8c0c01 authored by 神楽坂玲奈's avatar 神楽坂玲奈

duels

parent ce53ecc9
upload = (files, callback) ->
file = files[0]
return unless file
reader = new FileReader()
$('#upload').attr 'disabled', true
reader.onload = (ev)->
$('#upload').attr 'disabled', false
window.location = url file.name.split('.')[0], base64.encode(ev.target.result).replace /[+\/=]/g, (m)->
switch m
when '+' then '-'
when '/' then '_'
when '=' then ''
reader.readAsBinaryString(file)
url = (name, replay, format='', scheme='http')->
"#{scheme}://my-card.in/duels/new#{format}?name=#{encodeURIComponent(name)}&replay=#{replay}"
$(document).ready ->
if $.url().param('replay')
template = Handlebars.compile $('#duel-template').html()
name = $.url().param('name')
replay = $.url().param('replay')
$('#duel').html template(name: name, url_yrp: url(name, replay, '.yrp'), url_mycard: url(name, replay, '.yrp', 'mycard') + "&name=#{encodeURIComponent(name)}.yrp")
$('#upload').change ->
upload @files
\ No newline at end of file
// Generated by CoffeeScript 1.4.0
(function() {
var upload, url;
upload = function(files, callback) {
var file, reader;
file = files[0];
if (!file) {
return;
}
reader = new FileReader();
$('#upload').attr('disabled', true);
reader.onload = function(ev) {
$('#upload').attr('disabled', false);
return window.location = url(file.name.split('.')[0], base64.encode(ev.target.result).replace(/[+\/=]/g, function(m) {
switch (m) {
case '+':
return '-';
case '/':
return '_';
case '=':
return '';
}
}));
};
return reader.readAsBinaryString(file);
};
url = function(name, replay, format, scheme) {
if (format == null) {
format = '';
}
if (scheme == null) {
scheme = 'http';
}
return "" + scheme + "://my-card.in/duels/new" + format + "?name=" + (encodeURIComponent(name)) + "&replay=" + replay;
};
$(document).ready(function() {
var name, replay, template;
if ($.url().param('replay')) {
template = Handlebars.compile($('#duel-template').html());
name = $.url().param('name');
replay = $.url().param('replay');
$('#duel').html(template({
name: name,
url_yrp: url(name, replay, '.yrp'),
url_mycard: url(name, replay, '.yrp', 'mycard') + ("&name=" + (encodeURIComponent(name)) + ".yrp")
}));
}
return $('#upload').change(function() {
return upload(this.files);
});
});
}).call(this);
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" xmlns="http://www.w3.org/1999/html"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>mycard 决斗录像分享</title>
<meta name="description" content="mycard duels">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/vendor/stylesheets/bootstrap.min.css">
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link rel="stylesheet" href="/assets/stylesheets/duels.css">
<script src="/vendor/javascripts/modernizr-2.6.2.min.js"></script>
<script id="duel-template" type="text/x-handlebars-template">
<span>{{name}}</span>
<a href="{{url_yrp}}" class="btn btn-primary btn-large">下载</a>
<a href="{{url_mycard}}" class="btn btn-primary btn-large">播放</a>
</script>
</head>
<body>
<!--[if lt IE 9]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">mycard duels</a>
<div class="nav-collapse collapse">
<!--<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form pull-right">
<input class="span2" type="text" placeholder="Email">
<input class="span2" type="password" placeholder="Password">
<button type="submit" class="btn">Sign in</button>
</form>
-->
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<!--<h1>Hello, world!</h1>-->
<p>这是一个开发中的决斗录像分享系统,现在,它只有基本的上传/下载/播放replay的功能。</p>
<p>上传后页面会自动跳转,您可以把地址分享给好友</p>
<p>如果安装了mycard,可以点击“播放”按钮直接播放,否则下载rep文件放到ygopro的replay目录中。</p>
<p>上传 <input id="upload" type="file" class="btn btn-primary btn-large" /></p>
<div id="duel"></div>
</div>
<!-- Example row of columns -->
<div class="row">
<div class="span4">
<h2>注意</h2>
<p>
这里所谓上传并不是真的传到服务器上,仅仅是把replay保存在了链接中,因此,您如果弄丢了链接,是无法找回的。
生成的链接很长,如果这妨碍到您分享,建议使用 <a href="https://goo.gl">goo.gl</a> 来短化链接,以后我们将集成这一服务。
</p>
</div>
<div class="span4">
<h2>浏览器支持</h2>
<p>我们推荐使用<a href="http://www.google.com/chrome">chrome浏览器</a>访问本站以达到最佳体验,如果您不方便更换浏览器,建议安装<a href="http://www.google.com/chromeframe">谷歌浏览器内嵌框架</a>
在开发阶段,我们将优先支持chrome,正式版本将会支持IE9或更高,以及chrome, firefox, opera的较新版本。
</p>
</div>
<div class="span4">
<h2>联系我们</h2>
<p>如果使用这个分享系统出现了什么问题,或者想帮助我们进行开发,请联系: <a href="mailto:zh99998@gmail.com">zh99998@gmail.com</a></p>
<!--<p><a class="btn" href="#">View details &raquo;</a></p>-->
</div>
</div>
<hr>
<footer>
<p>&copy; mycard 2013</p>
</footer>
</div> <!-- /container -->
<script src="/vendor/javascripts/jquery-1.8.2.min.js"></script>
<script src="/vendor/javascripts/jQuery-URL-Parser.js"></script>
<script src="/vendor/javascripts/base64.js"></script>
<script src="/vendor/javascripts/bootstrap.min.js"></script>
<script src="/vendor/javascripts/handlebars-1.0.rc.1.js"></script>
<script src="/assets/javascripts/duels.js"></script>
<script>
var _gaq=[['_setAccount','UA-29582484-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>
/*
* Copyright (c) 2010 Nick Galbreath
* http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/* base64 encode/decode compatible with window.btoa/atob
*
* window.atob/btoa is a Firefox extension to convert binary data (the "b")
* to base64 (ascii, the "a").
*
* It is also found in Safari and Chrome. It is not available in IE.
*
* if (!window.btoa) window.btoa = base64.encode
* if (!window.atob) window.atob = base64.decode
*
* The original spec's for atob/btoa are a bit lacking
* https://developer.mozilla.org/en/DOM/window.atob
* https://developer.mozilla.org/en/DOM/window.btoa
*
* window.btoa and base64.encode takes a string where charCodeAt is [0,255]
* If any character is not [0,255], then an DOMException(5) is thrown.
*
* window.atob and base64.decode take a base64-encoded string
* If the input length is not a multiple of 4, or contains invalid characters
* then an DOMException(5) is thrown.
*/
var base64 = {};
base64.PADCHAR = '=';
base64.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
base64.makeDOMException = function() {
// sadly in FF,Safari,Chrome you can't make a DOMException
var e, tmp;
try {
return new DOMException(DOMException.INVALID_CHARACTER_ERR);
} catch (tmp) {
// not available, just passback a duck-typed equiv
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error/prototype
var ex = new Error("DOM Exception 5");
// ex.number and ex.description is IE-specific.
ex.code = ex.number = 5;
ex.name = ex.description = "INVALID_CHARACTER_ERR";
// Safari/Chrome output format
ex.toString = function() { return 'Error: ' + ex.name + ': ' + ex.message; };
return ex;
}
}
base64.getbyte64 = function(s,i) {
// This is oddly fast, except on Chrome/V8.
// Minimal or no improvement in performance by using a
// object with properties mapping chars to value (eg. 'A': 0)
var idx = base64.ALPHA.indexOf(s.charAt(i));
if (idx === -1) {
throw base64.makeDOMException();
}
return idx;
}
base64.decode = function(s) {
// convert to string
s = '' + s;
var getbyte64 = base64.getbyte64;
var pads, i, b10;
var imax = s.length
if (imax === 0) {
return s;
}
if (imax % 4 !== 0) {
throw base64.makeDOMException();
}
pads = 0
if (s.charAt(imax - 1) === base64.PADCHAR) {
pads = 1;
if (s.charAt(imax - 2) === base64.PADCHAR) {
pads = 2;
}
// either way, we want to ignore this last block
imax -= 4;
}
var x = [];
for (i = 0; i < imax; i += 4) {
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) |
(getbyte64(s,i+2) << 6) | getbyte64(s,i+3);
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff));
}
switch (pads) {
case 1:
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | (getbyte64(s,i+2) << 6);
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff));
break;
case 2:
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12);
x.push(String.fromCharCode(b10 >> 16));
break;
}
return x.join('');
}
base64.getbyte = function(s,i) {
var x = s.charCodeAt(i);
if (x > 255) {
throw base64.makeDOMException();
}
return x;
}
base64.encode = function(s) {
if (arguments.length !== 1) {
throw new SyntaxError("Not enough arguments");
}
var padchar = base64.PADCHAR;
var alpha = base64.ALPHA;
var getbyte = base64.getbyte;
var i, b10;
var x = [];
// convert to string
s = '' + s;
var imax = s.length - s.length % 3;
if (s.length === 0) {
return s;
}
for (i = 0; i < imax; i += 3) {
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8) | getbyte(s,i+2);
x.push(alpha.charAt(b10 >> 18));
x.push(alpha.charAt((b10 >> 12) & 0x3F));
x.push(alpha.charAt((b10 >> 6) & 0x3f));
x.push(alpha.charAt(b10 & 0x3f));
}
switch (s.length - imax) {
case 1:
b10 = getbyte(s,i) << 16;
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) +
padchar + padchar);
break;
case 2:
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8);
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) +
alpha.charAt((b10 >> 6) & 0x3f) + padchar);
break;
}
return x.join('');
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment