Skip to content

Instantly share code, notes, and snippets.

@htom78
Created May 22, 2012 07:07
Show Gist options
  • Save htom78/2767243 to your computer and use it in GitHub Desktop.
Save htom78/2767243 to your computer and use it in GitHub Desktop.
douban common, use as: Do('common')
(function () {
var a = /http:\/\/movie.douban.com\/sogou_search|http:\/\/audit.douban.com/;
if (self !== top && document.referrer.search(a) === -1) {
top.location = self.location
}
})();
if (top.location !== self.location && document.referrer.search(/http:\/\/[^\/]+\.douban\.com/i) !== 0) {
top.location = self.location
}
var Douban = Douban || {};
var set_cookie_with_domain = function (g, f, d, e) {
var b = new Date(),
a, c;
b.setTime(b.getTime() + ((f || 30) * 24 * 60 * 60 * 1000));
a = "; expires=" + b.toGMTString();
for (c in g) {
document.cookie = c + "=" + g[c] + a + "; domain=" + (d || "douban.com") + "; path=" + (e || "/")
}
};
var stat = function (b, h, c, a, f) {
var e = ["ref=" + encodeURIComponent(location.pathname)];
for (var d in h) {
e.push(d + "=" + h[d])
}
var g = {};
g[c] = e.join("&");
set_cookie_with_domain(g, a, f)
};
var moreurl = function (a, d, c, b) {
stat(a, d, "report", 0.001, b);
if (c) {
stat(a, d, "entry", 1 / 24 / 6, b)
}
};
var set_cookie = function (e, d) {
d = d || 30;
var b = new Date();
b.setTime(b.getTime() + (d * 24 * 60 * 60 * 1000));
var a = "; expires=" + b.toGMTString();
for (var c in e) {
document.cookie = c + "=" + e[c] + a + "; path=/"
}
};
var get_cookie = function (b) {
var e = b + "=";
var a = document.cookie.split(";");
for (var d = 0; d < a.length; d++) {
var f = a[d];
while (f.charAt(0) === " ") {
f = f.substring(1, f.length)
}
if (f.indexOf(e) === 0) {
return f.substring(e.length, f.length).replace(/\"/g, "")
}
}
return null
};
var paras = function (c) {
var d = {};
if (c.indexOf("?") === -1) {
return {}
}
var e = c.split("?")[1].split("&");
for (var b = 0; b < e.length; b++) {
if (e[b].indexOf("=") !== -1) {
var a = e[b].split("=");
d[a[0]] = a[1]
}
}
return d
};
$("html").click(function (c) {
var a = $(c.target),
b = a.attr("class");
if (!b) {
return
}
$(b.match(/a_(\w+)/gi)).each($.proxy(function (d, f) {
var e = Douban[f.replace(/^a_/, "init_")];
if (typeof e === "function") {
c.preventDefault();
e.call(this, c)
}
}, a[0]))
});
$.postJSON_withck = function (a, b, c) {
$.post_withck(a, b, c, "json")
};
$.post_withck = function (a, c, d, b) {
if ($.isFunction(c)) {
b = d;
d = c;
c = {}
}
return $.ajax({
type: "POST",
url: a,
data: $.extend(c, {
ck: get_cookie("ck")
}),
success: d,
dataType: b || "text"
})
};
(function () {
var a = {};
$.tmpl = function (d, c) {
var b = a[d] = a[d] || new Function("obj", "var p=[];with(obj){p.push('" + d.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%\})/g, "\t").split("'").join("\\'").split("\t").join("'").replace(/\{%=(.+?)%\}/g, "',$1,'").split("{%").join("');").split("%}").join("p.push('") + "');}return p.join('');");
return b(c)
}
})();
try {
document.execCommand("BackgroundImageCache", false, true)
}
catch (err) {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment