Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
彩云小译油猴脚本,添加按钮开启翻译!
// ==UserScript==
// @name 彩云小译
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 彩云小译自制脚本
// @author github@weaming
// @include *
// @grant none
// ==/UserScript==
/* 按钮控制是否开启翻译 */
// 1. Create the button
var button = document.createElement("button");
button.innerHTML = "彩云小译";
var css = button.style;
css.position = 'fixed';
css.width = '80px';
css.height = '80px';
css.right = '20px';
css.bottom = '50px';
css.background = '#02B677';
css['border-radius'] = '40px';
css.border = 'none';
// 2. Append somewhere
var body = document.getElementsByTagName("body")[0];
body.appendChild(button);
// 3. Add event handler
button.addEventListener("click", function () {
button.innerHTML = '翻译中';
run();
});
/*下面是从360极速浏览器彩云小译插件拷贝的脚本代码trs.js . */
function run() {
!function (e) {
function t(r) {
if (n[r])
return n[r].exports;
var i = n[r] = {
exports: {},
id: r,
loaded: !1
};
return e[r].call(i.exports, i, i.exports, t),
i.loaded = !0,
i.exports
}
var n = {};
return t.m = e,
t.c = n,
t.p = "",
t(0)
}
([function (e, exports, t) {
!function () {
function e() {
try {
var e = document.querySelectorAll(".cyxy-target-popup");
if (e && e.length > 0)
return;
F.preload([P.XIAOYI_DEFAULT_URL, P.FAVOR_IMG_URL, P.CHECKED_IMG_URL, P.LEFT_SLIDE_URL, P.RIGHT_SLIDE_URL]),
p(),
o(),
u(),
r(),
setTimeout(function () {
n(),
setInterval(function () {
n()
}, 3e3)
}, 9e3)
} catch (e) {
console.error(e)
}
}
function n() {
document.URL.indexOf("slack.com") >= 0 || location.origin + location.pathname != be && (console.log("url changed!!!"), s(), be = location.origin + location.pathname)
}
function r() {
var e = document.createElement("iframe");
e.src = ("https:" == document.location.protocol ? "https://" : "http://") + "caiyunapp.com/xiaoyi/web_translate_data_stat.html",
e.setAttribute("style", "display: none;"),
document.body.appendChild(e);
var t = t || [];
window._vds = t,
function () {
t.push(["setAccountId", "d8ab7616d8a24605b6bd7635943734a7"]),
function () {
var e = document.createElement("script");
e.type = "text/javascript",
e.async = !0,
e.src = ("https:" == document.location.protocol ? "https://" : "http://") + "dn-growing.qbox.me/vds.js";
var t = document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(e, t)
}
()
}
()
}
function i() {
var e = ["interpreter.caiyunai.com", "cdn.caiyunapp.com", "interpreter-staging.caiyunai.com"],
t = "web";
return e.indexOf(location.host) >= 0 ? (t = "share", U("a").on("click", function (e) {
this.href && "#" != this.getAttribute("href")[0] && (e.preventDefault(), window.open(P.LNADING_URL + "?targetUrl=" + encodeURIComponent(this.href)))
})) : k() && window.js ? t = "android" : L() ? (Se = window.cyUserData ? window.cyUserData : U("#cy-ios-user").text(), t = Se ? "ios" : "web") : t = "web",
t
}
function o() {
if ("share" == Ee)
(new I).get(function (e, t) {
ge = e,
s()
});
else if ("android" == Ee)
try {
var e = JSON.parse(window.js.getUserData());
me = e.device_id,
e.user && (xe = {
username: e.user.username || "",
_id: e.user._id || "",
avatar_url: e.user.avatar_url || P.DEFAULT_AVATAR_URL
}, Ae = e.user._id || ""),
s()
} catch (e) {
console.error(e),
D.open({
content: te + e,
skin: "msg",
time: 5
})
}
else if ("ios" == Ee)
try {
var e = JSON.parse(decodeURIComponent(Se));
me = e.device_id || "",
ve = e.lang || "zh",
e.user && (xe = {
username: e.user.username || "",
_id: e.user._id || "",
avatar_url: e.user.avatar_url || P.DEFAULT_AVATAR_URL
}, Ae = e.user._id || ""),
s()
} catch (e) {
console.error(e),
D.open({
content: te + e,
skin: "msg",
time: 5
})
}
else
B.testCookie(function (e) {
e ? (Ae = e._id, a(Ae, function (e) {
xe = e,
e && !e.avatar_url && (xe.avatar_url = P.DEFAULT_AVATAR_URL),
s()
})) : (new I).get(function (e, t) {
ge = e,
s()
})
})
}
function a(e, t) {
var n = O(),
r = P.TRS_URL + "/v1/user/" + e;
n.open("POST", r, !0),
n.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
n.timeout = 3e4,
n.setRequestHeader("content-type", "application/json"),
n.onload = function (e) {
var n = JSON.parse(this.responseText);
0 == n.rc ? t(n.user) : D.open({
content: ne,
skin: "msg",
time: 3
})
},
n.send(JSON.stringify({
user_id: Ae,
page_id: ye,
url: document.URL
}))
}
function s() {
var e = O(),
t = P.TRS_URL + "/v1/page/auth";
e.open("POST", t, !0),
e.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
e.timeout = 3e3,
e.setRequestHeader("content-type", "application/json"),
e.onerror = function (t) {
throw console.error(e, t),
D.open({
content: $,
skin: "msg",
time: 3
}),
new Error("PageAuth Error", t)
},
e.onload = function (e) {
var t = JSON.parse(this.responseText),
n = t.auth_type;
0 == t.rc ? n >= 0 && ("android" == Ee ? window.js.showSpendCMoney(V, "") : "ios" == Ee ? window.webkit.messageHandlers.showSpendCMoney.postMessage({
title1: V,
title2: ""
}) : D.open({
className: H,
content: V,
skin: "msg",
time: 2.3
}), ye = t.page_id, x(), setTimeout(function () {
c()
}, 4e3), "android" == Ee ? window.js.cancelLoading() : "ios" == Ee && window.webkit.messageHandlers.removeLoadingView.postMessage()) : n == -1 ? "android" == Ee ? window.js.showLoginDialog(z) : "ios" == Ee ? window.webkit.messageHandlers.showLoginDialog.postMessage({
title: z
}) : D.open({
content: z,
btn: ["登录", "取消"],
yes: function (e) {
D.close(e),
window.open(P.LOGIN_URL, "_blank")
}
}) : n == -101 && ("android" == Ee ? window.js.showOpeningVIPDialog(J) : "ios" == Ee ? window.webkit.messageHandlers.showOpeningVIPDialog.postMessage({
title: J
}) : D.open({
content: J,
btn: ["成为VIP", "取消"],
yes: function (e) {
B.alipayForOneMonthRedeem(Ae, function (e) {
0 == e.rc && e.alipay.notify_url ? window.open(e.alipay.notify_url, "_blank") : D.open({
content: ee,
skin: "msg",
time: 3
})
}),
D.close(e)
}
}))
},
e.send(JSON.stringify({
user_id: Ae,
browser_id: ge,
device_id: me,
url: document.URL,
title: document.title
}))
}
function u() {
if (!(location.host.indexOf("bing.com") >= 0 || location.host.indexOf("wx.qq.com") >= 0 || location.host.indexOf("slack.com") >= 0)) {
var e = document.createElement("div");
e.className = "cyxy-footer " + H,
e.innerHTML = "<p class='cyxy-footer-p'>本网页由彩云小译<font id='cyxy-footer-translator'></font>翻译<p/>",
"share" == Ee && (e.innerHTML = "<p class='cyxy-footer-p'>原网页由彩云小译<font id='cyxy-footer-translator'></font>翻译<p/>"),
document.body.appendChild(e)
}
}
function l() {
var e = U("#cyxy-footer-translator").text(),
t = "",
n = "",
r = "、";
e.indexOf(xe.username) < 0 && (e || (r = "", t = "和", n = "共同"), U("#cyxy-footer-translator").text(t + xe.username + r + e + n))
}
function c(e) {
var t = O(),
n = P.TRS_URL + "/v1/page/" + ye + "/author";
t.open("POST", n, !0),
t.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
t.timeout = 5e3,
t.setRequestHeader("content-type", "application/json"),
t.onload = function (e) {
var t = JSON.parse(this.responseText);
if (0 == t.rc) {
var n = t.user_list,
r = n.length,
i = "",
o = "",
a = "";
n.forEach(function (e, t) {
if (e.username && "彩云小译" != e.username) {
var n = "、";
o = "和",
a = "共同",
i = i + e.username + n
}
}),
i = i.substr(0, i.length - 1),
r > 9 && (i += "等"),
U("#cyxy-footer-translator").text(o + i + a);
var s = (U(".cyxy-footer-p").text(), 9e3);
"和" == o && U(".cyxy-footer").show(),
"share" == Ee && (U(".cyxy-footer").show(), U(".cyxy-footer").click(function () {
location.href = P.DOWNLOAD_URL
}), s = 3e4),
setTimeout(function () {
U(".cyxy-footer").css({
opacity: .88
}),
U(".cyxy-footer").hide()
}, s)
}
},
t.onerror = function (e) {
throw console.error(e),
new Error("fetchPageTranslator Error", e)
},
t.send(JSON.stringify({
user_id: Ae
}))
}
function p() {
function e() {
var e = parseInt(U("#cyxy-popup-favour-num").text()) + 1;
U("#cyxy-popup-favour-num").text(e),
M.data("comment", "like");
var t = M.data("targetInfo");
t && (t.rate.LIKE = e, M.data("targetInfo", t));
var n = M.data("targetList"),
r = M.data("index");
n && n.length > 0 && r >= 0 && (n[r].rate.lIKE = e, M.data("targetList", n))
}
function t() {
U("#cyxy-popup-oppose-num").text(parseInt(U("#cyxy-popup-oppose-num").text()) + 1),
M.data("comment", "unlike")
}
var n = document.createElement("div");
n.className = "cyxy-target-popup " + H,
n.innerHTML = '<div style="margin: auto"><img id="cyxy-popup-left-slide" src="https://caiyunapp.com/imgs/webtrs/left-slide.png"> <div id="cyxy-popup-userinfo"><img id="cyxy-popup-avatar" src="https://caiyunapp.com/imgs/xiaoyilogo.jpg"> <div id="cyxy-popup-name-time"> <span id="cyxy-popup-name">彩云小译</span> <span id="cyxy-popup-time">刚刚</span></div></div><div id="cyxy-popup-favour"><img id="cyxy-popup-favour-img" src="https://caiyunapp.com/images/favour.png"><span id="cyxy-popup-favour-num">0</span></div><img id="cyxy-popup-right-slide" src="https://caiyunapp.com/imgs/webtrs/right-slide.png"></div>',
document.body.appendChild(n),
U(".cyxy-target-popup").hide(),
U("#cyxy-popup-left-slide").hide(),
U("#cyxy-popup-right-slide").hide(),
U(".cyxy-target-popup").click(function () { }),
U(document).mouseup(function (e) {
var t = U(".cyxy-target-popup");
t.is(e.target) || 0 !== t.has(e.target).length || U("#cyxy-popup-favour").hasClass("commit") || t.hide()
}),
U("#cyxy-popup-left-slide").click(function () {
h();
var e = M.data("targetList"),
t = M.data("index");
if (!isNaN(t)) {
t--,
t <= 0 && (t = 0, U("#cyxy-popup-left-slide").hide()),
U("#cyxy-popup-right-slide").show();
var n = e[t];
M.data("targetInfo", n),
M[0].sentence_id = n.id,
M.data("comment", ""),
M.text(n.content),
U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL),
U("#cyxy-popup-avatar").attr("src", n.user.avatar_url),
U("#cyxy-popup-name").text(n.user.username),
U("#cyxy-popup-time").text(F.getDateDiff(n.updated_at)),
U("#cyxy-popup-favour-num").text(n.rate.LIKE || 0),
U("#cyxy-popup-oppose-num").text(n.rate.UNLIKE || 0),
M.data("index", t)
}
}),
U("#cyxy-popup-right-slide").click(function () {
h();
var e = M.data("targetList"),
t = M.data("index");
if (!isNaN(t)) {
t++,
t >= e.length - 1 && U("#cyxy-popup-right-slide").hide(),
t > 0 && U("#cyxy-popup-left-slide").show();
var n = e[t];
M.text(n.content),
M.data("targetInfo", n),
M[0].sentence_id = n.id,
M.data("comment", ""),
U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL),
U("#cyxy-popup-avatar").attr("src", n.user.avatar_url),
U("#cyxy-popup-name").text(n.user.username),
U("#cyxy-popup-time").text(F.getDateDiff(n.updated_at)),
U("#cyxy-popup-favour-num").text(n.rate.LIKE || 0),
U("#cyxy-popup-oppose-num").text(n.rate.UNLIKE || 0),
M.data("index", t)
}
}),
U("#cyxy-popup-favour").click(function () {
if (U("#cyxy-popup-favour").hasClass("commit"))
d(1);
else {
var t = M[0].sentence_id;
t ? y(t, "POINT_LIKE_SENTENCE", e) : g(M.data("source_text"), M.data("xiaoyiText"), "", function (n) {
n && 0 == n.rc && (t = n.sentence_id, M[0].sentence_id = t, y(t, "POINT_LIKE_SENTENCE", e))
}, P.XIAOYI_USERID)
}
}),
U("#cyxy-popup-oppose").click(function () {
var e = M.data("comment"),
n = M.data("sentence_id");
e ? "like" == e ? y(n, "POINT_CANCEL_LIKE_SENTENCE", function () {
U("#cyxy-popup-favour-num").text(parseInt(U("#cyxy-popup-favour-num").text()) - 1),
U("#cyxy-popup-favour-img").css("height", "18px"),
M.data("comment", "cancel")
}) : "unlike" == e ? y(n, "POINT_CANCEL_LIKE_SENTENCE", function () {
U("#cyxy-popup-oppose-num").text(parseInt(U("#cyxy-popup-oppose-num").text()) - 1),
M.data("comment", "cancel"),
U("#cyxy-popup-oppose-img").css("height", "18px")
}) : "cancel" == e && y(n, "POINT_UNLIKE_SENTENCE", t) : n ? y(n, "POINT_UNLIKE_SENTENCE", t) : g(M.data("source_text"), M.data("before"), "", function (e) {
e && 0 == e.rc && (n = e.sentence_id, M[0].sentence_id = n, y(n, "POINT_UNLIKE_SENTENCE", t))
}, P.XIAOYI_USERID)
})
}
function d(e) {
function t(e) {
if (U("#cyxy-popup-favour").removeClass("commit"), e && 0 == e.rc) {
M[0].sentence_id = e.sentence_id,
U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL),
U("#cyxy-popup-favour-num").text(U("cyxy-popup-favour-num").text() || 0),
M.data("before", M.text());
var t = {
id: e.sentence_id,
content: M.text(),
updated_at: Date.now(),
user: {
id: Ae,
avatar_url: xe.avatar_url,
username: xe.username
},
rate: {
LIKE: U("cyxy-popup-favour-num").text(),
UNLIKE: 0
}
};
M.data("targetInfo", t);
var n = M.data("targetList");
n && n.length > 0 && M.data("targetList", n.concat(t)),
l(),
"android" == Ee ? window.js.showEditSuccess(K, W + e.point.total_point) : "ios" == Ee ? window.webkit.messageHandlers.showEditSuccess.postMessage({
title1: K,
title2: W + e.point.total_point
}) : D.open({
content: K + W + e.point.total_point,
skin: "msg",
time: 3
})
} else
console.error(e), D.open({
content: oe,
skin: "msg",
time: 3
})
}
Ae && (M.data("before") !== M.text() ? M.data("user_s_id") ? m(M.data("source_text"), M.data("user_s_id"), M.text(), function (e) {
if (U("#cyxy-popup-favour").removeClass("commit"), e && 0 == e.rc) {
U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL);
var t = M.data("targetList"),
n = M.data("user_index"),
r = 0;
M.data("targetInfo") && (r = M.data("targetInfo").rate.LIKE),
t && t.length > 0 && n >= 0 && (t[n].content = M.text(), t[n].rate.lIKE = r, M.data("targetList", t)),
U("#cyxy-popup-favour-num").text(r || 0),
M.data("targetInfo", {
id: e.sentence_id,
content: M.text(),
updated_at: Date.now(),
user: {
id: Ae,
avatar_url: xe.avatar_url,
username: xe.username
},
rate: {
LIKE: r,
UNLIKE: 0
}
}),
M.data("before", M.text()),
D.open({
content: re,
skin: "msg",
time: 2
})
} else
console.error(e), D.open({
content: oe,
skin: "msg",
time: 3
})
}) : g(M.data("source_text"), M.text(), "", t) : 1 == e && (U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL), U("#cyxy-popup-favour-num").text(U("cyxy-popup-favour-num").text() || 0), D.open({
content: ie,
skin: "msg",
time: 2
}))),
setTimeout(function () {
U("#cyxy-popup-favour").removeClass("commit")
}, 2e3)
}
function f() {
null !== Ce && clearTimeout(Ce),
Ce = setTimeout(function () {
U(".cyxy-target-popup").hide()
}, 3e3)
}
function h() {
null !== Ce && clearTimeout(Ce)
}
function g(e, t, n, r, i) {
if (!Re) {
var o = O(),
a = P.TRS_URL + "/v1/page/" + ye + "/sentence",
s = Ae;
i && (s = i),
Re = !0,
o.open("POST", a, !0),
o.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
o.timeout = 5e3,
o.setRequestHeader("content-type", "application/json"),
o.onload = function (e) {
Re = !1;
var t = JSON.parse(this.responseText);
r(t)
},
o.onerror = function (e) {
throw Re = !1,
D.open({
content: oe,
skin: "msg",
time: 3
}),
console.error(e),
new Error("commitPageSentence Error", e)
},
o.send(JSON.stringify({
user_id: s,
page_id: ye,
source: e,
target: t,
trans_type: "en2zh",
action: n || ""
}))
}
}
function m(e, t, n, r) {
if (!Re) {
var i = O(),
o = P.TRS_URL + "/v1/page/" + ye + "/sentence/" + t;
Re = !0,
i.open("POST", o, !0),
i.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
i.timeout = 5e3,
i.setRequestHeader("content-type", "application/json"),
i.onload = function (e) {
Re = !1;
var t = JSON.parse(this.responseText);
r(t)
},
i.onerror = function (e) {
throw Re = !1,
D.open({
content: oe,
skin: "msg",
time: 3
}),
console.error(e),
r(),
new Error("commentPageSentence Error", e)
},
i.send(JSON.stringify({
source: e,
target: n,
user_id: Ae,
sentence_id: t,
trans_type: "en2zh"
}))
}
}
function y(e, t, n, r) {
if (!Re) {
var i = O();
Re = !0,
t = t.toUpperCase();
var o = P.TRS_URL + "/v1/page/" + ye + "/sentence/" + e + "/comment";
i.open("POST", o, !0),
i.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
i.timeout = 3e3,
i.setRequestHeader("content-type", "application/json"),
i.onload = function (e) {
Re = !1;
var t = JSON.parse(this.responseText);
0 == t.rc ? (D.open({
content: ae,
skin: "msg",
time: 2
}), n()) : t.rc == -1 ? D.open({
content: se,
skin: "msg",
time: 2
}) : D.open({
content: oe,
skin: "msg",
time: 3
})
},
i.onerror = function (e) {
throw Re = !1,
D.open({
content: oe,
skin: "msg",
time: 3
}),
console.error(e),
new Error("commentPageSentence Error", e)
},
f(),
i.send(JSON.stringify({
user_id: Ae,
sentence_id: e,
trans_type: "en2zh",
action: t
}))
}
}
function v() {
_e || (_e = !0, D.open({
className: H,
content: "想修改译文成为共同译者吗?<br>快来下载「彩云小译」吧!",
btn: ["立即下载", "取消"],
yes: function (e) {
D.close(e),
window.open(DOWNLOAD_URL, "_blank")
},
end: function () {
setTimeout(function () {
_e = !1
}, 500)
}
}))
}
function x() {
function e(n) {
if (!(U(n).is(":hidden") || "SCRIPT" == n.nodeName || "LINK" == n.nodeName || "STYLE" == n.nodeName || "CODE" == n.nodeName || "NOSCRIPT" == n.nodeName || "CITE" == n.nodeName || n.classList && (n.classList.contains(H) || n.classList.contains(G) || n.classList.contains("qq_face") || n.classList.contains("msg_input_wrapper") || n.classList.contains("prettyprint") || n.classList.contains("PROGRAMLISTING"))))
for (var r = n.childNodes, i = 0, o = r.length; i < o; i++) {
var a = r[i];
if (a && (!a.classList || !a.classList.contains(H) && !a.classList.contains(G)))
if (a.classList && (a.classList.contains("js_message_plain") || a.classList.contains("message_body")))
U(r[i]).children("." + G).length > 0 || (t(a), u.push(a));
else if ("PRE" != a.nodeName)
if ("P" != a.nodeName) {
if (w(a)) {
if (a.nodeName.indexOf("H") >= 0 && ("H1" == a.nodeName || "H2" == a.nodeName || "H3" == a.nodeName || "H4" == a.nodeName || "H5" == a.nodeName || "H6" == a.nodeName) && !(a.firstElementChild && ("SPAN" == a.firstElementChild.nodeName || "SPAN" == a.lastElementChild.nodeName || "A" == a.firstElementChild.nodeName || "A" == a.lastElementChild.nodeName) || a.parentElement && "A" == a.parentElement.nodeName)) {
C(a, H),
l.push(a);
continue
}
if (!("SPAN" != a.nodeName && "LABEL" != a.nodeName && "LI" != a.nodeName || a.firstElementChild && "STRONG" != a.firstElementChild.nodeName)) {
C(a, H),
p.push(a);
continue
}
if ("A" == a.nodeName && (!a.firstElementChild || "STRONG" == a.firstElementChild.nodeName)) {
C(a, H),
c.push(a);
continue
}
}
a.nodeType === Node.TEXT_NODE && T(a) ? (C(a.parentElement, H), m.push(a)) : a.nodeType === Node.ELEMENT_NODE && e(a)
} else
C(a, H), s.push(a)
}
}
function t(e) {
var t = document.createElement("font");
C(t, G),
e.appendChild(t)
}
function n() {
for (var e = [], t = [], n = [], i = [], o = [], a = [], d = 0, f = l.length; d < f; d++)
R(l[d]) && (e = e.concat(l.splice(d, 1)), d--);
for (var d = 0, f = s.length; d < f; d++)
R(s[d]) && (t = t.concat(s.splice(d, 1)), d--);
u.length > 0 && (n = n.concat(u.splice(0, u.length)), r(n, "pre"));
for (var d = 0, f = c.length; d < f; d++)
R(c[d]) && (i = i.concat(c.splice(d, 1)), d--);
for (var d = 0, f = p.length; d < f; d++)
R(p[d]) && (o = o.concat(p.splice(d, 1)), d--);
for (var d = 0, f = m.length; d < f; d++)
_(m[d]) && (a = a.concat(m.splice(d, 1)), d--);
var h = e.length + t.length + i.length + o.length,
g = l.length + s.length + c.length + p.length,
y = h / (h + g).toFixed(2) * 100;
isNaN(y) && (y = 0),
r(e, "h"),
r(t, "p"),
r(i, "a"),
r(o, "span"),
r(a, "text"),
A(y)
}
function r(e, t) {
for (var n = [], r = [], o = [], a = [], s = [], u = [], l = [], c = [], p = [], d = 0, f = e.length; d < f; d++) {
var h = e[d],
g = h.innerText;
if ("text" == t && (g = h.nodeValue), g = g.trim()) {
var m = F.detectLang(g),
y = g.length;
if ("jp" == m)
y > 30 ? l.push(h) : y > 8 ? c.push(h) : p.push(h);
else if ("zh" == m)
y > 30 ? s.push(h) : y > 8 ? a.push(h) : u.push(h);
else {
var v = g.split(" ").length;
v > 30 ? o.push(h) : v > 6 ? r.push(h) : n.push(h)
}
}
}
n.sort(function (e, n) {
var r = e.innerText,
i = n.innerText;
return "text" == t && (r = e.nodeValue, i = n.nodeValue),
r.trim().split(" ").length - i.trim().split(" ").length
}),
i(n, t, 50, "en2zh"),
i(r, t, 10, "en2zh"),
i(o, t, 2, "en2zh"),
i(u, t, 50, "zh2en"),
i(a, t, 10, "zh2en"),
i(s, t, 2, "zh2en"),
i(p, t, 50, "ja2zh"),
i(c, t, 20, "ja2zh"),
i(l, t, 2, "ja2zh")
}
function i(e, t, n, r) {
var i = 25;
for (n && (i = n); e.length > 0;) {
var a = e.splice(0, i);
o(a, t, r)
}
}
function o(e, t, n) {
function r() {
console.log("translate retry:", e),
setTimeout(function () {
o(e, t, n)
}, 15e3)
}
for (var i = [], a = 0, s = e.length; a < s; a++) {
var u = e[a].innerText;
"text" == t && (u = e[a].nodeValue),
i.push(E(u))
}
if (!(i.length <= 0)) {
var l = "en2zh",
c = P.TRS_URL + "/v1/page/translator";
"ja2zh" == n ? (l = "ja2zh", c = P.TRS_URL + "/v1/page/translator") : "zh2en" == n && (l = "zh2en", c = P.TRS_URL + "/v1/page/translator");
var p = O();
p.open("POST", c, !0),
p.setRequestHeader("content-type", "application/json"),
p.setRequestHeader("X-Authorization", "token j1np9nb4h8jad0mi2odk"),
p.timeout = 27e3,
p.ontimeout = function (r) {
console.warn("timeout: ", r),
D.open({
content: Z,
skin: "msg",
time: 2
}),
o(e, t, n)
},
p.onerror = function (e) {
throw r(),
console.error(p, e),
new Error("Translate Error", e)
},
p.onload = function (n) {
var r = JSON.parse(p.responseText);
if (r && 0 == r.rc) {
var o = r.target;
if (i.length != o.length)
throw new Error("sources targets length error");
for (var a = 0, s = e.length; a < s; a++) {
var u = e[a],
l = "";
if (o[a] && o[a].target && (l = o[a].target.trim(), i[a].trim().toLowerCase() !== l.toLowerCase())) {
var c = 0;
o[a].sentence_id && (c = o[a].sentence_id);
var d = o[a].count || 0;
if ("p" == t) {
var f = u.cloneNode(!0);
if (f.innerText = l, f.contentEditable = !0, C(f, G), f.sentence_id = c, f.source_text = E(u.innerText), d > 1) {
var h = document.createElement("span");
h.className = q,
h.innerText = "(" + d + ")",
f.appendChild(h)
}
u.parentNode.insertBefore(f, u.nextSibling)
} else if ("pre" == t) {
var f = U(u).children("." + G)[0];
if ("" != f.innerText)
continue;
l = S(l),
l.length > 4 && (f.contentEditable = !0),
f.sentence_id = c,
f.source_text = E(u.innerText),
f.innerText = " " + l
} else if ("h" == t) {
l = S(l);
var f = u.cloneNode(!0);
if (f.innerText = l, f.contentEditable = !0, f.sentence_id = c, f.source_text = E(u.innerText), C(f, G), d > 1) {
var h = document.createElement("span");
h.className = q,
h.innerText = "(" + d + ")",
f.appendChild(h)
}
u.parentNode.insertBefore(f, u.nextSibling)
} else if ("a" == t || "span" == t) {
if (l = S(l), i[a].trim().toLowerCase() === l.toLowerCase())
continue;
var g = document.createElement("font");
if (C(g, G), l.length > 4 && "span" == t && (g.contentEditable = !0), g.sentence_id = c, g.source_text = E(u.innerText), d > 1) {
var h = document.createElement("span");
h.className = q,
h.innerText = "(" + d + ")",
g.appendChild(h)
}
g.innerText = " " + l,
u.appendChild(g)
} else {
if (l = S(l), i[a].trim().toLowerCase() === l.toLowerCase())
continue;
var g = document.createElement("font");
if (C(g, G), l.length > 4 && "A" != u.parentNode.nodeName && (g.contentEditable = !0), g.sentence_id = c, g.source_text = E(u.nodeValue), d > 1) {
var h = document.createElement("span");
h.className = q,
h.innerText = "(" + d + ")",
g.appendChild(h)
}
g.innerText = " " + l,
u.parentNode.insertBefore(g, u.nextSibling)
}
C(u, j)
}
}
} else
console.error(r, e)
},
p.send(JSON.stringify({
source: i,
trans_type: l,
request_id: Ae || me || ge || "web-translate",
url: document.URL,
page_id: ye,
replaced: !0,
cached: P.CACHED
}))
}
}
var a = document.querySelectorAll("." + H);
if (!(a && a.length > 3)) {
var s = [],
u = [],
l = [],
c = [],
p = [],
g = (Date.now(), null),
m = [];
we = setInterval(function () {
e(document.body),
n()
}, Te),
A(20),
e(document.body),
A(40),
n(),
A(80),
window.onscroll = function (t) {
null !== g && clearTimeout(g),
g = setTimeout(function () {
e(document.body),
n(),
U(window).scrollTop() + U(window).height() >= U(document).height() && (U(".cyxy-footer").show(), setTimeout(function () {
U(".cyxy-footer").hide()
}, 7500))
}, 200)
},
setTimeout(function () { }, 500);
U("body").on("click", "." + G + "[contenteditable]", function () {
if (!U("#cyxy-popup-favour").hasClass("commit")) {
M = U(this),
M.data("source_text") || M.data("source_text", this.source_text),
U(this).find("." + q).remove();
var e = this.sentence_id;
if (h(), !Ae) {
if ("share" == Ee)
return v(), U(this);
if ("android" == Ee)
return window.js.showLoginDialog(Q), U(this);
if ("ios" == Ee)
return window.webkit.messageHandlers.showLoginDialog.postMessage({
title: Q
}), U(this);
B.testCookie(function (e) {
return e ? (Ae = e._id, void (xe = {
username: e.name || "***",
_id: e._id,
avatar_url: e.avatar || P.DEFAULT_AVATAR_URL
})) : (D.open({
content: Y,
btn: [de, fe],
yes: function (e) {
D.close(e),
window.open(P.LOGIN_URL, "_blank")
}
}), U(this))
})
}
e ? B.fetchPageSentenceTargetList(e, Ae, ye, function (e) {
if (0 == e.rc) {
var t,
n = e.sentence;
if (n && n.length > 0) {
M.data("index", 0),
U("#cyxy-popup-left-slide").hide(),
M.data("targetList", n);
for (var r = 0, i = n.length; r < i; r++)
n[r] && (n[r].user && Ae == n[r].user.id && (M.data("user_s_id", n[r].id), M.data("user_index", r)), n[r].invalid && (n.splice(r, 1), r--));
n.length > 1 && U("#cyxy-popup-right-slide").show()
}
t = n[0],
M.data("targetInfo") && M.data("targetInfo").user.id != t.user.id && (t = M.data("targetInfo"), M.data("index", -1)),
U("#cyxy-popup-avatar").attr("src", t.user.avatar_url),
U("#cyxy-popup-name").text(t.user.username),
U("#cyxy-popup-time").text(F.getDateDiff(t.updated_at)),
U("#cyxy-popup-favour-num").text(t.rate.LIKE || 0),
U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL),
U("#cyxy-popup-oppose-num").text(t.rate.UNLIKE || 0)
}
}) : (M.data("targetList", []), U("#cyxy-popup-left-slide").hide(), U("#cyxy-popup-right-slide").hide(), U("#cyxy-popup-avatar").attr("src", P.XIAOYI_DEFAULT_URL), U("#cyxy-popup-name").text(ue), U("#cyxy-popup-time").text(le), U("#cyxy-popup-favour-num").text("0"), U("#cyxy-popup-favour-img").attr("src", P.FAVOR_IMG_URL), U(this).data("xiaoyiText", U(this).text()));
for (var t = this, n = t.offsetTop + t.offsetHeight + 5, r = t.offsetLeft; t.offsetParent;)
t = t.offsetParent, n += t.offsetTop, r += t.offsetLeft;
return r > window.innerWidth / 3 && (r = .25 * window.innerWidth),
U(".cyxy-target-popup").css({
top: n,
left: r
}),
U(".cyxy-target-popup").show(),
U(this).data("before", U(this).text()),
U(this)
}
}).on("paste input", "." + G + "[contenteditable]", function () {
if (!U("#cyxy-popup-favour").hasClass("commit"))
return U(this).data("before") !== U(this).text() && (M.data("status", "edit"), U("#cyxy-popup-avatar").attr("src", xe.avatar_url), U("#cyxy-popup-name").text(xe.username), U("#cyxy-popup-time").text(pe), U("#cyxy-popup-favour-num").text(ce), U("#cyxy-popup-favour-img").attr("src", P.CHECKED_IMG_URL), U("#cyxy-popup-favour").addClass("commit"), U("#cyxy-popup-oppose-num").text("0")), U(this)
}).on("blur focusout", "." + G + "[contenteditable]", function () {
return d(),
f(),
U(this)
})
}
}
function A(e) {
"android" == Ee && window.js.changeProgress(e)
}
function b(e) {
return !!e.match(/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?/gi)
}
function w(e) {
return e.innerText && e.innerText.trim().length > 1 && e.innerText.length < 2048 && isNaN(e.innerText) && !b(e.innerText)
}
function T(e) {
if (e.nodeValue) {
var t = e.nodeValue.trim();
return t.length > 1 && e.nodeValue.length < 2048 && isNaN(t) && !b(t)
}
return !1
}
function E(e) {
return e.trim().replace("\n", "").replace("<br>", "").replace("&nbsp;", "")
}
function S(e) {
var t = e[e.length - 1];
return "." != t && "。" != t && "!" != t || (e = e.substr(0, e.length - 1).trim()),
e
}
function C(e, t) {
var n = e.className || "";
if ("String" != typeof n || n.indexOf(t) === -1) {
var r = "" != n ? " " : "",
i = n + r + t;
e.className = i
}
}
function R(e) {
if (e) {
for (var t = e.offsetTop || 0, n = e.offsetLeft || 0; e.offsetParent;)
e = e.offsetParent, t += e.offsetTop, n += e.offsetLeft;
return t < window.pageYOffset + window.innerHeight * X
}
}
function _(e) {
if (e && e.parentElement) {
for (var t = e.parentElement, n = t.offsetTop || 0, r = t.offsetLeft || 0; t.offsetParent;)
t = t.offsetParent, n += t.offsetTop, r += t.offsetLeft;
return n < window.pageYOffset + window.innerHeight * X && r < window.pageXOffset + window.innerWidth
}
}
function k() {
return he.indexOf("Android") > 0
}
function L() {
return /(iPhone|iPad|iPod)/i.test(he)
}
function O() {
for (var e = [function () {
return new XMLHttpRequest
}, function () {
return new ActiveXObject("Msxml2.XMLHTTP")
}, function () {
return new ActiveXObject("Msxml3.XMLHTTP")
}, function () {
return new ActiveXObject("Microsoft.XMLHTTP")
}
], t = !1, n = 0; n < e.length; n++) {
try {
t = e[n]()
} catch (e) {
continue
}
break
}
return t
}
var N = document.querySelectorAll(".cyxy-target-popup");
if (!(N && N.length > 0)) {
var M,
Raven = t(1),
I = t(8),
D = (t(9), t(14)),
B = t(15),
P = t(16),
F = t(17),
U = t(18),
H = "cyxy-trs-source",
j = "cyxy-trs-source-ted",
G = "cyxy-trs-target",
q = "cyxy-target-count",
X = 2.2,
V = "小译火力全开!LingoCloud, FIRE!",
K = "",
W = "+30 彩云朵!现有:",
z = "限免次数已不足,成为小译注册用户,畅享更多阅读次数!现在注册还送彩云朵哟~",
J = "诶呦喂~彩云朵不足!修订译文或点击赞、分享赚取彩云朵,或购买VIP畅享无限阅读次数",
Q = "您还没有登录,是否登录编辑译文?",
Y = "您还没有登录,是否登录编辑译文?如果已经登录,请刷新页面重试哦",
Z = "翻译请求超时,可能是服务器太繁忙了,小译正在重试...",
$ = "抱歉,网页认证有误,请刷新重试",
ee = "抱歉,网络请求有误,请刷新重试",
te = "抱歉,本地数据获取异常,请刷新重试",
ne = "抱歉,获取用户信息失败,请刷新重试",
re = "修改译文成功",
ie = "译文未修改",
oe = "提交有误",
ae = "感谢点赞,+5 彩云朵!",
se = "已经赞过啦",
ue = "彩云小译",
le = "刚刚",
ce = "提交",
pe = "现在",
de = "登录",
fe = "取消",
he = navigator.userAgent,
ge = "",
me = "",
ye = 0,
ve = "",
xe = {},
Ae = "",
be = location.origin + location.pathname,
we = null,
Te = 2300;
(location.host.indexOf("youtube.com") >= 0 || location.host.indexOf("wx.qq.com") >= 0 || location.host.indexOf("slack.com") >= 0) && (Te = 1e3),
"local" != P.ENV && Raven.config("https://c49231b0334e4624b8941767b8f6bfa4@sentry.in.caiyunapp.com/22", {
release: P.VERSION,
environment: P.ENV,
sampleRate: 1
}).install();
var Ee = i();
Raven.context(function () {
e()
});
var Se,
Ce = null,
Re = !1,
_e = !1,
ke = new Date;
window.cyPageMark = function () {
var e = F.wordStatistics(document.body),
t = Math.round(((new Date).getTime() - ke.getTime()) / 1e3),
n = (1.6 * e.en_words + e.zh_chars) / 9,
r = t / n;
r >= 1 && (r = 1),
B.pageMark({
time: t,
chars: Math.round(e.chars * r),
en_words: Math.round(e.en_words * r),
zh_chars: Math.round(e.zh_chars * r)
}, Ae, ye, function (e) { })
},
window.onbeforeunload = function () {
cyPageMark(),
console.log(location.href)
}
}
}
()
}, function (e, exports, t) {
(function (n) {
"use strict";
var r = t(2),
i = "undefined" != typeof window ? window : "undefined" != typeof n ? n : "undefined" != typeof self ? self : {},
o = i.Raven,
Raven = new r;
Raven.noConflict = function () {
return i.Raven = o,
Raven
},
Raven.afterLoad(),
e.exports = Raven
}).call(exports, function () {
return this
}
())
}, function (e, exports, t) {
(function (n) {
"use strict";
function r() {
return +new Date
}
function i(e, t) {
return a(t) ? function (n) {
return t(n, e)
}
: t
}
function Raven() {
this._hasJSON = !("object" != typeof JSON || !JSON.stringify),
this._hasDocument = !o(I),
this._hasNavigator = !o(D),
this._lastCapturedException = null,
this._lastData = null,
this._lastEventId = null,
this._globalServer = null,
this._globalKey = null,
this._globalProject = null,
this._globalContext = {},
this._globalOptions = {
logger: "javascript",
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
crossOrigin: "anonymous",
collectWindowErrors: !0,
maxMessageLength: 0,
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: !0,
instrument: !0,
sampleRate: 1
},
this._ignoreOnError = 0,
this._isRavenInstalled = !1,
this._originalErrorStackTraceLimit = Error.stackTraceLimit,
this._originalConsole = M.console || {},
this._originalConsoleMethods = {},
this._plugins = [],
this._startTime = r(),
this._wrappedBuiltIns = [],
this._breadcrumbs = [],
this._lastCapturedEvent = null,
this._keypressTimeout,
this._location = M.location,
this._lastHref = this._location && this._location.href,
this._resetBackoff();
for (var e in this._originalConsole)
this._originalConsoleMethods[e] = this._originalConsole[e]
}
function o(e) {
return void 0 === e
}
function a(e) {
return "function" == typeof e
}
function s(e) {
return "[object String]" === B.toString.call(e)
}
function u(e) {
for (var t in e)
return !1;
return !0
}
function l(e, t) {
var n,
r;
if (o(e.length))
for (n in e)
f(e, n) && t.call(null, n, e[n]);
else if (r = e.length)
for (n = 0; n < r; n++)
t.call(null, n, e[n])
}
function c(e, t) {
return t ? (l(t, function (t, n) {
e[t] = n
}), e) : e
}
function p(e) {
return !!Object.isFrozen && Object.isFrozen(e)
}
function d(e, t) {
return !t || e.length <= t ? e : e.substr(0, t) + "…"
}
function f(e, t) {
return B.hasOwnProperty.call(e, t)
}
function h(e) {
for (var t, n = [], r = 0, i = e.length; r < i; r++)
t = e[r], s(t) ? n.push(t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1")) : t && t.source && n.push(t.source);
return new RegExp(n.join("|"), "i")
}
function g(e) {
var t = [];
return l(e, function (e, n) {
t.push(encodeURIComponent(e) + "=" + encodeURIComponent(n))
}),
t.join("&")
}
function m(e) {
var t = e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
if (!t)
return {};
var n = t[6] || "",
r = t[8] || "";
return {
protocol: t[2],
host: t[4],
path: t[5],
relative: t[5] + n + r
}
}
function y() {
var e = M.crypto || M.msCrypto;
if (!o(e) && e.getRandomValues) {
var t = new Uint16Array(8);
e.getRandomValues(t),
t[3] = 4095 & t[3] | 16384,
t[4] = 16383 & t[4] | 32768;
var n = function (e) {
for (var t = e.toString(16); t.length < 4;)
t = "0" + t;
return t
};
return n(t[0]) + n(t[1]) + n(t[2]) + n(t[3]) + n(t[4]) + n(t[5]) + n(t[6]) + n(t[7])
}
return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (e) {
var t = 16 * Math.random() | 0,
n = "x" === e ? t : 3 & t | 8;
return n.toString(16)
})
}
function v(e) {
for (var t, n = 5, r = 80, i = [], o = 0, a = 0, s = " > ", u = s.length; e && o++ < n && (t = x(e), !("html" === t || o > 1 && a + i.length * u + t.length >= r));)
i.push(t), a += t.length, e = e.parentNode;
return i.reverse().join(s)
}
function x(e) {
var t,
n,
r,
i,
o,
a = [];
if (!e || !e.tagName)
return "";
if (a.push(e.tagName.toLowerCase()), e.id && a.push("#" + e.id), t = e.className, t && s(t))
for (n = t.split(/\s+/), o = 0; o < n.length; o++)
a.push("." + n[o]);
var u = ["type", "name", "title", "alt"];
for (o = 0; o < u.length; o++)
r = u[o], i = e.getAttribute(r), i && a.push("[" + r + '="' + i + '"]');
return a.join("")
}
function A(e, t) {
return !!(!!e ^ !!t)
}
function b(e, t) {
return !A(e, t) && (e = e.values[0], t = t.values[0], e.type === t.type && e.value === t.value && w(e.stacktrace, t.stacktrace))
}
function w(e, t) {
if (A(e, t))
return !1;
var n = e.frames,
r = t.frames;
if (n.length !== r.length)
return !1;
for (var i, o, a = 0; a < n.length; a++)
if (i = n[a], o = r[a], i.filename !== o.filename || i.lineno !== o.lineno || i.colno !== o.colno || i.function !== o.function) return !1;
return !0
}
function T(e, t, n, r) {
var i = e[t];
e[t] = n(i),
r && r.push([e, t, i])
}
var E = t(3),
S = t(5),
C = t(6),
R = t(4),
_ = R.isError,
k = R.isObject,
L = t(7).wrapMethod,
O = "source protocol user pass host port path".split(" "),
N = /^(?:(\w+):)?\/\/(?:(\w+)(:\w+)?@)?([\w\.-]+)(?::(\d+))?(\/.*)/,
M = "undefined" != typeof window ? window : "undefined" != typeof n ? n : "undefined" != typeof self ? self : {},
I = M.document,
D = M.navigator;
Raven.prototype = {
VERSION: "3.17.0",
debug: !1,
TraceKit: E,
config: function (e, t) {
var n = this;
if (n._globalServer)
return this._logDebug("error", "Error: Raven has already been configured"), n;
if (!e)
return n;
var r = n._globalOptions;
t && l(t, function (e, t) {
"tags" === e || "extra" === e || "user" === e ? n._globalContext[e] = t : r[e] = t
}),
n.setDSN(e),
r.ignoreErrors.push(/^Script error\.?$/),
r.ignoreErrors.push(/^Javascript error: Script error\.? on line 0$/),
r.ignoreErrors = h(r.ignoreErrors),
r.ignoreUrls = !!r.ignoreUrls.length && h(r.ignoreUrls),
r.whitelistUrls = !!r.whitelistUrls.length && h(r.whitelistUrls),
r.includePaths = h(r.includePaths),
r.maxBreadcrumbs = Math.max(0, Math.min(r.maxBreadcrumbs || 100, 100));
var i = {
xhr: !0,
console: !0,
dom: !0,
location: !0
},
o = r.autoBreadcrumbs;
"[object Object]" === {}
.toString.call(o) ? o = c(i, o) : o !== !1 && (o = i),
r.autoBreadcrumbs = o;
var a = {
tryCatch: !0
},
s = r.instrument;
return "[object Object]" === {}
.toString.call(s) ? s = c(a, s) : s !== !1 && (s = a),
r.instrument = s,
E.collectWindowErrors = !!r.collectWindowErrors,
n
},
install: function () {
var e = this;
return e.isSetup() && !e._isRavenInstalled && (E.report.subscribe(function () {
e._handleOnErrorStackInfo.apply(e, arguments)
}), e._globalOptions.instrument && e._globalOptions.instrument.tryCatch && e._instrumentTryCatch(), e._globalOptions.autoBreadcrumbs && e._instrumentBreadcrumbs(), e._drainPlugins(), e._isRavenInstalled = !0),
Error.stackTraceLimit = e._globalOptions.stackTraceLimit,
this
},
setDSN: function (e) {
var t = this,
n = t._parseDSN(e),
r = n.path.lastIndexOf("/"),
i = n.path.substr(1, r);
t._dsn = e,
t._globalKey = n.user,
t._globalSecret = n.pass && n.pass.substr(1),
t._globalProject = n.path.substr(r + 1),
t._globalServer = t._getGlobalServer(n),
t._globalEndpoint = t._globalServer + "/" + i + "api/" + t._globalProject + "/store/",
this._resetBackoff()
},
context: function (e, t, n) {
return a(e) && (n = t || [], t = e, e = void 0),
this.wrap(e, t).apply(this, n)
},
wrap: function (e, t, n) {
function r() {
var r = [],
o = arguments.length,
s = !e || e && e.deep !== !1;
for (n && a(n) && n.apply(this, arguments); o--;)
r[o] = s ? i.wrap(e, arguments[o]) : arguments[o];
try {
return t.apply(this, r)
} catch (t) {
throw i._ignoreNextOnError(),
i.captureException(t, e),
t
}
}
var i = this;
if (o(t) && !a(e))
return e;
if (a(e) && (t = e, e = void 0), !a(t))
return t;
try {
if (t.__raven__)
return t;
if (t.__raven_wrapper__)
return t.__raven_wrapper__
} catch (e) {
return t
}
for (var s in t)
f(t, s) && (r[s] = t[s]);
return r.prototype = t.prototype,
t.__raven_wrapper__ = r,
r.__raven__ = !0,
r.__inner__ = t,
r
},
uninstall: function () {
return E.report.uninstall(),
this._restoreBuiltIns(),
Error.stackTraceLimit = this._originalErrorStackTraceLimit,
this._isRavenInstalled = !1,
this
},
captureException: function (e, t) {
if (!_(e))
return this.captureMessage(e, c({
trimHeadFrames: 1,
stacktrace: !0
}, t));
this._lastCapturedException = e;
try {
var n = E.computeStackTrace(e);
this._handleStackInfo(n, t)
} catch (t) {
if (e !== t)
throw t
}
return this
},
captureMessage: function (e, t) {
if (!this._globalOptions.ignoreErrors.test || !this._globalOptions.ignoreErrors.test(e)) {
t = t || {};
var n = c({
message: e + ""
}, t);
if (this._globalOptions.stacktrace || t && t.stacktrace) {
var r;
try {
throw new Error(e)
} catch (e) {
r = e
}
r.name = null,
t = c({
fingerprint: e,
trimHeadFrames: (t.trimHeadFrames || 0) + 1
}, t);
var i = E.computeStackTrace(r),
o = this._prepareFrames(i, t);
n.stacktrace = {
frames: o.reverse()
}
}
return this._send(n),
this
}
},
captureBreadcrumb: function (e) {
var t = c({
timestamp: r() / 1e3
}, e);
if (a(this._globalOptions.breadcrumbCallback)) {
var n = this._globalOptions.breadcrumbCallback(t);
if (k(n) && !u(n))
t = n;
else if (n === !1)
return this
}
return this._breadcrumbs.push(t),
this._breadcrumbs.length > this._globalOptions.maxBreadcrumbs && this._breadcrumbs.shift(),
this
},
addPlugin: function (e) {
var t = [].slice.call(arguments, 1);
return this._plugins.push([e, t]),
this._isRavenInstalled && this._drainPlugins(),
this
},
setUserContext: function (e) {
return this._globalContext.user = e,
this
},
setExtraContext: function (e) {
return this._mergeContext("extra", e),
this
},
setTagsContext: function (e) {
return this._mergeContext("tags", e),
this
},
clearContext: function () {
return this._globalContext = {},
this
},
getContext: function () {
return JSON.parse(S(this._globalContext))
},
setEnvironment: function (e) {
return this._globalOptions.environment = e,
this
},
setRelease: function (e) {
return this._globalOptions.release = e,
this
},
setDataCallback: function (e) {
var t = this._globalOptions.dataCallback;
return this._globalOptions.dataCallback = i(t, e),
this
},
setBreadcrumbCallback: function (e) {
var t = this._globalOptions.breadcrumbCallback;
return this._globalOptions.breadcrumbCallback = i(t, e),
this
},
setShouldSendCallback: function (e) {
var t = this._globalOptions.shouldSendCallback;
return this._globalOptions.shouldSendCallback = i(t, e),
this
},
setTransport: function (e) {
return this._globalOptions.transport = e,
this
},
lastException: function () {
return this._lastCapturedException
},
lastEventId: function () {
return this._lastEventId
},
isSetup: function () {
return !!this._hasJSON && (!!this._globalServer || (this.ravenNotConfiguredError || (this.ravenNotConfiguredError = !0, this._logDebug("error", "Error: Raven has not been configured.")), !1))
},
afterLoad: function () {
var e = M.RavenConfig;
e && this.config(e.dsn, e.config).install()
},
showReportDialog: function (e) {
if (I) {
e = e || {};
var t = e.eventId || this.lastEventId();
if (!t)
throw new C("Missing eventId");
var n = e.dsn || this._dsn;
if (!n)
throw new C("Missing DSN");
var r = encodeURIComponent,
i = "";
i += "?eventId=" + r(t),
i += "&dsn=" + r(n);
var o = e.user || this._globalContext.user;
o && (o.name && (i += "&name=" + r(o.name)), o.email && (i += "&email=" + r(o.email)));
var a = this._getGlobalServer(this._parseDSN(n)),
s = I.createElement("script");
s.async = !0,
s.src = a + "/api/embed/error-page/" + i,
(I.head || I.body).appendChild(s)
}
},
_ignoreNextOnError: function () {
var e = this;
this._ignoreOnError += 1,
setTimeout(function () {
e._ignoreOnError -= 1
})
},
_triggerEvent: function (e, t) {
var n,
r;
if (this._hasDocument) {
t = t || {},
e = "raven" + e.substr(0, 1).toUpperCase() + e.substr(1),
I.createEvent ? (n = I.createEvent("HTMLEvents"), n.initEvent(e, !0, !0)) : (n = I.createEventObject(), n.eventType = e);
for (r in t)
f(t, r) && (n[r] = t[r]);
if (I.createEvent)
I.dispatchEvent(n);
else
try {
I.fireEvent("on" + n.eventType.toLowerCase(), n)
} catch (e) { }
}
},
_breadcrumbEventHandler: function (e) {
var t = this;
return function (n) {
if (t._keypressTimeout = null, t._lastCapturedEvent !== n) {
t._lastCapturedEvent = n;
var r;
try {
r = v(n.target)
} catch (e) {
r = "<unknown>"
}
t.captureBreadcrumb({
category: "ui." + e,
message: r
})
}
}
},
_keypressEventHandler: function () {
var e = this,
t = 1e3;
return function (n) {
var r;
try {
r = n.target
} catch (e) {
return
}
var i = r && r.tagName;
if (i && ("INPUT" === i || "TEXTAREA" === i || r.isContentEditable)) {
var o = e._keypressTimeout;
o || e._breadcrumbEventHandler("input")(n),
clearTimeout(o),
e._keypressTimeout = setTimeout(function () {
e._keypressTimeout = null
}, t)
}
}
},
_captureUrlChange: function (e, t) {
var n = m(this._location.href),
r = m(t),
i = m(e);
this._lastHref = t,
n.protocol === r.protocol && n.host === r.host && (t = r.relative),
n.protocol === i.protocol && n.host === i.host && (e = i.relative),
this.captureBreadcrumb({
category: "navigation",
data: {
to: t,
from: e
}
})
},
_instrumentTryCatch: function () {
function e(e) {
return function (t, r) {
for (var i = new Array(arguments.length), o = 0; o < i.length; ++o)
i[o] = arguments[o];
var s = i[0];
return a(s) && (i[0] = n.wrap(s)),
e.apply ? e.apply(this, i) : e(i[0], i[1])
}
}
function t(e) {
var t = M[e] && M[e].prototype;
t && t.hasOwnProperty && t.hasOwnProperty("addEventListener") && (T(t, "addEventListener", function (t) {
return function (r, o, a, s) {
try {
o && o.handleEvent && (o.handleEvent = n.wrap(o.handleEvent))
} catch (e) { }
var u,
l,
c;
return i && i.dom && ("EventTarget" === e || "Node" === e) && (l = n._breadcrumbEventHandler("click"), c = n._keypressEventHandler(), u = function (e) {
if (e) {
var t;
try {
t = e.type
} catch (e) {
return
}
return "click" === t ? l(e) : "keypress" === t ? c(e) : void 0
}
}),
t.call(this, r, n.wrap(o, void 0, u), a, s)
}
}, r), T(t, "removeEventListener", function (e) {
return function (t, n, r, i) {
try {
n = n && (n.__raven_wrapper__ ? n.__raven_wrapper__ : n)
} catch (e) { }
return e.call(this, t, n, r, i)
}
}, r))
}
var n = this,
r = n._wrappedBuiltIns,
i = this._globalOptions.autoBreadcrumbs;
T(M, "setTimeout", e, r),
T(M, "setInterval", e, r),
M.requestAnimationFrame && T(M, "requestAnimationFrame", function (e) {
return function (t) {
return e(n.wrap(t))
}
}, r);
for (var o = ["EventTarget", "Window", "Node", "ApplicationCache", "AudioTrackList", "ChannelMergerNode", "CryptoOperation", "EventSource", "FileReader", "HTMLUnknownElement", "IDBDatabase", "IDBRequest", "IDBTransaction", "KeyOperation", "MediaController", "MessagePort", "ModalWindow", "Notification", "SVGElementInstance", "Screen", "TextTrack", "TextTrackCue", "TextTrackList", "WebSocket", "WebSocketWorker", "Worker", "XMLHttpRequest", "XMLHttpRequestEventTarget", "XMLHttpRequestUpload"], s = 0; s < o.length; s++)
t(o[s])
},
_instrumentBreadcrumbs: function () {
function e(e, n) {
e in n && a(n[e]) && T(n, e, function (e) {
return t.wrap(e)
})
}
var t = this,
n = this._globalOptions.autoBreadcrumbs,
r = t._wrappedBuiltIns;
if (n.xhr && "XMLHttpRequest" in M) {
var i = XMLHttpRequest.prototype;
T(i, "open", function (e) {
return function (n, r) {
return s(r) && r.indexOf(t._globalKey) === -1 && (this.__raven_xhr = {
method: n,
url: r,
status_code: null
}),
e.apply(this, arguments)
}
}, r),
T(i, "send", function (n) {
return function (r) {
function i() {
if (o.__raven_xhr && (1 === o.readyState || 4 === o.readyState)) {
try {
o.__raven_xhr.status_code = o.status
} catch (e) { }
t.captureBreadcrumb({
type: "http",
category: "xhr",
data: o.__raven_xhr
})
}
}
for (var o = this, s = ["onload", "onerror", "onprogress"], u = 0; u < s.length; u++)
e(s[u], o);
return "onreadystatechange" in o && a(o.onreadystatechange) ? T(o, "onreadystatechange", function (e) {
return t.wrap(e, void 0, i)
}) : o.onreadystatechange = i,
n.apply(this, arguments)
}
}, r)
}
n.xhr && "fetch" in M && T(M, "fetch", function (e) {
return function (n, r) {
for (var i = new Array(arguments.length), o = 0; o < i.length; ++o)
i[o] = arguments[o];
var a,
s = i[0],
u = "GET";
"string" == typeof s ? a = s : (a = s.url, s.method && (u = s.method)),
i[1] && i[1].method && (u = i[1].method);
var l = {
method: u,
url: a,
status_code: null
};
return t.captureBreadcrumb({
type: "http",
category: "fetch",
data: l
}),
e.apply(this, i).then(function (e) {
return l.status_code = e.status,
e
})
}
}, r),
n.dom && this._hasDocument && (I.addEventListener ? (I.addEventListener("click", t._breadcrumbEventHandler("click"), !1), I.addEventListener("keypress", t._keypressEventHandler(), !1)) : (I.attachEvent("onclick", t._breadcrumbEventHandler("click")), I.attachEvent("onkeypress", t._keypressEventHandler())));
var o = M.chrome,
u = o && o.app && o.app.runtime,
c = !u && M.history && history.pushState;
if (n.location && c) {
var p = M.onpopstate;
M.onpopstate = function () {
var e = t._location.href;
if (t._captureUrlChange(t._lastHref, e), p)
return p.apply(this, arguments)
},
T(history, "pushState", function (e) {
return function () {
var n = arguments.length > 2 ? arguments[2] : void 0;
return n && t._captureUrlChange(t._lastHref, n + ""),
e.apply(this, arguments)
}
}, r)
}
if (n.console && "console" in M && console.log) {
var d = function (e, n) {
t.captureBreadcrumb({
message: e,
level: n.level,
category: "console"
})
};
l(["debug", "info", "warn", "error", "log"], function (e, t) {
L(console, t, d)
})
}
},
_restoreBuiltIns: function () {
for (var e; this._wrappedBuiltIns.length;) {
e = this._wrappedBuiltIns.shift();
var t = e[0],
n = e[1],
r = e[2];
t[n] = r
}
},
_drainPlugins: function () {
var e = this;
l(this._plugins, function (t, n) {
var r = n[0],
i = n[1];
r.apply(e, [e].concat(i))
})
},
_parseDSN: function (e) {
var t = N.exec(e),
n = {},
r = 7;
try {
for (; r--;)
n[O[r]] = t[r] || ""
} catch (t) {
throw new C("Invalid DSN: " + e)
}
if (n.pass && !this._globalOptions.allowSecretKey)
throw new C("Do not specify your secret key in the DSN. See: http://bit.ly/raven-secret-key");
return n
},
_getGlobalServer: function (e) {
var t = "//" + e.host + (e.port ? ":" + e.port : "");
return e.protocol && (t = e.protocol + ":" + t),
t
},
_handleOnErrorStackInfo: function () {
this._ignoreOnError || this._handleStackInfo.apply(this, arguments)
},
_handleStackInfo: function (e, t) {
var n = this._prepareFrames(e, t);
this._triggerEvent("handle", {
stackInfo: e,
options: t
}),
this._processException(e.name, e.message, e.url, e.lineno, n, t)
},
_prepareFrames: function (e, t) {
var n = this,
r = [];
if (e.stack && e.stack.length && (l(e.stack, function (e, t) {
var i = n._normalizeFrame(t);
i && r.push(i)
}), t && t.trimHeadFrames))
for (var i = 0; i < t.trimHeadFrames && i < r.length; i++)
r[i].in_app = !1;