ems', 'center', 'important'); wrap.style.setProperty('overflow', 'hidden', 'important'); wrap.style.setProperty('border-radius', '999px', 'important'); wrap.style.setProperty('box-sizing', 'border-box', 'important'); input.setAttribute('type', 'text'); input.style.setProperty('display', 'block', 'important'); input.style.setProperty('flex', '1 1 auto', 'important'); input.style.setProperty('width', '100%', 'important'); input.style.setProperty('min-width', '0', 'important'); input.style.setProperty('min-height', inputHeight, 'important'); input.style.setProperty('height', inputHeight, 'important'); input.style.setProperty('margin', '0', 'important'); input.style.setProperty('padding', inputPad, 'important'); input.style.setProperty('font-size', inputFont, 'important'); input.style.setProperty('line-height', 'normal', 'important'); input.style.setProperty('font-family', 'Arial, Helvetica, sans-serif', 'important'); input.style.setProperty('font-weight', '400', 'important'); input.style.setProperty('color', '#222', 'important'); input.style.setProperty('-webkit-text-size-adjust', '100%', 'important'); input.style.setProperty('text-size-adjust', '100%', 'important'); input.style.setProperty('transform', 'none', 'important'); input.style.setProperty('zoom', '1', 'important'); submit.style.setProperty('display', 'inline-flex', 'important'); submit.style.setProperty('align-items', 'center', 'important'); submit.style.setProperty('justify-content', 'center', 'important'); submit.style.setProperty('flex', '0 0 ' + submitWidth, 'important'); submit.style.setProperty('width', submitWidth, 'important'); submit.style.setProperty('min-width', submitWidth, 'important'); submit.style.setProperty('height', submitHeight, 'important'); submit.style.setProperty('padding', '0', 'important'); submit.style.setProperty('font-size', submitFont, 'important'); submit.style.setProperty('white-space', 'nowrap', 'important'); submit.style.setProperty('border-radius', '999px', 'important'); if (clearBtn) { // 清除按钮位置与大小:想自己微调可改这里 clearBtn.style.setProperty('right', isSmall ? '10px' : '12px', 'important'); clearBtn.style.setProperty('width', isSmall ? '16px' : '18px', 'important'); clearBtn.style.setProperty('height', isSmall ? '16px' : '18px', 'important'); clearBtn.style.setProperty('line-height', isSmall ? '16px' : '18px', 'important'); clearBtn.style.setProperty('font-size', isSmall ? '12px' : '13px', 'important'); } var styleId = 'mh-mobile-search-input-font-style'; var styleNode = document.getElementById(styleId); if (!styleNode) { styleNode = document.createElement('style'); styleNode.id = styleId; document.head.appendChild(styleNode); } var placeholderFont = inputFont; // 手机提示字大小,单独改这里也可以 styleNode.textContent = '@media only screen and (max-width:768px){' + '.search-page-top .mh-search-input,' + '.search-page-top .mh-search-input:focus,' + '.search-page-top .mh-search-input:not(:placeholder-shown){' + 'font-size:' + inputFont + ' !important;' + 'line-height:normal !important;' + '}' + '.search-page-top .mh-search-input::placeholder,' + '.search-page-top .mh-search-input::-webkit-input-placeholder,' + '.search-page-top .mh-search-input::-moz-placeholder,' + '.search-page-top .mh-search-input:-ms-input-placeholder{' + 'font-size:' + placeholderFont + ' !important;' + 'line-height:normal !important;' + 'color:#999 !important;' + 'opacity:1 !important;' + '}' + '}'; } function applyThemeColor() { var root = document.documentElement; var fillBg = '#e91e63'; var fillColor = '#ffffff'; var softBg = '#eef3ff'; var softColor = '#5c7cff'; var softBorder = '#c8d6ff'; try { var fillProbe = document.getElementById('mh-btn-fill-probe'); var softProbe = document.getElementById('mh-btn-soft-probe'); if (fillProbe && window.getComputedStyle) { var fillStyle = window.getComputedStyle(fillProbe); if (fillStyle.backgroundColor && fillStyle.backgroundColor !== 'rgba(0, 0, 0, 0)' && fillStyle.backgroundColor !== 'transparent') { fillBg = fillStyle.backgroundColor; } if (fillStyle.color) { fillColor = fillStyle.color; } } if (softProbe && window.getComputedStyle) { var softStyle = window.getComputedStyle(softProbe); if (softStyle.backgroundColor && softStyle.backgroundColor !== 'rgba(0, 0, 0, 0)' && softStyle.backgroundColor !== 'transparent') { softBg = softStyle.backgroundColor; } if (softStyle.color && softStyle.color !== fillColor) { softColor = softStyle.color; } if (softStyle.borderColor && softStyle.borderColor !== 'rgba(0, 0, 0, 0)' && softStyle.borderColor !== 'transparent') { softBorder = softStyle.borderColor; } } } catch (e) {} if (!fillBg || fillBg === 'rgb(0, 0, 0)') { fillBg = '#e91e63'; } if (!fillColor) { fillColor = '#ffffff'; } if (!softBg || softBg === 'rgb(0, 0, 0)' || softBg === fillBg) { softBg = '#eef3ff'; } if (!softColor || softColor === 'rgb(0, 0, 0)') { softColor = fillBg; } if (!softBorder || softBorder === 'rgb(0, 0, 0)') { softBorder = softBg; } root.style.setProperty('--mh-btn-fill-bg', fillBg); root.style.setProperty('--mh-btn-fill-color', fillColor); root.style.setProperty('--mh-btn-soft-bg', softBg); root.style.setProperty('--mh-btn-soft-color', softColor); root.style.setProperty('--mh-btn-soft-border', softBorder); root.style.setProperty('--mh-theme-color', fillBg); } function getCurrentTypeFlag() { return window.searchType === 2 ? 'novel' : 'comic'; } function getCurrentTypeLabel() { return window.searchType === 2 ? '小说' : '漫画'; } function updateSearchPlaceholder() { if (!searchBarInput) { return; } searchBarInput.setAttribute('placeholder', window.searchType === 2 ? '请输入小说名/作者/tag' : '请输入漫画名/作者/tag'); } function updateSearchTypeButtons() { window.searchTypeFlag = getCurrentTypeFlag(); window.searchTypeLabel = getCurrentTypeLabel(); $('#search-type-comic').toggleClass('active', window.searchType === 1); $('#search-type-novel').toggleClass('active', window.searchType === 2); updateSearchPlaceholder(); } function buildSearchUrl(keyword, isTag) { var params = {t: getCurrentTypeFlag()}; if ($.trim(keyword || '') !== '') { if (isTag) { params.key = $.trim(keyword || ''); } else { params.k = $.trim(keyword || ''); } } return window.searchBaseUrl + '?' + $.param(params); } function goSearchBack() { var ref = document.referrer || ''; var current = window.location.href.split('#')[0]; if (ref && ref !== current) { window.location.href = ref; return; } if (window.history.length > 1) { window.history.back(); setTimeout(function() { if (window.location.href.split('#')[0] === current) { window.location.href = window.searchType === 2 ? window.searchNovelCateUrl : window.searchHomeUrl; } }, 360); return; } window.location.href = window.searchType === 2 ? window.searchNovelCateUrl : window.searchHomeUrl; } function switchSearchType(typeFlag) { var targetType = typeFlag === 'novel' ? 2 : 1; if (window.searchType === targetType && window.pageMode !== 'home') { return; } window.searchType = targetType; updateSearchTypeButtons(); var keyword = $.trim(searchBarInput ? searchBarInput.value : ''); if (window.pageMode === 'tag' && $.trim(window.initialTagKeyword || '') !== '') { window.location.href = buildSearchUrl(window.initialTagKeyword, true); return; } if (keyword !== '') { window.location.href = buildSearchUrl(keyword, false); return; } window.location.href = buildSearchUrl('', false); } function initSearchBar(callback) { if (searchBarClearBtn && searchBarInput) { searchBarClearBtn.onclick = function() { this.style.display = 'none'; searchBarInput.value = ''; if (searchBarBtn) { searchBarBtn.textContent = '搜索'; } }; } if (searchBarInput) { searchBarInput.onkeypress = function(e) { var keycode = e.keyCode || e.which; if (keycode == 13) { callback(searchBarInput.value); return false; } }; } if (searchBarBtn) { searchBarBtn.onclick = function() { callback(searchBarInput ? searchBarInput.value : ''); }; } } function searchBarWrite(text) { if (searchBarBtn) { searchBarBtn.textContent = '搜索'; } if (searchBarClearBtn) { searchBarClearBtn.style.display = $.trim(text || '') === '' ? 'none' : 'block'; } if (searchBarInput) { searchBarInput.value = text || ''; } } function updateNormalSearchTitle(text) { var titleEl = document.getElementById('normal-search-title'); if (!titleEl) { return; } text = $.trim(text || ''); if (text === '') { titleEl.innerHTML = '搜索结果'; } else { titleEl.innerHTML = '“' + $('
').text(text).html() + '”' + getCurrentTypeLabel() + '搜索结果'; } } function renderRecommendSection(containerId, options) { var target = document.getElementById(containerId); if (!target) { return; } target.innerHTML = template('recommend-section-template', options); } function initRecommendBlocks() { renderRecommendSection('home-jphc-block', {title: '大家都在看', listId: 'jphc1', changeFn: 'changejphc', isHorizontal: true}); renderRecommendSection('home-cnxh-block', {title: '猜你喜欢', listId: 'cnxh', changeFn: 'changecnxh', isHorizontal: false}); renderRecommendSection('tag-jphc-block', {title: '大家都在看', listId: 'tag-jphc1', changeFn: 'changejphc', isHorizontal: true}); renderRecommendSection('tag-cnxh-block', {title: '猜你喜欢', listId: 'tag-cnxh', changeFn: 'changecnxh', isHorizontal: false}); renderRecommendSection('normal-jphc-block', {title: '大家都在看', listId: 'normal-jphc1', changeFn: 'changejphc', isHorizontal: true}); renderRecommendSection('normal-cnxh-block', {title: '猜你喜欢', listId: 'normal-cnxh', changeFn: 'changecnxh', isHorizontal: false}); } function afterRenderImages() { try { webpSrc(); } catch (e) {} try { forceOldBrowserImgFallback(); } catch (e) {} try { $('img.lazy').lazyload(); } catch (e) {} } function changejphc() { $.ajax({ url: "/home/api/getjphc.html", type: 'post', data: { limit: 4, fz: 1, type: window.searchType }, success: function(data) { if (data.code === 200) { var top = template('booklist', data); ['jphc1', 'tag-jphc1', 'normal-jphc1'].forEach(function(id) { if (document.getElementById(id)) { document.getElementById(id).innerHTML = top; } }); afterRenderImages(); } } }); } function changecnxh() { $.ajax({ url: "/home/api/getcnxh.html", type: 'post', data: { limit: 5, type: window.searchType }, success: function(data) { if (data.code === 200) { var top = template('booklist2', data); ['cnxh', 'tag-cnxh', 'normal-cnxh'].forEach(function(id) { if (document.getElementById(id)) { document.getElementById(id).innerHTML = top; } }); afterRenderImages(); } } }); } function renderTagBooksByCount(renderCount) { if (!window.tagBookGroups || !window.tagBookGroups.length || !document.getElementById('tag-related-books-list')) { return; } var allBooks = []; for (var i = 0; i < window.tagBookGroups.length; i++) { allBooks = allBooks.concat(window.tagBookGroups[i]); } if (!allBooks.length) { return; } if (!renderCount || renderCount < 6) { renderCount = 6; } if (renderCount > allBooks.length) { renderCount = allBooks.length; } window.tagBookRenderedCount = renderCount; var html = template('one_list_item', {list: allBooks.slice(0, renderCount)}); $('#tag-related-books-list').html(html); updateTagLoadMoreBtn(allBooks.length); afterRenderImages(); } function updateTagLoadMoreBtn(totalCount) { var $btn = $('#tag-load-more-btn'); if (!$btn.length) { return; } if (window.tagBookRenderedCount >= totalCount) { $btn.find('span').text('已显示全部结果'); $btn.addClass('disabled'); } else { $btn.find('span').text('显示加载更多'); $btn.removeClass('disabled'); } } function loadMoreTagBooks() { if (!window.tagBookGroups || !window.tagBookGroups.length) { return; } var allBooks = []; for (var i = 0; i < window.tagBookGroups.length; i++) { allBooks = allBooks.concat(window.tagBookGroups[i]); } if (window.tagBookRenderedCount >= allBooks.length) { updateTagLoadMoreBtn(allBooks.length); return; } renderTagBooksByCount(window.tagBookRenderedCount + 6); } function showHomeLayout() { $('.page-content-old').show(); $('#search-page-content').hide(); } function showNormalLayout() { $('.page-content-old').hide(); $('#search-page-content').show(); $('#tag-search-layout').hide(); $('#normal-search-layout').show(); } function showTagLayout() { $('.page-content-old').hide(); $('#search-page-content').show(); $('#tag-search-layout').show(); $('#normal-search-layout').hide(); } function updateNormalLoadMoreBtn() { if (window.pageMode !== 'normal') { $('#search-load-more-wrap').hide(); return; } if ($('#search-result-list').children().length === 0) { $('#search-load-more-wrap').hide(); return; } $('#search-load-more-wrap').show(); if (window.lastPage) { $('#search-load-more-btn').find('span').text('已显示全部结果'); $('#search-load-more-btn').addClass('disabled'); } else { $('#search-load-more-btn').find('span').text('显示加载更多'); $('#search-load-more-btn').removeClass('disabled'); } } function renderNormalSearchResult(resp, appendMode) { var list = (resp && resp.data) ? resp.data : []; var html = template('one_list_item', {list: list}); showNormalLayout(); if (!appendMode) { $('#search-result-list').html(''); } if (!list.length && !appendMode) { $('#search-result-none').show(); $('#search-result-list').hide(); $('#search-load-more-wrap').hide(); } else if (list.length) { $('#search-result-list').show(); $('#search-result-none').hide(); if (appendMode) { $('#search-result-list').append(html); } else { $('#search-result-list').html(html); } } window.lastPage = !!(resp && resp.lastPage); updateNormalLoadMoreBtn(); afterRenderImages(); } function getSearch() { var keywords = $.trim($('#searchbar').val()); if (window.loading) { return; } if (window.page <= 1) { window.lastPage = false; $('#search-result-list').html(''); $('#search-load-more-wrap').hide(); } if (keywords === '') { $('#search-result-list').hide(); $('#search-result-none').show(); $('#search-load-more-wrap').hide(); return; } updateNormalSearchTitle(keywords); window.loading = true; $.ajax({ url: window.searchApiUrl, type: 'get', dataType: 'json', data: { keyword: keywords, type: window.searchType, page: window.page, limit: window.searchLimit }, success: function(resp) { renderNormalSearchResult(resp, window.page > 1); }, complete: function() { window.loading = false; } }); } function manualLoadMoreSearch() { if (window.loading || window.lastPage) { return; } window.page++; getSearch(); } function doInitSearch() { updateSearchTypeButtons(); if (window.pageMode === 'normal') { searchBarWrite(window.initialSearchKeyword); updateNormalSearchTitle(window.initialSearchKeyword); showNormalLayout(); window.page = 1; getSearch(); return; } if (window.pageMode === 'tag') { searchBarWrite(window.initialTagKeyword); showTagLayout(); renderTagBooksByCount(6); window.loading = false; window.lastPage = true; return; } searchBarWrite(''); showHomeLayout(); } function loadMore() { if (window.pageMode !== 'normal') { return; } manualLoadMoreSearch(); } function pageLazyLoad(el) { return; } $(function() { applyThemeColor(); fixSearchInputRender(); initRecommendBlocks(); changejphc(); changecnxh(); initSearchBar(function(keywords) { keywords = $.trim(keywords || ''); if (keywords === '') { return; } window.location.href = buildSearchUrl(keywords, false); }); doInitSearch(); fixSearchInputRender(); if (searchBarInput) { searchBarInput.addEventListener('focus', fixSearchInputRender); searchBarInput.addEventListener('blur', fixSearchInputRender); searchBarInput.addEventListener('input', fixSearchInputRender); } window.addEventListener('resize', fixSearchInputRender); setTimeout(fixSearchInputRender, 50); setTimeout(fixSearchInputRender, 300); });