d); window.Cookies.set('search_history', JSON.stringify(searchHistory), { expires: 365 }) window.location.href = this.locale === this.fallback ? `/search/${keyword}` : `/${this.locale}/search/${keyword}` }, getSearchHistory() { const searchHistoryText = window.Cookies.get('search_history') if (! searchHistoryText) { return [] } return JSON.parse(searchHistoryText).slice(0, 5) }, clearSearchHistory() { window.Cookies.remove('search_history') this.searchHistory = [] }, clearWatchHistory() { this.showDropdown = null if (! confirm(`你确定要清除所有观看记录?`)) { return } window.axios.delete('/').then(response => { alert(`观看记录已清除`) window.location.href = '/' }) }, localizedUrl(locale) { let path = window.location.pathname if (! path.endsWith('/')) { path = `${path}/` } path = path + window.location.search if (locale === this.fallbackLocale) { return this.removeTrailingSlash(path .replace('/cn/', '/').replace('/en/', '/').replace('/ja/', '/').replace('/ko/', '/').replace('/ms/', '/').replace('/th/', '/').replace('/de/', '/').replace('/fr/', '/') ) } if (path.startsWith('/cn/') || path.startsWith('/en/') || path.startsWith('/ja/') || path.startsWith('/ko/') || path.startsWith('/ms/') || path.startsWith('/th/') || path.startsWith('/de/') || path.startsWith('/fr/')) { return this.removeTrailingSlash(path .replace('/cn/', `/${locale}/`).replace('/en/', `/${locale}/`).replace('/ja/', `/${locale}/`).replace('/ko/', `/${locale}/`).replace('/ms/', `/${locale}/`).replace('/th/', `/${locale}/`).replace('/de/', `/${locale}/`).replace('/fr/', `/${locale}/`) ) } return this.removeTrailingSlash(`/${locale}${path}`) }, removeTrailingSlash(url) { if (url.substr(url.length - 1) === '/') { return url.slice(0, -1) } return url.replace('/?', '?') }, redirectToBaseLocalizedUrl() { window.Cookies.set('localized', 1, { expires: 30 }) setTimeout(() => { window.location.href = '/?localized=1' }, 100) }, loadRecaptcha() { if (! this.loadedRecaptcha) { this.loadedRecaptcha = true let script = document.createElement('script') script.type = 'text/javascript'; script.src = '/' document.getElementsByTagName('head')[0].appendChild(script) } }, requireRecaptcha(callback) { grecaptcha.ready(() => { grecaptcha.execute('6Leez8oZAAAAABJqF0uuw35s7N50I1pZkIJBO1QT', { action: 'submit' }).then(recaptchaToken => { callback(recaptchaToken) }) }) }, showLoginModal(page) { this.loadRecaptcha() this.showModal.login = true if (page) { this.currentPage = page } }, requireLogin(callback) { if (! this.user) { this.loginCallback = callback this.showLoginModal() return } callback() }, handleErrorResponse(page, error) { this.errors[page] = error.response.data.errors }, setPreview(id) { if (window.innerWidth < 1024) { return } if (this.showPreview) { const previousPreview = document.getElementById(`preview-${this.showPreview}`) if (previousPreview) { previousPreview.pause() } } if (! id) { this.showPreview = id return } this.playPreview(id) }, clickPreview(id) { if (window.innerWidth >= 1024) { return } if (! this.holdPreviews.includes(id)) { event.preventDefault() this.holdPreviews.push(id) this.playPreview(id) } }, playPreview(id) { const preview = document.getElementById(`preview-${id}`) if (! preview.getAttribute('src')) { preview.addEventListener('loadedmetadata', event => { event.target.play() this.showPreview = id }) preview.setAttribute('src', preview.getAttribute('data-src')) } else { preview.play() this.showPreview = id } }, }" x-init="$nextTick(() => { for (element of document.getElementsByClassName('font-serif')) { element.style.visibility = 'visible' } searchHistory = getSearchHistory() })">