Skip to content

Commit 069d4b0

Browse files
committed
fixed m.youtube.com search bar not displayed issue; updated index.html
1 parent b8a3246 commit 069d4b0

9 files changed

+1092
-80
lines changed

Proxy.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ var enableCors = function(req, res) {
2828
}
2929
};
3030

31+
var redirect2HomePage = function({res, httpprefix, serverName,} ) {
32+
try {
33+
res.setHeader('location',`${httpprefix}://${serverName}`)
34+
} catch(e) {
35+
logSave(`error: ${e}`)
36+
return
37+
}
38+
res.status(302).send(``)
39+
}
40+
3141
let getHostFromReq = (req) => { //return target
3242
// url: http://127.0.0.1:8011/https/www.youtube.com/xxx/xxx/...
3343
let https_prefix = '/https/'
@@ -114,7 +124,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
114124
if (!req.url) {
115125
return
116126
}
117-
if (req.url.indexOf(site) !== -1 || req.headers['referer'].indexOf(site) !== -1) {
127+
if (req.url.indexOf(site) !== -1 || (req.headers['referer'] && req.headers['referer'].indexOf(site) !== -1)) {
118128
keys = Object.keys(siteSpecificReplace[site])
119129
keys.forEach( key => {
120130
myRe = new RegExp(key, 'g') // match group
@@ -188,7 +198,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
188198
if ((err.code && (err.code === 'ECONNREFUSED'|| err.code === 'EHOSTUNREACH'|| err.code === 'EPROTO'||
189199
err.code === 'ECONNRESET'|| err.code === 'ENOTFOUND')) ||
190200
(err.reason && err.reason.indexOf('Expected') === -1)) {
191-
res.status(404).send(`{"error": "${err}"}`)
201+
redirect2HomePage({res, httpprefix, serverName,})
192202
}
193203
} catch(e) {
194204
logSave(`error of sending 404: ${e}`)
@@ -225,7 +235,8 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
225235
proxyRes.headers["content-type"].indexOf('urlencoded') !== -1 ||
226236
proxyRes.headers["content-type"].indexOf('json') !== -1) {
227237
if (!gunzipped) {
228-
res.status(404).send(`{"error":"failed unzip"}`)
238+
// res.status(404).send(`{"error":"failed unzip"}`)
239+
redirect2HomePage({res, httpprefix, serverName,})
229240
return
230241
}
231242
logSave(`utf-8 text...`)
@@ -316,7 +327,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
316327
if (res.statusCode === 404) {
317328
try {
318329
delete res.headers['content-length'] //remove content-length field
319-
res.status(404).send("")
330+
redirect2HomePage({res, httpprefix, serverName,})
320331
} catch(e) {
321332
logSave(`error: ${e}`)
322333
}
@@ -331,15 +342,16 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
331342

332343
let {host, httpType} = getHostFromReq(req)
333344
for (let i=0; i<blockedSites.length; i++) {
334-
let site = blockedSites[i]
345+
let site = blockedSites[i]
335346
if (site === host) {
336-
res.status(404).send(`{"blockedSite":true}`)
347+
redirect2HomePage({res, httpprefix, serverName,})
337348
return
338349
}
339350
}
340-
console.log(`httpType:${httpType}, host:${host}`)
351+
let timestr = new Date().toISOString()
352+
console.log(`[${timestr}] route:${fwdStr}, httpType:${httpType}, host:${host}`)
341353
if (host.indexOf(serverName) !== -1 || // we cannot request resource from proxy itself
342-
host == '' || host.indexOf('.') === -1 || (fwdStr && fwdStr.split(',').length > 3)) { // too many forwardings
354+
host == '' || host.indexOf('.') === -1 || (fwdStr && fwdStr.split(',').length > 1)) { // too many forwardings
343355
res.status(404).send("{}")
344356
return
345357
}
@@ -365,7 +377,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
365377
logSave(`req host:${host}, req.url:${req.url}, proxyReq.query:${proxyReq.query} proxyReq.path:${proxyReq.path}, proxyReq.url:${proxyReq.url} proxyReq headers:${JSON.stringify(proxyReq.getHeaders())}`)
366378
if(host === '' || !host) {
367379
logSave(`------------------ sending status 404`)
368-
res.status(404).send("{}")
380+
redirect2HomePage({res, httpprefix, serverName,})
369381
res.end()
370382
}
371383

config.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const {CookieAccessInfo, CookieJar, Cookie} = cookiejar
99

1010
let config = {
1111
httpprefix: 'https', port: 443,
12-
serverName: 'siteproxy.herokuapp.com',
12+
serverName: 'siteproxy.netptop.com',
1313
}
14-
let blockedSites = ['www.youtube.com', 'm.youtube.com', 'merlinblog.xyz']
14+
let blockedSites = ['merlinblog.xyz']
1515

1616
if (process.env.herokuAddr) {
1717
config.serverName = process.env.herokuAddr
@@ -161,8 +161,15 @@ const siteSpecificReplace = {
161161
'="/sw.js"': `="/https/www.youtube.com/sw.js"`,
162162
},
163163
'm.youtube.com': {
164-
'"/(results.search_query=)"': `"/https/m.youtube.com/$1"`,
165-
},
164+
'"/(results.search_query=)': `"/https/m.youtube.com/$1`,
165+
'"./(results.search_query=)': `"\\/https\\/m.youtube.com\\/$1`,
166+
'mobile-topbar-header-content search-mode"': `mobile-topbar-header-content non-search-mode"`, // enable search on youtube.
167+
' non-search-mode cbox"': ` search-mode cbox"`
168+
},
169+
'www.youtube.com': {
170+
'"/(results.search_query=)': `"/https/m.youtube.com/$1`,
171+
'"./(results.search_query=)': `"\\/https\\/www.youtube.com\\/$1`,
172+
},
166173
'search.yahoo.com': {
167174
'"./ra./click"': `"\\/https\\/search.yahoo.com\\/ra\\/click"`,
168175
'(["\']).?/beacon': `$1${serverName}:${port}\\/https\\/search.yahoo.com\\/beacon`,

favicon.jpeg

90.4 KB
Loading

favicon.png

26.3 KB
Loading

0 commit comments

Comments
 (0)