// Rewrite absolute yifanyi requests to same-origin relative paths (function(){ const hostRe = /^https?:\/\/(?:www\.)?yifanyi\.(?:id|com\.cn)/i; const replaceDomain = url => { try{ return url.replace(hostRe,''); }catch(e){return url} }; // Fetch/XHR interception const origFetch = window.fetch; if(origFetch){ window.fetch = function(input, init){ try{ if(typeof input === 'string' && hostRe.test(input)) input = replaceDomain(input); } catch(e){} return origFetch.call(this, input, init); }; } const origOpen = window.XMLHttpRequest && window.XMLHttpRequest.prototype.open; if(origOpen){ window.XMLHttpRequest.prototype.open = function(method, url){ try{ if(typeof url === 'string' && hostRe.test(url)) arguments[1] = replaceDomain(url); } catch(e){} return origOpen.apply(this, arguments); }; } // Replace attributes (src, srcset, href) on elements function rewriteAttributes(root=document){ try{ const els = root.querySelectorAll && root.querySelectorAll('img[src],source[src],img[srcset],source[srcset],link[href]'); if(els) els.forEach(el=>{ ['src','srcset','href'].forEach(attr=>{ const v = el.getAttribute && el.getAttribute(attr); if(v && hostRe.test(v)){ el.setAttribute(attr, replaceDomain(v)); } }); }); }catch(e){} } // Replace inline style url(...) occurrences 易翻译