Skip to content

Instantly share code, notes, and snippets.

View jtyjty99999's full-sized avatar

Adams jtyjty99999

  • Tencent
  • Shenzhen China
View GitHub Profile
@jtyjty99999
jtyjty99999 / gist:8862415
Last active August 29, 2015 13:56
彩蛋制造器
感觉cheet.js挺有意思的,制造页面彩蛋,随便写了一个
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
var keys = {
backspace: 8,
tab: 9,
enter: 13,
'return': 13,
shift: 16,
'⇧': 16,
control: 17,
ctrl: 17,
'⌃': 17,
@jtyjty99999
jtyjty99999 / gist:8862498
Created February 7, 2014 13:18
测试输入法事件composition
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input type="text" name="" id="hello">
<script>
@jtyjty99999
jtyjty99999 / gist:8877103
Created February 8, 2014 05:28
利用xhr2得到文件,转为bolb存储到localstorage中
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR, Blob and FileReader objects
var xhr = new XMLHttpRequest(),
@jtyjty99999
jtyjty99999 / gist:9087540
Created February 19, 2014 07:28
切换多语言
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
[data-i18n="hello"]:before {
content: "Hello Maksim!";
}
@jtyjty99999
jtyjty99999 / gist:9521482
Created March 13, 2014 03:27
鼠标移动方向
$(".overlayLink").bind("mouseenter mouseleave",function(e){
/** the width and height of the current div **/
var w = $(this).width();
var h = $(this).height();
/** calculate the x and y to get an angle to the center of the div from that x and y. **/
/** gets the x value relative to the center of the DIV and "normalize" it **/
var x = (e.pageX - this.offsetLeft - (w/2)) * ( w > h ? (h/w) : 1 );
var y = (e.pageY - this.offsetTop - (h/2)) * ( h > w ? (w/h) : 1 );
@jtyjty99999
jtyjty99999 / storefile
Created March 18, 2014 02:32
保存一个外部域的图片
var img = new Image,
canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
src = "http://example.com/image"; // 外部域中的图片url
img.crossOrigin = "Anonymous";
img.onload = function() {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage( img, 0, 0 );
@jtyjty99999
jtyjty99999 / no referer.js
Last active August 29, 2015 13:57
点击链接不发送referer
//用window.open的方式打开一个中转页面,再在里面执行代码打开(新窗口打开)
function open_new_window(full_link){
window.open('javascript:window.name;', '<script>location.replace("'+full_link+'")<\/script>');
}
//其中location.replace刷新页面的方式也可以替换成html自刷新的方式
var html = '<html><head><meta http-equiv='Refresh' content='0; URL=" 路径 + "' /></head><body></body></html>'
@jtyjty99999
jtyjty99999 / html to canvas
Created March 18, 2014 07:27
html转图片
<!DOCTYPE html>
<html>
<body>
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px'>" +
@jtyjty99999
jtyjty99999 / parseUrl
Created March 25, 2014 05:27
另类解析url
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){