我正在尝试将链接从 linkshare 转换为 itunes 链接,唯一的方法是在我的 wordpress 主题标题中插入这行 jQuery 代码
$(document).ready(function() {
// READ THIS!!
// START OF REQUIRED CHANGES
// you MUST change this value to one for your georiot account TSIDs
var tsid = 2062;
// END OF REQUIRED CHANGES
// DO NOT MODIFY BELOW THIS LINE
convertToGeoRiotLinks(tsid);
});
function convertToGeoRiotLinks(tsid) {
var numberOfLinks = document.links.length;
var currentLinkIndex = 0;
for (currentLinkIndex = 0; currentLinkIndex < numberOfLinks; currentLinkIndex++) {
var currentLink = document.links[currentLinkIndex];
var linkType = getLinkType(currentLink.href);
if (linkType == "apple" || linkType == "amazon") {
currentLink.href = "http://target.georiot.com/Proxy.ashx?TSID=" + tsid + "&GR_URL=" + encodeURIComponent(currentLink.href);
} else if (linkType == "linkshare" || linkType == "tradedoubler" || linkType == "dgmperf") {
var itunesUrl = extractItunesLinkFromAffiliateUrl(currentLink, linkType);
if (itunesUrl != "") {
currentLink.href = "http://target.georiot.com/Proxy.ashx?TSID=" + tsid + "&GR_URL=" + itunesUrl;
}
} else
continue;
}
}
function extractItunesLinkFromAffiliateUrl(currentLink, linkType)
{
if (currentLink.href.indexOf("?") > 0)
{
var arrParams = currentLink.href.split("?");
var arrURLParams = arrParams[1].split("&");
var arrParamNames = new Array(arrURLParams.length);
var arrParamValues = new Array(arrURLParams.length);
var i = 0;
for (i=0;i < arrURLParams.length;i++)
{
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1] != "") {
arrParamValues[i] = sParam[1];
if (linkType == "tradedoubler" && arrParamNames[i] == "url") {
return arrParamValues[i];
} else if (linkType == "linkshare" && arrParamNames[i] == "RD_PARM1") {
return arrParamValues[i];
} else if (linkType == "dgmperf" && arrParamNames[i] == "u") {
return arrParamValues[i];
}
} else
arrParamValues[i] = "";
}
}
return "";
}
/* Returns link type: unknown, amazon, apple, linkshare, dgm, tradedoubler
*/
function getLinkType(currentLinkHref) {
var appleRegex = /itunes.apple.com\/\S+id[0-9]+/i;
var tradeDoublerRegex = /clk[uk]*\.tradedoubler\.com\S*\?\S*url=[https%3A%2F%2F|http%3A%2F%2F]*\itunes\.apple\.com/i;
var linkshareRegex = /click\.linksynergy\.com\S*?\S*RD_PARM1=[https%3A%2F%2F|https%253A%252F%252F|http%253A%252F%252F|http%3A%2F%2F]*\itunes\.apple\.com/i;
var dgmPerfRegex = /t.dgm-au.c\S+\?+\S*u=[https%3A%2F%2F|http%3A%2F%2F|https%253A%252F%252F|http%253A%252F%252F]*\itunes\.apple\.com/i;
var amazonRegex = /\.amazon\./;
if (appleRegex.test(currentLinkHref))
return "apple";
else if (tradeDoublerRegex.test(currentLinkHref))
return "tradedoubler";
else if (linkshareRegex.test(currentLinkHref))
return "linkshare";
else if (dgmPerfRegex.test(currentLinkHref))
return "dgmperf";
else if (amazonRegex.test(currentLinkHref))
return "amazon";
else
return "unknown";
}
结果是加载时页面标题中的脱机代码如何正确执行而没有任何冲突,谢谢