Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Last active December 12, 2015 07:18
Show Gist options
  • Save ishiduca/4735811 to your computer and use it in GitHub Desktop.
Save ishiduca/4735811 to your computer and use it in GitHub Desktop.
http-cookies 用の cookie_jar.cookies を生成する Generator と Data
var data =
module.exports = {
domain: ('.pixiv.net www.pixiv.net i9.pixiv.net img.pixiv.net .pixiv.org').split(' ')
, path: ('/ /pro /profile /prototype /pro/file').split(' ')
, key: ('PHPSESSID node_session_id ID _id over18').split(' ')
, value: ('red <> blue <> black <> white <> yellow <> yelow hearts <> B&L <> abc=ABC;')
.split(' <> ')
};
var path = require('path')
, data = require(path.join( __dirname, 'data'))
;
var generator =
module.exports = function () {
return data.domain.reduce(function (jar, domain_) {
jar[domain_] = data.path.reduce(function (domain, path_) {
domain[path_] = data.key.reduce(function (pth, key_) {
pth[key_] = generate_cookie()
return pth;
}, {});
return domain;
}, {});
return jar;
}, {});
};
function generate_cookie () {
var cookie = {
value: data.value[
Math.round(Math.random() * 10) % data.value.length ]
};
var expires = generate_expires(); expires && (cookie.expires = expires);
flg() && (cookie.HttpOnly = '');
flg() && (cookie.Secure= '');
return cookie;
}
function generate_expires () {
if (flg())
return (new Date(
Date.now()
+ (1000 * 60 * Math.round(Math.random() * 100)) * (flg() ? 1 : -1)
)).toUTCString();
}
function flg () { return Math.round(Math.random() * 10) % 2 }
@ishiduca
Copy link
Author

ishiduca commented Feb 8, 2013

{
    ".pank.net": {
        "/": {
            "PHPSESSID": {
                "value": "abc ABC;",
                "HttpOnly": ""
            },
        }
    }
}

のような構造体を吐く

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment