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 / color
Last active July 18, 2017 02:11
控制台输出彩色字符
/**
* 获得带颜色转义字符的控制台输出模板.
* @param {String}tmpl 包含标签的模板字符串
* @param {boolean}isBright 是否高亮,default false
* @return {String}
* @public
*/
function getRichTmpl(tmpl, isBright){
if(typeof tmpl == 'object'){ return tmpl; }
var nodeStatic = require('node-static').Server;
var request = require("request");
var dns = require("dns");
var fileServer = new nodeStatic("./");
var http = require("http");
var httpServer = http.createServer(function(req, res) {
req.addListener('end', function() {
fileServer.serve(req, res, function(err, result) {
if (err && (err.status === 404)) {
var url = require("url");
var fs = require("fs");
var path = require("path");
var mime = require("./mime").types;
var config = require("./config");
var utils = require("./utils");
var zlib = require("zlib");
var staticHandler = function () {};
var http = require('http'),
url = require('url'),
path = require('path'),
fs = require('fs'),
config = require('./config.js')
var PORT = config.PORT;
var server = http.createServer(function (request, response) {
response.setHeader("Server", "ICBUNBSERVER");
var urlparse = require('url').parse
, http = require('http')
, fs = require('fs');
function upload(url, uploadfile, callback) {
var urlinfo = urlparse(url);
var options = {
method: 'POST',
host: urlinfo.host,
path: urlinfo.pathname
<!doctype html>
<html>
<head>
<!-- Run in full-screen mode. -->
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Make the status bar black with white text. -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@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(){
@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 / 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 / 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 );