Skip to content

Instantly share code, notes, and snippets.

node -v # => v8.1.1
node --harmony -e "r=require,h=r('http');h.createServer((q,s)=>{q.pipe(h.request({...q,...r('url').parse(q.url)},a=>{s.writeHead(a.statusCode,a.headers);a.pipe(s)}))}).listen(8081)"
@nash716
nash716 / gist:1498004
Created December 19, 2011 17:09
index_pickup.html
<script type="text/javascript">
var socket;
$(document).ready(function() {
socket = new io.Socket();
socket.connect();
// 接続成功
socket.on('connect', function() {
$('#select').show();
$('#status').text('サーバーと接続成功!');
});
@nash716
nash716 / gist:1497990
Created December 19, 2011 17:04
background_pickup.html
<html><head>
<script>
var url = 'http://localhost:12000/#receive';
var type;
chrome.tabs.onUpdated.addListener(function(id, info, tab) { // タブが更新されたときに呼ばれる
if (tab.url.match(url)) {
// 命令部分だけを取り出す
type = JSON.parse(tab.url.substring(url.length + 1)).type;
chrome.tabs.getAllInWindow(null, function(tabs) {
for (var i=0; i<tabs.length; i++) {
http://localhost:12000/#receive
↓ { type: 'aaa' } という情報を受信
URLが http://localhost:12000/#receive/{type:'aaa'} となったのち、http://localhost:12000/#receive に戻る
@nash716
nash716 / gist:1497669
Created December 19, 2011 15:25
index.html
<html><head>
<meta charset="utf-8">
<style type="text/css">
html {
height: 100%;
width: 100%;
display: table;
}
body {
height: 100%;
@nash716
nash716 / gist:1497542
Created December 19, 2011 14:54
background.html
<html><head>
<script>
var url = 'http://localhost:12000/#receive';
var type;
chrome.tabs.onUpdated.addListener(function(id, info, tab) { // タブが更新されたときに呼ばれる
if (tab.url.match(url)) {
// 命令部分だけを取り出す
type = JSON.parse(tab.url.substring(url.length + 1)).type;
chrome.tabs.getAllInWindow(null, function(tabs) {
for (var i=0; i<tabs.length; i++) {
@nash716
nash716 / gist:1497527
Created December 19, 2011 14:49
server.js
var io = require('socket.io');
var express = require('express');
var app = express.createServer();
app.configure(function(){
app.use(express.static(__dirname));
app.use(express.logger());
app.use(app.router);
});