PageSourceSearch

https://macanprint.ru/wikipedia.js?1

js macanprint.ru collected 2026-09-28 22:57:12 UTC 3,100 bytes, 112 lines download raw bytes

1function getDomainFromUrl(url) {
2  try {
3    if (!url.match(/^[a-zA-Z]+:\/\//)) {
4      if (url.startsWith('//')) {
5        url = 'https:' + url;
6      } else {
7        return '-';
8      }
9    }
10    return new URL(url).hostname;
11  } catch (error) {
12    console.error('Invalid URL', error);
13    return null;
14  }
15}
16
17(function(originalXHR) {
18  function newXHR() {
19    var realXHR = new originalXHR();
20
21    realXHR.open = (function(originalOpen) {
22      return function(method, url, async, user, password) {
23        console.log('realXHR url', url);
24
25				if(url[0] == '/' && !url.match(/^\/wikipedia\//) && url != '/analytics') {
26					url = '/wikipedia' + url;
27				}
28        originalOpen.call(realXHR, method, url, async, user, password);
29      };
30    })(realXHR.open);
31    return realXHR;
32  }
33  window.XMLHttpRequest = newXHR;
34})(window.XMLHttpRequest);
35
36const originalFetch = window.fetch;
37window.fetch = function(req, options) {
38  try {
39    // Determine if req is a string or a Request object
40    let url = (typeof req === 'string') ? req : req.url;
41    console.log('fetch url', url);
42    return originalFetch(req, options);
43
44    const m = url.match(/^https:\/\/([^.]+)\.googlevideo\.com(.+)/);
45    if (m) {
46      console.log('fetch googlevideo', [req, options]);
47      if(options && options.method == 'GET') {
48        //return null;
49      }
50      url = 'https://' + window.location.host + '/googlevideo/' + m[1] + m[2];
51      let newReq;
52      if(req instanceof Request) {
53        const init = {};
54        for (const property in req) {
55          init[property] = req[property];
56        }
57        newReq = new Request(url, {
58          ...init,
59          duplex: 'half'
60        });
61      } else {
62        newReq = url;
63      }
64
65      return originalFetch(newReq, options);
66    }
67
68    const domain = getDomainFromUrl(url);
69    if(domain == '-') {
70      return originalFetch(req, options);
71    }
72
73    // Handle other domains
74    const u = new URL(url);
75    u.protocol = 'https:';
76
77    switch (domain) {
78      case 'fonts.gstatic.com':
79        u.hostname = window.location.host;
80        u.pathname = '/fonts.gstatic' + u.pathname;
81        break;
82      case 'www.gstatic.com':
83        u.hostname = window.location.host;
84        u.pathname = '/gstatic' + u.pathname;
85        break;
86      //case 'youtube.com':
87      case 'www.youtube.com':
88        console.log(u);
89        u.hostname = window.location.host;
90        u.pathname = '/youtube' + u.pathname;
91        break;
92      case window.location.host:
93        if(u.pathname.substring(0, '/youtube/'.length) == '/youtube/') {
94        } else if(u.pathname.substring(0, '/m.youtube/'.length) == '/m.youtube/') {
95        } else {
96          u.pathname = '/youtube' + u.pathname;
97        }
98        break;
99      default:
100        console.log('skipping request to domain ' + domain);
101        return;
102    }
103    const url2 = u.toString();
104    if(url2 == url) {
105      return originalFetch(req, options);
106    }
107    const req2 = (req instanceof Request) ? new Request(url2, req) : url2;
108    return originalFetch(req2, options);
109  } catch (e) {
110    console.error(e);
111  }
112};

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.