From 3ce8b91eb0ce55bb54e0026d5d646fab04cfe4ac Mon Sep 17 00:00:00 2001 From: hole-thu Date: Sun, 22 May 2022 14:01:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=20###token=3D=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 22 ++++++++++++++++++++++ src/App.js | 26 -------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/public/index.html b/public/index.html index 9f2498c..7ea15d8 100644 --- a/public/index.html +++ b/public/index.html @@ -42,6 +42,28 @@ function force_reload() { window.location.reload(true); }, 200); } + + let token; + if (window.location.hash.startsWith('###token=')) { + token = window.location.hash.substr(9); + window.location.hash = ''; + } + + if (window.location.search.startsWith('?token')) { + token = window.location.search.substr(7); + window.location.search = ''; + } + if (token) { + if (token.endsWith(encodeURI('_任意自定义后缀'))) { + let tmp_token_suf = + localStorage['TOKEN_SUF'] || + prompt('设置一个你专属的临时token后缀吧') || + Math.random(); + localStorage['TOKEN_SUF'] = tmp_token_suf; + token = `${token.split('_')[0]}_${tmp_token_suf}`; + } + localStorage['TOKEN'] = token; + } diff --git a/src/App.js b/src/App.js index 8ddf87c..2396209 100644 --- a/src/App.js +++ b/src/App.js @@ -99,32 +99,6 @@ class App extends Component { }); } - componentDidMount() { - if ( - window.location.protocol === 'http:' && - window.location.hostname !== '127.0.0.1' && - !window.location.hostname.endsWith('localhost') - ) { - window.location.protocol = 'https:'; // 因为CDN的原因先在前端做下https跳转 - return; - } - let arg = window.location.search; - console.log(arg); - if (arg.startsWith('?token=')) { - let token = arg.substr(7); - if (token.endsWith(encodeURI('_任意自定义后缀'))) { - let tmp_token_suf = - localStorage['TOKEN_SUF'] || - prompt('设置一个你专属的临时token后缀吧') || - Math.random(); - localStorage['TOKEN_SUF'] = tmp_token_suf; - token = `${token.split('_')[0]}_${tmp_token_suf}`; - } - localStorage['TOKEN'] = token; - window.location.search = ''; - } - } - render() { return (