PageSourceSearch

https://www.chinadaily.com.cn/h5hack/respond.proxy.js

js chinadaily.com.cn collected 2026-10-01 06:37:05 UTC 3,449 bytes, 129 lines download raw bytes

1/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs  */
2(function(win, doc, undefined){
3	var docElem			= doc.documentElement,
4		proxyURL		= doc.getElementById("respond-proxy").href,
5		redirectURL		= (doc.getElementById("respond-redirect") || location).href,
6		baseElem		= doc.getElementsByTagName("base")[0],
7		urls			= [],
8		refNode;
9
10	function encode(url){
11		return win.encodeURIComponent(url);
12	}
13
14	 function fakejax( url, callback ){
15
16		var iframe,
17			AXO;
18		
19		// All hail Google https://j.mp/iKMI19
20		// Behold, an iframe proxy without annoying clicky noises.
21		if ( "ActiveXObject" in win ) {
22			AXO = new ActiveXObject( "htmlfile" );
23			AXO.open();
24			AXO.write( '<iframe id="x"></iframe>' );
25			AXO.close();
26			iframe = AXO.getElementById( "x" );
27		} else {
28			iframe = doc.createElement( "iframe" );
29			iframe.style.cssText = "position:absolute;top:-99em";
30			docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
31		}
32
33		iframe.src = checkBaseURL(proxyURL) + "?url=" + encode(redirectURL) + "&css=" + encode(checkBaseURL(url));
34		
35		function checkFrameName() {
36			var cssText;
37
38			try {
39				cssText = iframe.contentWindow.name;
40			}
41			catch (e) { }
42
43			if (cssText) {
44				// We've got what we need. Stop the iframe from loading further content.
45				iframe.src = "about:blank";
46				iframe.parentNode.removeChild(iframe);
47				iframe = null;
48
49			
50				// Per https://j.mp/kn9EPh, not taking any chances. Flushing the ActiveXObject
51				if (AXO) {
52					AXO = null;
53
54					if (win.CollectGarbage) {
55						win.CollectGarbage();
56					}
57				}
58
59				callback(cssText);
60			}
61			else{
62				win.setTimeout(checkFrameName, 100);
63			}
64		}
65		
66		win.setTimeout(checkFrameName, 500);
67	}
68
69    // https://stackoverflow.com/a/472729
70	function checkBaseURL(href) {
71        var el = document.createElement('div'),
72        escapedURL = href.split('&').join('&amp;').
73            split('<').join('&lt;').
74            split('"').join('&quot;');
75
76        el.innerHTML = '<a href="' + escapedURL + '">x</a>';
77        return el.firstChild.href;
78	}
79	
80	function checkRedirectURL() {
81		// IE6 & IE7 don't build out absolute urls in <link /> attributes.
82		// So respond.proxy.gif remains relative instead of https://example.com/respond.proxy.gif.
83		// This trickery resolves that issue.
84		if (~ !redirectURL.indexOf(location.host)) {
85
86			var fakeLink = doc.createElement("div");
87
88			fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>';
89			docElem.insertBefore(fakeLink, docElem.firstElementChild || docElem.firstChild );
90
91			// Grab the parsed URL from that dummy object
92			redirectURL = fakeLink.firstChild.href;
93
94			// Clean up
95			fakeLink.parentNode.removeChild(fakeLink);
96			fakeLink = null;
97		}
98	}
99	
100	function buildUrls(){
101		var links = doc.getElementsByTagName( "link" );
102		
103		for( var i = 0, linkl = links.length; i < linkl; i++ ){
104			
105			var thislink	= links[i],
106				href		= links[i].href,
107				extreg		= (/^([a-zA-Z:]*\/\/(www\.)?)/).test( href ),
108				ext			= (baseElem && !extreg) || extreg;
109
110			//make sure it's an external stylesheet
111			if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){
112				(function( link ){			
113					fakejax( href, function( css ){
114						link.styleSheet.rawCssText = css;
115						respond.update();
116					} );
117				})( thislink );
118			}	
119		}
120
121		
122	}
123	
124	if( !respond.mediaQueriesSupported ){
125		checkRedirectURL();
126		buildUrls();
127	}
128
129})( window, document );

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.