Cobalt Routing Bookmarklet: Advanced
by James Greene
HTML
<h2>Bookmarklet: Cobalt Routes</h2>
JavaScript
(function (ipAddress, verticalsToRoute) {
if (typeof ipAddress !== "string" || !ipAddress || !/^(\d{1,3}\.){4}$/.test(ipAddress + ".") || ipAddress === "127.0.0.1") {
return alert("ERROR: You did not provide a valid IP address string to this bookmarklet!\n\n" + ipAddress);
}
function keys(obj) {
if (Object.keys) {
return Object.keys(obj);
}
/* else... */
var objKeys = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
objKeys.push(prop);
}
}
return objKeys;
}
function contains(arr, item) {
if (arr && arr.indexOf) {
return arr.indexOf(item) !== -1;
}
/* else... */
for (var i = 0, len = arr.length; i < len; i++) {
if (arr[i] === item) {
return true;
}
}
return false;
}
function each(arr, fn, scope) {
if (arr.forEach) {
return arr.forEach(fn, scope);
}
/* else... */
var thisArg = scope || arr;
for (var i = 0, len = arr.length; i < len; i++) {
fn.call(thisArg, arr[i], i, arr);
}
}
function endsWith(str, substr) {
return str.slice(-1 * (substr.length)) === substr;
}
var undetectableExternalVerticals = ["Beacon", "CaseEvaluatorMobile", "CompanyAuthorityService", "ImagesPermalink", "LiveChat", "RequestDirectorHost", "Sync", "Video", "WebsiteDefault"];
var productDomain = window.location.host.replace(/^(1|a|www|(\d{1,3}\.){4}ip)\./i, "");
var verticalNames = keys(verticalsToRoute);
each(verticalNames, function (e /*, i, c */) {
var verticalData = verticalsToRoute[e];
var router = document.getElementById("coid_website_routingTextbox_" + e);
if (router) {
var routerInt = document.getElementById(router.id + "Internal");
var verticalIsInternal = false;
...