Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created October 22, 2013 18:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zhuangya/7105959 to your computer and use it in GitHub Desktop.
Save zhuangya/7105959 to your computer and use it in GitHub Desktop.
its.detect.openItunes.js
function (t) {
t || (t = window.location.href);
var n = its.detect.currentPageIsMacAppStore() || its.url.queryParamValue("mt", t) == "12" || t.indexOf("associateVPPUserWithITSAccount") !== -1 || t.indexOf("vpp-associate") !== -1,
r = its.detect.currentPageIsMacBookStore(),
i = !1,
s;
n ? (i = its.detect.macAppStoreDetected(), s = "macappstore") : r && its.detect.macBookStoreDetected() ? (i = !0, s = "itms-books") : (i = its.detect.itunesDetected(), s = "itms");
if (i) {
t = t.replace(/^http/, s);
var o = t.indexOf("#");
o > -1 && (t = t.substring(0, o));
if (t.indexOf("payPalMIPReturn") === -1 && t.indexOf("firstGateReturn") === -1 && t.indexOf("payclickSignUpReturn") === -1 && t.indexOf("payclickBillingReturn") === -1) {
var u = t.indexOf("?") === -1 ? "?" : "&";
(new RegExp("itunes[.]apple[.]com/(../station/|WebObjects/MZStore.woa/wa/viewRadioStation[?])")).test(t) && (t += u + "cmd=AddStation", u = "&"), (new RegExp("itunes[.]apple[.]com/(../radio|WebObjects/MZStore.woa/wa/viewRadioMain)([?/]|$)")).test(t) && (t += u + "cmd=ViewStations", u = "&");
var a = its.cookies.get("a");
a && (t += u + "affC=" + its.detect.encodedQueryParameter(a), u = "&");
if (document.referrer) {
var f = its.detect.encodedQueryParameter(document.referrer);
t.length + f.length < 400 && (dbg("openItunes: Attaching " + document.referrer), t += u + "ign-msr=" + f)
}
}
} else !its.detect.itunesDetected() || t.indexOf("associateVPPUserWithITSAccount") === -1 && t.indexOf("vpp-associate") === -1 ? t = itms.PageData.itunesDownloadUrl : t = t.replace(/^http/, "itms");
return dbg("openItunes: " + t), window.location.href != t && setTimeout(function () {
window.location.href = t
}, 1), !1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment