Skip to content

Commit

Permalink
fixed youtube address bar issue while switching video
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed May 3, 2020
1 parent b20278d commit f16da56
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 35 deletions.
22 changes: 15 additions & 7 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ const pathReplace = ({host, httpType, body}) => {
let myRe = new RegExp(`href=([\"\']?)/([-a-z0-9_]+?)`, 'g')
body = body.replace(myRe, `href=$1/${httpType}/${host}/$2`)

myRe = new RegExp(`href[ ]?=[ ]?"/`, 'g')
body = body.replace(myRe, `href="/${httpType}/${host}/`)
myRe = new RegExp(`href[ ]?=[ ]?"/([-a-z0-9_])`, 'g')
body = body.replace(myRe, `href="/${httpType}/${host}/$1`)

myRe = new RegExp(`(href=\\\\")\\\\/`, 'g')
body = body.replace(myRe, `$1\\/${httpType}\\/${host}\\/`)

myRe = new RegExp(` src=([\"\']?)/([-a-z0-9_]+?)`, 'g')
body = body.replace(myRe, ` src=$1/${httpType}/${host}/$2`)
Expand All @@ -106,6 +109,9 @@ const pathReplace = ({host, httpType, body}) => {
myRe = new RegExp('("url":[ ]?")/([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

myRe = new RegExp('("url":[ ]?")(\\\\/)([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1$2${httpType}$2${host}/$3`) // {"url":"\/watch?v=tTzRY7F_1OU",...}

myRe = new RegExp('(sUrl":[ ]?")/([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

Expand Down Expand Up @@ -170,13 +176,16 @@ const siteSpecificReplace = {
'[&]{2}this\.connectedCallback[(][)][)]:': `):`, // &&this.connectedCallback()):
'="/sw.js"': `="/https/www.youtube.com/sw.js"`,
'"://"([+])': `"://${serverName}:${port}/https/"$1`,
'("././)(www.google.com)': `$1${serverName}:${port}/https/www.google.com`,
'("\\\\/\\\\/)(www.google.com)': `$1${serverName}:${port}/https/www.google.com`,
'"://([a-z]+[.]youtube.com/)"': `"://${serverName}:${port}/https/$1"`,
'"(.../).../www.google.com': `"$1$1${serverName}:${port}$1www.google.com`, // tConfig('COMMENTS_BG_IU', \"\\\/\\\/www.google.com
'"(\\\\\\\\\\\\/).../www.google.com': `"$1$1${serverName}:${port}$1www.google.com`, // tConfig('COMMENTS_BG_IU', \"\\\/\\\/www.google.com
// '(.\..=this\.fx[(][)]);return (.)': `$1;$2.bandwidthEstimate=1000.1;return $2`,// a.C=this.fx();return a
'[a-zA-Z]\.setSizeStyle[(]..,.[)]': `1`,
'a\.....\.style.display=0===.."none":"";': `;`, // a.A[c].style.display = 0 === b ? "none" : "";
},
'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"`,
'PLAYER_JS_URL":"': `PLAYER_JS_URL":"\\/https\\/m.youtube.com`,
Expand All @@ -190,8 +199,7 @@ const siteSpecificReplace = {
'PLAYER_CSS_URL":"': `PLAYER_CSS_URL":"\\/https\\/www.youtube.com`,
'(action=.")/results': `$1/https/www.youtube.com/results`,
// '"/channel': `"/https/www.youtube.com/channel`,
'"(./channel)': `"\\/https\\/www.youtube.com$1`,
'.\.....\.style.display=0===.."none":"";': `;`, // a.A[c].style.display = 0 === b ? "none" : "";
'"(\\\\/channel)': `"\\/https\\/www.youtube.com$1`,
},
'search.yahoo.com': {
'"./ra./click"': `"\\/https\\/search.yahoo.com\\/ra\\/click"`,
Expand Down
47 changes: 21 additions & 26 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ <h1 class="logo">
<!--顶部导航条-->
<nav class="nav">
<ul>
<li><a href="/contact-info" target="_blank">联系方式</a></li>
<li><a href="/contact-info" target="_self">联系方式</a></li>
</ul>
</nav>
<!--便携设备右上角菜单-->
Expand Down Expand Up @@ -773,32 +773,32 @@ <h1 class="logo">
<!--获取内容列表-->
<div class="clearfix two-list-box">
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/zh.wikipedia.org" class="card-link" target="_blank">
<a href="/https/zh.wikipedia.org" class="card-link" target="_self">
<div class="card-tit">维基百科</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.youtube.com/playlist?list=PLPVsJMpVPkCd_OUBs7Aj_dYEbwgO8ZtLY" class="card-link" target="_blank">
<a href="/https/www.youtube.com/playlist?list=PLPVsJMpVPkCd_OUBs7Aj_dYEbwgO8ZtLY" class="card-link" target="_self">
<div class="card-tit">YouTube</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/twitter.com/explore" class="card-link" target="_blank">
<a href="/https/twitter.com/explore" class="card-link" target="_self">
<div class="card-tit">Twitter</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/web.telegram.org" class="card-link" target="_blank">
<a href="/https/web.telegram.org" class="card-link" target="_self">
<div class="card-tit">Telegram登录</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="https://github.com/esu-tg/tg-app/blob/master/README.md" class="card-link" target="_blank">
<a href="https://github.com/esu-tg/tg-app/blob/master/README.md" class="card-link" target="_self">
<div class="card-tit">Telegram下载</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/t.me/s/socks5list" class="card-link" target="_blank">
<a href="/https/t.me/s/socks5list" class="card-link" target="_self">
<div class="card-tit">Telegram代理</div>
</a>
</div>
Expand All @@ -815,47 +815,47 @@ <h1 class="logo">
<!--获取内容列表-->
<div class="clearfix two-list-box">
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/cn.nytimes.com" class="card-link" target="_blank">
<a href="/https/cn.nytimes.com" class="card-link" target="_self">
<div class="card-tit">纽约时报中文网</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/cn.reuters.com/" class="card-link" target="_blank">
<a href="/https/cn.reuters.com/" class="card-link" target="_self">
<div class="card-tit">路透社中文</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/cn.wsj.com/" class="card-link" target="_blank">
<a href="/https/cn.wsj.com/" class="card-link" target="_self">
<div class="card-tit">华尔街日报</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.dw.com/zh/%E5%9C%A8%E7%BA%BF%E6%8A%A5%E5%AF%BC/s-9058" class="card-link" target="_blank">
<a href="/https/www.dw.com/zh/%E5%9C%A8%E7%BA%BF%E6%8A%A5%E5%AF%BC/s-9058" class="card-link" target="_self">
<div class="card-tit">德国之声</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/http/news.creaders.net/headline/" class="card-link" target="_blank">
<a href="/http/news.creaders.net/headline/" class="card-link" target="_self">
<div class="card-tit">万维读者</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/udn.com/news/index" class="card-link" target="_blank">
<a href="/https/udn.com/news/index" class="card-link" target="_self">
<div class="card-tit">联合新闻网</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/http/www.rfi.fr/cn/" class="card-link" target="_blank">
<a href="/http/www.rfi.fr/cn/" class="card-link" target="_self">
<div class="card-tit">法国广播电台</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/asahichinese-f.com/" class="card-link" target="_blank">
<a href="/https/asahichinese-f.com/" class="card-link" target="_self">
<div class="card-tit">朝日新闻</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.zaobao.com.sg/" class="card-link" target="_blank">
<a href="/https/www.zaobao.com.sg/" class="card-link" target="_self">
<div class="card-tit">新加坡联合早报</div>
</a>
</div>
Expand All @@ -872,22 +872,17 @@ <h1 class="logo">
<!--获取内容列表-->
<div class="clearfix two-list-box">
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.wenxuecity.com" class="card-link" target="_blank">
<div class="card-tit">文学城</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.6parknews.com" class="card-link" target="_blank">
<a href="/https/www.6parknews.com" class="card-link" target="_self">
<div class="card-tit">留园网</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/https/www.mitbbs.com" class="card-link" target="_blank">
<a href="/http/www.mitbbs.com" class="card-link" target="_self">
<div class="card-tit">未名空间</div>
</a>
</div>
<div class="col-md-3 col-sm-4 col-xs-6">
<a href="/http/www.iask.ca/index.html" class="card-link" target="_blank">
<a href="/http/www.iask.ca/index.html" class="card-link" target="_self">
<div class="card-tit">加拿大家园网</div>
</a>
</div>
Expand Down Expand Up @@ -965,7 +960,7 @@ <h1 class="logo">
$('#txt').keydown(function(ev){
// 回车键的处理
if(ev.keyCode==13){
window.open(thisSearch + $('#txt').val())
window.open(thisSearch + $('#txt').val(), "_self")
// $('#txt').val('');
$('#box ul').html('')
}
Expand Down Expand Up @@ -1008,7 +1003,7 @@ <h1 class="logo">
$("#search-btn").click(function(){
var textValue = $('#txt').val();
if(textValue != ''){
window.open(thisSearch + textValue)
window.open(thisSearch + textValue, "_self")
}
});
</script>
Expand Down
47 changes: 45 additions & 2 deletions test/siteproxylocal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test('youtube url check issue', async () => {
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
console.log(`${response.data}`)
// console.log(`${response.data}`)
// expect(response.data.indexOf(`"Captions URL"`)).toBe(-1)
expect(response.data.indexOf(`("//${serverName}:${port}/https/"+this.`)).not.toBe(-1)
expect(response.data.indexOf(`://i1.ytimg.com/vi`)).toBe(-1)
Expand Down Expand Up @@ -185,6 +185,21 @@ test('youtube desktop_polymer_v2.js issue', async () => {



test('/watch url conversion', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/watch?v=ii1fTxhD_D0&spf=navigate`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
'Cookie': `VISITOR_INFO1_LIVE=WxtnB8UaTM4; YSC=QPym_D-ojR0`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${JSON.stringify(response.data)}`)
expect(JSON.stringify(response.data).indexOf(`/https/www.youtube.com/watch?v=`)).not.toBe(-1)
}, 30000);

test('youtube url conversion', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/watch?v=I9K4MbvlDss&frags=pl%2Cwn`
const response = await axios({
Expand Down Expand Up @@ -414,6 +429,34 @@ test('youtube Url www.google.com issue', async () => {
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${response.data}`)
//console.log(`${response.data}`)
expect(response.data.indexOf(`\"interpreterUrl\":\"\/\/www.google.com\/js\/bg\/jeQSBy52GP_vj-aLADK6D_RsHFfZXrt-vZElH-uv2ok.js\"`)).toBe(-1)
}, 15000); // should be done within 3 seconds.

test('youtube href fonts.googleapis.com issue', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/watch?v=5HHRBe8bskE&list=PLPVsJMpVPkCd_OUBs7Aj_dYEbwgO8ZtLY&index=6&t=0s&frags=pl%2Cwn`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${response.data}`)
expect(response.data.indexOf(`href="/https/www.youtube.com//127.0.0.1:8011/https/fonts.googleapis.com/css`)).toBe(-1)
}, 15000); // should be done within 3 seconds.

test('youtube watch address bar issue', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/watch?v=tTzRY7F_1OU&spf=navigate`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
console.log(`${JSON.stringify(response.data)}`)
expect(JSON.stringify(response.data).indexOf(`{"url":"/watch?v=tTzRY7F_1OU"`)).toBe(-1)
}, 15000); // should be done within 3 seconds.

0 comments on commit f16da56

Please sign in to comment.