1;(function(w, d, name){ 2 'use strict'; 3 if(!w[name]) w[name] = {}; 4 5 // prototype 6 var CdnReplace = (function() { 7 // default vars 8 var 9 DOMAIN = 'pilgrimsurfsupply.jp', 10 CDN_URL = [ 11 '//cdn.pilgrimsurfsupply.jp' 12 ], 13 TAGS = [ 14 // src 15 'audio', 16 'embed', 17 'img', 18 'input', 19 'script', 20 'source', 21 'track', 22 'video', 23 24 // href 25 'link' 26 ], 27 DATA = 'data-cdn-src'; 28 29 // constructor 30 function CdnReplace(option) { 31 this.option = option ? option : {}; 32 33 if(!option) { 34 this.option.tags = TAGS; 35 this.option.domain = DOMAIN; 36 }else{ 37 if(!this.option.tags) { 38 this.option.tags = TAGS; 39 } 40 if(!this.option.domain) { 41 this.option.domain = DOMAIN; 42 } 43 if(!this.option.cdn) { 44 this.option.cdn = CDN_URL; 45 } 46 } 47 48 if(this.option.domain == d.domain) return; 49 50 this.proc(); 51 } 52 CdnReplace.prototype = { 53 'init': init, 54 'proc': proc, 55 'setOption': setOption, 56 'getOption': getOption 57 }; 58 return CdnReplace; 59 60 // initialize 61 function init(option_, tag_) { 62 var 63 _that = this, 64 _tag = d.getElementsByTagName(tag_), 65 _src = '', 66 _domainSrc = ''; 67 68 for(var i = 0; _tag.length > i; i++) { 69 70 for(var j = 0; _that.option.cdn.length > j; j++) { 71 _src = _tag[i].src ? _tag[i].src : _tag[i].href || ''; 72 _domainSrc = (this.option.domain == d.domain) ? 73 _src : (_src.match(/(https?:)/) ? 74 _src.replace(RegExp.$1+_that.option.cdn[j], '') : _src.replace(_that.option.cdn[j], '')); 75 76 // link is not src. href set. 77 if(!_tag[i].src && _tag[i].href) { 78 if(_src && _tag[i].href != _domainSrc) { 79 _tag[i].href = _domainSrc; 80 } 81 }else{ 82 if(_src && _tag[i].src != _domainSrc) { 83 _tag[i].src = _domainSrc; 84 } 85 } 86 } 87 88 } 89 } 90 91 // procedure 92 function proc() { 93 for(var i = 0; this.option.tags.length > i; i++) { 94 this.init(this.option, this.option.tags[i]); 95 } 96 } 97 98 // set option 99 function setOption(option) { 100 this.option = option; 101 } 102 103 // get option 104 function getOption() { 105 return this.option; 106 } 107 108 })(); 109 110 // global vars set 111 w[name] = CdnReplace; 112 113})(window, document, 'pilgrim-cdnReplace');
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.