Skip to content

Instantly share code, notes, and snippets.

@furugomu
Created February 14, 2012 12:22
Show Gist options
  • Save furugomu/1826434 to your computer and use it in GitHub Desktop.
Save furugomu/1826434 to your computer and use it in GitHub Desktop.
神撃のバハムートを PC で遊ぼう!
// usage: node proxy.js
var http = require('http'),
httpProxy = require('http-proxy');
var userScripts = [
// 神撃のバハムートの PC 拒否を突破
function() {
window.ontouchstart = function(){};
window.orientation = 0;
},
// バレンタイン藍子を通常藍子に
function() {
addEventListener('DOMContentLoaded', function(e) {
if (!window.$) return;
var rx = /(%2F3[01])021(0[12]\.jpg)/i;
$('img')
.filter(function() {
return this.src.match(rx);
})
.each(function() {
this.src = this.src.replace(rx, '$1002$2');
});
}, false);
}
].map(function(x){ return '('+x.toString()+')();'}).join("\n");
function filter(req, res) {
// User Agent を iPhone にする
req.headers['user-agent'] = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3";
// HTML だったらスクリプトを差し込む
var writeHead = res.writeHead;
res.writeHead = function(code, headers) {
for (var key in headers) {
res.setHeader(key, headers[key]);
}
var type = res.getHeader('content-type');
if (type && type.indexOf('/html') >= 0) {
console.log('replace', req.url);
var write = res.write;
var script = "<script>"+userScripts+"</script>";
res.write = function (data) {
write.call(res, data.toString().replace("<head>", "<head>"+script));
}
}
writeHead.call(res, code);
}
}
httpProxy.createServer(function (req, res, proxy) {
var url = require('url').parse(req.url);
req.url = url.path;
if (url.host.match(/mbga\.jp$/)) {
filter(req, res);
}
proxy.proxyRequest(req, res, {
host: url.host,
port: url.port || 80,
});
}).listen(9393);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment