Skip to content

Commit

Permalink
Add wallhaven
Browse files Browse the repository at this point in the history
  • Loading branch information
trmdi committed Nov 24, 2024
1 parent bdce899 commit 9cf6425
Show file tree
Hide file tree
Showing 9 changed files with 509 additions and 6 deletions.
4 changes: 4 additions & 0 deletions _locales/vi/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Default group": "Default group",
"Folder": "Thư mục",
"Photo by <name>": "Ảnh tạo bởi <name>",
"Photo from Wallhaven": "Ảnh từ Wallhaven",
"Editing": "Đang sửa",
"No selection": "Không chọn",
"Grid position": "Vị trí",
Expand Down Expand Up @@ -81,6 +82,9 @@
"Unsplash collection": "Bộ sưu tập Unsplash",
"Tips on Unsplash collections": "Mẹo về bộ sưu tập Unsplash",
"Type the collection ID from its URL, add more by separating them with a comma.": "Nhập ID bộ sưu tập từ URL của nó, thêm nhiều ID bằng cách phân tách chúng bằng dấu phẩy.",
"Wallhaven parameters": "Tham số Wallhaven",
"Tips on Wallhaven parameters": "Mẹo về tham số Wallhaven",
"Type the full search URL, or keywords.": "Nhập URL tìm kiếm, hoặc từ khóa.",
"Blur intensity": "Làm mờ",
"Brightness": "Độ sáng",
"Quick Links": "Liên kết nhanh",
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const SYNC_DEFAULT: Sync.Storage = {
pausedImage: undefined,
time: undefined,
},
wallhaven: {
every: 'hour',
parameters: '',
lastParams: 'day',
pausedImage: undefined,
time: undefined,
},
weather: {
ccode: undefined,
city: undefined,
Expand Down Expand Up @@ -193,4 +200,11 @@ export const LOCAL_DEFAULT: Local.Storage = {
night: [],
user: [],
},
wallhavenCache: {
noon: [],
day: [],
evening: [],
night: [],
user: [],
},
}
27 changes: 23 additions & 4 deletions src/scripts/features/backgrounds/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unsplashBackgrounds from './unsplash'
import wallhavenBackgrounds from './wallhaven'
import localBackgrounds from './local'
import { rgbToHex } from '../../utils'
import { eventDebounce } from '../../utils/debounce'
Expand Down Expand Up @@ -30,7 +31,13 @@ export default function initBackground(data: Sync.Storage, local: Local.Storage)
bgsecond.style.transform = 'scale(1.1) translateX(0px) translate3d(0, 0, 0)'
}

type === 'local' ? localBackgrounds() : unsplashBackgrounds({ unsplash: data.unsplash, cache: local.unsplashCache })
if (type === 'local') {
localBackgrounds()
} else if (type === 'unsplash') {
unsplashBackgrounds({ unsplash: data.unsplash, cache: local.unsplashCache })
} else if (type === 'wallhaven') {
wallhavenBackgrounds({ wallhaven: data.wallhaven, cache: local.wallhavenCache })
}
}

//
Expand Down Expand Up @@ -86,14 +93,26 @@ export function backgroundFilter({ blur, brightness, isEvent }: FilterOptions) {

export function updateBackgroundOption({ freq, refresh }: UpdateOptions) {
const i_type = document.getElementById('i_type') as HTMLInputElement
const isLocal = i_type.value === 'local'
const type = i_type.value || 'unsplash'

if (freq !== undefined) {
isLocal ? localBackgrounds({ freq }) : unsplashBackgrounds(undefined, { every: freq })
if (type === 'local') {
localBackgrounds({ freq })
} else if (type === 'unsplash') {
unsplashBackgrounds(undefined, { every: freq })
} else if (type === 'wallhaven') {
wallhavenBackgrounds(undefined, { every: freq })
}
}

if (refresh) {
isLocal ? localBackgrounds({ refresh }) : unsplashBackgrounds(undefined, { refresh })
if (type === 'local') {
localBackgrounds({ refresh })
} else if (type === 'unsplash') {
unsplashBackgrounds(undefined, { refresh })
} else if (type === 'wallhaven') {
wallhavenBackgrounds(undefined, { refresh })
}
}
}

Expand Down
Loading

0 comments on commit 9cf6425

Please sign in to comment.