JSFiddle - React, Tailwind, and code Playground
HTML
<table>
<tr><th>stripDomain</th><th>Expected</th><th>Given URL</th><th>Requested URL</th></tr>
</table>
CSS
td, tr, th {
border: 1px solid black;
padding: 4px;
}
.even td {
background: silver;
}
th {
background: black;
color: white;
}
th, .td0, .td1 {
font-weight: bold;
text-align: center;
border: 2px solid black;
}
table {
border: 2px solid black;
}
JavaScript
(function() {
if ( jQuery.ajaxPrefilter ) {
var rURL = /^([^\/]+)/,
rEsc = /(\-|\.)/,
protocol = rURL.exec( document.location.href )[ 1 ].replace( rEsc, "\\$1" ),
rDomains = {};
jQuery.ajaxPrefilter(function( options ) {
var strip = options.stripDomain,
rDomain,
sDomain;
if( strip ) {
rDomain = rDomains[ strip ];
if ( !rDomain ) {
sDomain = "^(?:" + protocol + ")?\\/\\/" + strip.replace( rEsc, "\\$1" );
rDomains[ strip ] = rDomain = new RegExp( sDomain, "i" )
}
options.url = options.url.replace( rDomain, "" );
}
});
}
})( jQuery );
jQuery(function() {
var table = jQuery( "table" ),
even = true;
function log() {
var tr = jQuery( "<tr/>" ).addClass( even ? "even" : "odd" );
even = !even;
for( var i = 0, length = arguments.length; i < length; i++ ) {
jQuery( "<td class='td" + i + "' />" ).text( arguments[ i ] ).appendTo( tr );
}
table.append( tr );
}
jQuery.each( [ false, "jsFiddle.net" ], function( _, stripDomain ) {
if ( stripDomain ) {
jQuery.ajaxSetup({
stripDomain: stripDomain
});
}
jQuery.each( [ "//jsFiddle.net/somethingElse",
"http://jsfiddle.net/somethingElse",
"/somethingElse",
"http://jsfiddle-net/somethingElse",
"https://jsFiddle.net/somethingElse",
"http://otherDomain.com/helloworld",
"//otherDomain.com/helloworld" ], function( index, url ) {
jQuery.ajax( url, {
beforeSend: function() {
log( stripDomain,
( stripDomain && index < 2 ? "strip" :...