-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
187 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# CHANGELOG | ||
|
||
## 3.7.1 | ||
|
||
- 重构:URL净化、BV号转AV号 | ||
- 优化:去除播放页网址跳变问题 | ||
- 优化:减少URL变化对浏览器历史记录的影响 | ||
|
||
## 3.7.0 | ||
|
||
- 新增:播放页 播放设定板块 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { unsafeWindow } from '$' | ||
import { error } from './logger' | ||
|
||
class URLCleaner { | ||
origReplaceState = unsafeWindow.history.replaceState | ||
origPushState = unsafeWindow.history.pushState | ||
|
||
// URL清理函数 | ||
cleanFnArr: ((url: string) => string)[] = [] | ||
|
||
constructor() { | ||
try { | ||
this.hijack() | ||
} catch (err) { | ||
error('init URLCleaner error', err) | ||
} | ||
} | ||
|
||
hijack() { | ||
unsafeWindow.history.replaceState = (data: any, unused: string, url?: string | URL | null): void => { | ||
try { | ||
if (typeof url === 'string') { | ||
// 修补url | ||
if (!url.startsWith(location.origin) && !url.startsWith(location.hostname)) { | ||
url = `${location.origin}${url.startsWith('/') ? '' : '/'}${url}` | ||
} | ||
const cleanURL = this.cleanFnArr.reduce((curr, fn) => fn(curr), url) | ||
if (location.href.endsWith(cleanURL)) { | ||
return | ||
} | ||
return this.origReplaceState.apply(unsafeWindow.history, [data, unused, cleanURL]) | ||
} | ||
return this.origReplaceState.apply(unsafeWindow.history, [data, unused, url]) | ||
} catch (err) { | ||
error('URLCleaner replaceState error', err) | ||
return this.origReplaceState.apply(unsafeWindow.history, [data, unused, url]) | ||
} | ||
} | ||
unsafeWindow.history.pushState = (data: any, unused: string, url?: string | URL | null): void => { | ||
try { | ||
if (typeof url === 'string') { | ||
if (!url.startsWith(location.origin) && !url.startsWith(location.hostname)) { | ||
url = `${location.origin}${url.startsWith('/') ? '' : '/'}${url}` | ||
} | ||
const cleanURL = this.cleanFnArr.reduce((curr, fn) => fn(curr), url) | ||
if (location.href.endsWith(cleanURL)) { | ||
return | ||
} | ||
return this.origPushState.apply(unsafeWindow.history, [data, unused, cleanURL]) | ||
} | ||
return this.origPushState.apply(unsafeWindow.history, [data, unused, url]) | ||
} catch (err) { | ||
error('URLCleaner pushState error', err) | ||
return this.origReplaceState.apply(unsafeWindow.history, [data, unused, url]) | ||
} | ||
} | ||
} | ||
|
||
clean() { | ||
try { | ||
const cleanURL = this.cleanFnArr.reduce((curr, fn) => fn(curr), location.href) | ||
if (location.href !== cleanURL) { | ||
this.origReplaceState.apply(unsafeWindow.history, [null, '', cleanURL]) | ||
} | ||
} catch (err) { | ||
error('init URLCleaner error', err) | ||
} | ||
} | ||
} | ||
|
||
// 单例 | ||
const URLCleanerInstance = new URLCleaner() | ||
export default URLCleanerInstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters