Skip to content

Commit

Permalink
fixed m.youtube.com search bar not displayed issue; updated index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed Apr 23, 2020
1 parent b8a3246 commit 069d4b0
Show file tree
Hide file tree
Showing 9 changed files with 1,092 additions and 80 deletions.
30 changes: 21 additions & 9 deletions Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ var enableCors = function(req, res) {
}
};

var redirect2HomePage = function({res, httpprefix, serverName,} ) {
try {
res.setHeader('location',`${httpprefix}://${serverName}`)
} catch(e) {
logSave(`error: ${e}`)
return
}
res.status(302).send(``)
}

let getHostFromReq = (req) => { //return target
// url: http://127.0.0.1:8011/https/www.youtube.com/xxx/xxx/...
let https_prefix = '/https/'
Expand Down Expand Up @@ -114,7 +124,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
if (!req.url) {
return
}
if (req.url.indexOf(site) !== -1 || req.headers['referer'].indexOf(site) !== -1) {
if (req.url.indexOf(site) !== -1 || (req.headers['referer'] && req.headers['referer'].indexOf(site) !== -1)) {
keys = Object.keys(siteSpecificReplace[site])
keys.forEach( key => {
myRe = new RegExp(key, 'g') // match group
Expand Down Expand Up @@ -188,7 +198,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
if ((err.code && (err.code === 'ECONNREFUSED'|| err.code === 'EHOSTUNREACH'|| err.code === 'EPROTO'||
err.code === 'ECONNRESET'|| err.code === 'ENOTFOUND')) ||
(err.reason && err.reason.indexOf('Expected') === -1)) {
res.status(404).send(`{"error": "${err}"}`)
redirect2HomePage({res, httpprefix, serverName,})
}
} catch(e) {
logSave(`error of sending 404: ${e}`)
Expand Down Expand Up @@ -225,7 +235,8 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
proxyRes.headers["content-type"].indexOf('urlencoded') !== -1 ||
proxyRes.headers["content-type"].indexOf('json') !== -1) {
if (!gunzipped) {
res.status(404).send(`{"error":"failed unzip"}`)
// res.status(404).send(`{"error":"failed unzip"}`)
redirect2HomePage({res, httpprefix, serverName,})
return
}
logSave(`utf-8 text...`)
Expand Down Expand Up @@ -316,7 +327,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
if (res.statusCode === 404) {
try {
delete res.headers['content-length'] //remove content-length field
res.status(404).send("")
redirect2HomePage({res, httpprefix, serverName,})
} catch(e) {
logSave(`error: ${e}`)
}
Expand All @@ -331,15 +342,16 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai

let {host, httpType} = getHostFromReq(req)
for (let i=0; i<blockedSites.length; i++) {
let site = blockedSites[i]
let site = blockedSites[i]
if (site === host) {
res.status(404).send(`{"blockedSite":true}`)
redirect2HomePage({res, httpprefix, serverName,})
return
}
}
console.log(`httpType:${httpType}, host:${host}`)
let timestr = new Date().toISOString()
console.log(`[${timestr}] route:${fwdStr}, httpType:${httpType}, host:${host}`)
if (host.indexOf(serverName) !== -1 || // we cannot request resource from proxy itself
host == '' || host.indexOf('.') === -1 || (fwdStr && fwdStr.split(',').length > 3)) { // too many forwardings
host == '' || host.indexOf('.') === -1 || (fwdStr && fwdStr.split(',').length > 1)) { // too many forwardings
res.status(404).send("{}")
return
}
Expand All @@ -365,7 +377,7 @@ let Proxy = ({blockedSites, urlModify, httpprefix, serverName, port, cookieDomai
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())}`)
if(host === '' || !host) {
logSave(`------------------ sending status 404`)
res.status(404).send("{}")
redirect2HomePage({res, httpprefix, serverName,})
res.end()
}

Expand Down
15 changes: 11 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const {CookieAccessInfo, CookieJar, Cookie} = cookiejar

let config = {
httpprefix: 'https', port: 443,
serverName: 'siteproxy.herokuapp.com',
serverName: 'siteproxy.netptop.com',
}
let blockedSites = ['www.youtube.com', 'm.youtube.com', 'merlinblog.xyz']
let blockedSites = ['merlinblog.xyz']

if (process.env.herokuAddr) {
config.serverName = process.env.herokuAddr
Expand Down Expand Up @@ -161,8 +161,15 @@ const siteSpecificReplace = {
'="/sw.js"': `="/https/www.youtube.com/sw.js"`,
},
'm.youtube.com': {
'"/(results.search_query=)"': `"/https/m.youtube.com/$1"`,
},
'"/(results.search_query=)': `"/https/m.youtube.com/$1`,
'"./(results.search_query=)': `"\\/https\\/m.youtube.com\\/$1`,
'mobile-topbar-header-content search-mode"': `mobile-topbar-header-content non-search-mode"`, // enable search on youtube.
' non-search-mode cbox"': ` search-mode cbox"`
},
'www.youtube.com': {
'"/(results.search_query=)': `"/https/m.youtube.com/$1`,
'"./(results.search_query=)': `"\\/https\\/www.youtube.com\\/$1`,
},
'search.yahoo.com': {
'"./ra./click"': `"\\/https\\/search.yahoo.com\\/ra\\/click"`,
'(["\']).?/beacon': `$1${serverName}:${port}\\/https\\/search.yahoo.com\\/beacon`,
Expand Down
Binary file added favicon.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 069d4b0

Please sign in to comment.