From 74159677dbb28d88796032869232300a150e3c9c Mon Sep 17 00:00:00 2001 From: Hakadao Date: Sun, 12 Feb 2023 02:52:23 +0800 Subject: [PATCH] feat: add search watch history in history page --- src/background/apis/history.ts | 41 +- src/components/Button.vue | 84 ++++ src/components/Input.vue | 14 + src/contentScripts/views/History/History.vue | 427 +++++++++++++------ src/styles/variables.scss | 99 ++++- src/utils/index.ts | 4 + 6 files changed, 513 insertions(+), 156 deletions(-) create mode 100644 src/components/Button.vue create mode 100644 src/components/Input.vue diff --git a/src/background/apis/history.ts b/src/background/apis/history.ts index ae39559a..57e6701c 100644 --- a/src/background/apis/history.ts +++ b/src/background/apis/history.ts @@ -10,13 +10,52 @@ export const setupHistoryAPIs = () => { .then(data => (data)) .catch(error => console.error(error)) } + else if (message.contentScriptQuery === 'searchHistoryList') { + const url = `https://api.bilibili.com/x/web-goblin/history/search?pn=${message.pn}&keyword=${message.keyword}&business=all` + return fetch(url) + .then(response => response.json()) + .then(data => (data)) + .catch(error => console.error(error)) + } // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/history&toview/history.md#%E5%88%A0%E9%99%A4%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95 else if (message.contentScriptQuery === 'deleteHistoryItem') { - const url = `https://api.bilibili.com/x/v2/history/delete?kid=${message.kid}&csrf=${message.csrf}` + const url = 'https://api.bilibili.com/x/v2/history/delete' + return fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', + }, + body: JSON.stringify({ kid: message.kid, csrf: message.csrf }), + }) + .then(response => response.json()) + .then(data => (data)) + .catch(error => console.error(error)) + } + // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/history&toview/history.md#%E6%9F%A5%E8%AF%A2%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95%E5%81%9C%E7%94%A8%E7%8A%B6%E6%80%81 + else if (message.contentScriptQuery === 'getHistoryPauseStatus') { + const url = 'https://api.bilibili.com/x/v2/history/shadow' return fetch(url) .then(response => response.json()) .then(data => (data)) .catch(error => console.error(error)) } + // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/history&toview/history.md#%E5%81%9C%E7%94%A8%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95 + else if (message.contentScriptQuery === 'setHistoryPauseStatus') { + const url = 'https://api.bilibili.com/x/v2/history/shadow/set' + return fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', + 'origin': 'https://www.bilibili.com', + }, + body: new URLSearchParams({ + switch: message.switch, + csrf: message.csrf, + }), + }) + .then(response => response.json()) + .then(data => (data)) + .catch(error => console.error(error)) + } }) } diff --git a/src/components/Button.vue b/src/components/Button.vue new file mode 100644 index 00000000..bf7b2347 --- /dev/null +++ b/src/components/Button.vue @@ -0,0 +1,84 @@ + + + + + diff --git a/src/components/Input.vue b/src/components/Input.vue new file mode 100644 index 00000000..c1df4355 --- /dev/null +++ b/src/components/Input.vue @@ -0,0 +1,14 @@ + + + + + diff --git a/src/contentScripts/views/History/History.vue b/src/contentScripts/views/History/History.vue index c8f76733..84457ee7 100644 --- a/src/contentScripts/views/History/History.vue +++ b/src/contentScripts/views/History/History.vue @@ -1,14 +1,42 @@ diff --git a/src/styles/variables.scss b/src/styles/variables.scss index e68ae762..22f4398b 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -4,6 +4,7 @@ --bew-filter-glass: blur(20px) saturate(180%); + // #region shadow --bew-shadow-1: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); --bew-shadow-2: 0 10px 15px -3px rgb(0 0 0 / 0.1), @@ -11,28 +12,85 @@ --bew-shadow-3: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); --bew-shadow-4: 0 25px 50px -12px rgb(0 0 0 / 0.25); - - --bew-theme-color: rgb(0, 161, 214); - --bew-theme-color-10: rgba(0, 161, 214, 0.1); - --bew-theme-color-20: rgba(0, 161, 214, 0.2); - --bew-theme-color-30: rgba(0, 161, 214, 0.3); - --bew-theme-color-40: rgba(0, 161, 214, 0.4); - --bew-theme-color-50: rgba(0, 161, 214, 0.5); - --bew-theme-color-60: rgba(0, 161, 214, 0.6); - --bew-theme-color-70: rgba(0, 161, 214, 0.7); - --bew-theme-color-80: rgba(0, 161, 214, 0.8); - --bew-theme-color-90: rgba(0, 161, 214, 0.9); - --bew-theme-color-100: var(--bew-theme-color); + // #endregion --bew-logo-color: var(--bew-theme-color); + // #region colors + --bew-theme-color: rgb(0 161 214); + --bew-theme-color-10: rgba(0 161 214 / 0.1); + --bew-theme-color-20: rgba(0 161 214 / 0.2); + --bew-theme-color-30: rgba(0 161 214 / 0.3); + --bew-theme-color-40: rgba(0 161 214 / 0.4); + --bew-theme-color-50: rgba(0 161 214 / 0.5); + --bew-theme-color-60: rgba(0 161 214 / 0.6); + --bew-theme-color-70: rgba(0 161 214 / 0.7); + --bew-theme-color-80: rgba(0 161 214 / 0.8); + --bew-theme-color-90: rgba(0 161 214 / 0.9); + + --bew-info-color: rgb(56 189 248); + --bew-info-color-10: rgba(56 189 248 / 0.1); + --bew-info-color-20: rgba(56 189 248 / 0.2); + --bew-info-color-30: rgba(56 189 248 / 0.3); + --bew-info-color-40: rgba(56 189 248 / 0.4); + --bew-info-color-50: rgba(56 189 248 / 0.5); + --bew-info-color-60: rgba(56 189 248 / 0.6); + --bew-info-color-70: rgba(56 189 248 / 0.7); + --bew-info-color-80: rgba(56 189 248 / 0.8); + --bew-info-color-90: rgba(56 189 248 / 0.9); + + --bew-success-color: rgb(110 231 183); + --bew-success-color-10: rgba(110 231 183 / 0.1); + --bew-success-color-20: rgba(110 231 183 / 0.2); + --bew-success-color-30: rgba(110 231 183 / 0.3); + --bew-success-color-40: rgba(110 231 183 / 0.4); + --bew-success-color-50: rgba(110 231 183 / 0.5); + --bew-success-color-60: rgba(110 231 183 / 0.6); + --bew-success-color-70: rgba(110 231 183 / 0.7); + --bew-success-color-80: rgba(110 231 183 / 0.8); + --bew-success-color-90: rgba(110 231 183 / 0.9); + + --bew-warning-color: rgb(250 204 21); + --bew-warning-color-10: rgba(250 204 21 / 0.1); + --bew-warning-color-20: rgba(250 204 21 / 0.2); + --bew-warning-color-30: rgba(250 204 21 / 0.3); + --bew-warning-color-40: rgba(250 204 21 / 0.4); + --bew-warning-color-50: rgba(250 204 21 / 0.5); + --bew-warning-color-60: rgba(250 204 21 / 0.6); + --bew-warning-color-70: rgba(250 204 21 / 0.7); + --bew-warning-color-80: rgba(250 204 21 / 0.8); + --bew-warning-color-90: rgba(250 204 21 / 0.9); + + --bew-error-color: rgb(251 114 153); + --bew-error-color-10: rgba(251 114 153 / 0.1); + --bew-error-color-20: rgba(251 114 153 / 0.2); + --bew-error-color-30: rgba(251 114 153 / 0.3); + --bew-error-color-40: rgba(251 114 153 / 0.4); + --bew-error-color-50: rgba(251 114 153 / 0.5); + --bew-error-color-60: rgba(251 114 153 / 0.6); + --bew-error-color-70: rgba(251 114 153 / 0.7); + --bew-error-color-80: rgba(251 114 153 / 0.8); + --bew-error-color-90: rgba(251 114 153 / 0.9); + // #endregion + + // #region text colors --bew-text-1: hsl(217, 33%, 17%); --bew-text-2: hsl(215, 19%, 35%); --bew-text-3: hsl(215, 19%, 55%); + --bew-text-4: hsl(215, 19%, 72%); + // #endregion + + --bew-bg: hsl(220, 14%, 94%); + + --bew-content-opacity: 0.6; + + // #region content colors, used to buttons, cards, popover and so on + --bew-content-1: hsl(0 0% 100% / var(--bew-content-opacity)); + --bew-content-1-hover: hsl(0 0% 85% / var(--bew-content-opacity)); - --bew-bg: rgb(243 244 246); - --bew-content-1: hsl(0 0% 100% / 60%); --bew-content-solid-1: hsl(0 0% 100%); + --bew-content-solid-1-hover: hsl(0 0% 85%); + // #endregion --bew-fill-1: rgb(120 120 128 / 12%); --bew-fill-2: rgb(120 120 128 / 22%); @@ -49,18 +107,15 @@ --bew-text-3: hsl(215, 19%, 50%); --bew-bg: hsl(230 12% 6%); - --bew-content-1: hsl(230 12% 13% / 60%); + + --bew-content-1: hsl(230 12% 13% / var(--bew-content-opacity)); + --bew-content-1-hover: hsl(230 12% 25% / var(--bew-content-opacity)); + --bew-content-solid-1: hsl(230 12% 13%); + --bew-content-solid-1-hover: hsl(230 12% 25%); --bew-fill-1: rgb(120 120 128 / 16%); --bew-fill-2: rgb(120 120 128 / 26%); --bew-fill-3: rgb(120 120 128 / 36%); --bew-fill-4: rgb(120 120 128 / 46%); } - -@supports not (backdrop-filter: blur(15px)) { - :root, - :root.dark { - --bew-content-1: var(--bew-content-solid-1); - } -} diff --git a/src/utils/index.ts b/src/utils/index.ts index e3f1029b..90ebc411 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -48,3 +48,7 @@ export const getCSRF = () => getCookie('bili_jct') export const removeHttpFromUrl = (url: string) => { return url.replace(/^https?:/, '') } + +export const openLinkToNewTab = (url: string) => { + window.open(url, '_blank') +}