From c34e166327c92155bf46859b17e10a9d9a6a094b Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:23:47 +0800 Subject: [PATCH 1/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 124 +++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 37 deletions(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index 989968d..c46ebac 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -2,8 +2,6 @@ // @name Bilibili Search Filter By Time // @namespace https://github.com/KID-joker/userscript // @version 1.1.3 -// @updateURL https://github.com/KID-joker/userscript/blob/main/bilibili-search-filter-by-time.js -// @downloadURL https://github.com/KID-joker/userscript/blob/main/bilibili-search-filter-by-time.js // @supportURL https://github.com/KID-joker/userscript/issues // @description add time filter to bilibili search results // @author KID-joker @@ -68,6 +66,8 @@ return obj } let date = 'none'; + let playAmount = 'none'; + let dateRange = []; function getDate() { let queryObj = getQueryObject(); @@ -139,13 +139,15 @@ router = app.config.globalProperties.$router; route = app.config.globalProperties.$route; if (route.name === 'video') { - insertComponent(); + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); } else { removeComponent(); } router.afterEach(route => { if (route.name === 'video') { - insertComponent(); + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); } else { removeComponent(); } @@ -169,43 +171,72 @@ }) // 插入日期过滤组件 - function insertComponent() { - if (document.querySelector('#date-search-conditions')) { + function insertComponent(selector) { + if (document.querySelector('#'+selector)) { return; } let element = document.createElement('div'); - element.id = 'date-search-conditions'; + element.id = selector; element.className = 'search-condition-row'; - element.addEventListener('click', clickDateCondition); + + let clickCondition; + if (selector === 'date-search-conditions') { + clickCondition = clickDateCondition + } else { + clickCondition = clickPlayAmountCondition + } + + element.addEventListener('click', clickCondition); let fragment = document.createDocumentFragment(); - let list = [{ - name: 'none', - title: '时间不限' - }, { - name: 'day', - title: '过去1天内' - }, { - name: 'week', - title: '过去1周内' - }, { - name: 'month', - title: '过去1月内' - }, { - name: 'year', - title: '过去1年内' - }, { - name: 'custom', - title: '自定日期范围' - }] - list.forEach(function (ele) { - let button = document.createElement('button'); - button.textContent = ele.title; - button.className = 'vui_button vui_button--tab mt_sm mr_sm'; - button.dataset.datecondition = ele.name; - if (ele.name === date) { - button.className += ' vui_button--active'; - } - fragment.appendChild(button); + let list = { + 'date-search-conditions': [{ + name: 'none', + title: '时间不限' + }, { + name: 'day', + title: '过去1天内' + }, { + name: 'week', + title: '过去1周内' + }, { + name: 'month', + title: '过去1月内' + }, { + name: 'year', + title: '过去1年内' + }, { + name: 'custom', + title: '自定日期范围' + }], + 'playAmount-search-conditions': [{ + name: 'none', + title: '播放量不限' + }, { + name: '1k', + title: '1千以上' + }, { + name: '5k', + title: '5千以上' + }, { + name: '1w', + title: '1万以上' + }, { + name: '5w', + title: '5万以上' + }] + } + list[selector].forEach(function (ele) { + let button = document.createElement('button'); + button.textContent = ele.title; + button.className = 'vui_button vui_button--tab mt_sm mr_sm'; + button.dataset.date_playAmount_condition = ele.name; + if (selector === 'date-search-conditions' && ele.name === date) { + button.className += ' vui_button--active'; + } + if (selector === 'playAmount-search-conditions' && ele.name === playAmount) { + button.className += ' vui_button--active'; + } + fragment.appendChild(button); }); element.appendChild(fragment); document.querySelector('.more-conditions').appendChild(element); @@ -283,6 +314,25 @@ filterByDate(datecondition, endTime - timeMap[datecondition], endTime); } } + // 播放量过滤点击事件 + function clickPlayAmountCondition(evt) { + let datecondition = evt.target.dataset.datecondition; + if (datecondition === 'none') { + // 时间不限 + let { date, date_range, ...query } = route.query; + routerGo(query); + } else if (datecondition) { + // 固定日期范围选择 + let endTime = Date.now(); + let timeMap = { + 'day': 86400000, + 'week': 604800000, + 'month': 2592000000, + 'year': 31536000000 + } + filterByDate(datecondition, endTime - timeMap[datecondition], endTime); + } + } function filterByDate(datecondition, startTime, endTime) { let { page, o, ...query } = route.query; @@ -424,4 +474,4 @@ st.charAt(St) && Et.push(st.charAt(St)) }), Et.join("").slice(0, 32) } -})(); \ No newline at end of file +})(); From bf1cb90c1de25e854ecfe2de0111e20847180cef Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:54:15 +0800 Subject: [PATCH 2/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 93 ++++++++++++++++++------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index c46ebac..a0b8ce1 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -69,15 +69,15 @@ let playAmount = 'none'; let dateRange = []; - function getDate() { + function getFromQuery() { let queryObj = getQueryObject(); date = queryObj.date || 'none'; - dateRange = queryObj.date_range || []; + dateRange = queryObj.date_range || []; // 填充默认值 if (date !== 'none') { dateRange = dateRange.split('_'); } } - getDate(); + getFromQuery(); // 返回json结果 let responseJson = null; @@ -103,7 +103,7 @@ unsafeWindow.fetch = async function (url, options) { // 只针对视频搜索接口 let params = options && options.params; - if (url.indexOf('x/web-interface/wbi/search/type') > -1 && params.search_type === 'video' && date !== 'none') { + if (url.indexOf('x/web-interface/wbi/search/type') > -1 && params.search_type === 'video' && (date !== 'none' || playAmount !== 'none')) { // 暂停上报 const originReportObserver = unsafeWindow.reportObserver; unsafeWindow.reportObserver = null; @@ -139,18 +139,18 @@ router = app.config.globalProperties.$router; route = app.config.globalProperties.$route; if (route.name === 'video') { - insertComponent('date-search-conditions'); - insertComponent('playAmount-search-conditions'); + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); } else { - removeComponent(); + removeComponent(); } router.afterEach(route => { - if (route.name === 'video') { - insertComponent('date-search-conditions'); - insertComponent('playAmount-search-conditions'); - } else { - removeComponent(); - } + if (route.name === 'video') { + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); + } else { + removeComponent(); + } }) // const vnode = route.matched.find(ele => ele.name == 'video').instances.default._; @@ -246,20 +246,33 @@ const dateCondition = document.querySelector('#date-search-conditions') if (dateCondition) { document.querySelector('.more-conditions').removeChild(dateCondition); + } + + const Condition2 = document.querySelector('#playAmount-search-conditions') + if (Condition2) { + document.querySelector('.more-conditions').removeChild(Condition2); } } // 更新日期按钮状态 function updateComponent() { - const dateCondition = document.querySelector('#date-search-conditions') - if (dateCondition) { - [...dateCondition.children].forEach(btn => { - if (btn.dataset.datecondition == date) { - btn.classList.add("vui_button--active") - } else { - btn.classList.remove("vui_button--active"); - } - }) - } + ['#date-search-conditions', '#playAmount-search-conditions'].forEach(selectorr => { + const dateCondition = document.querySelector(selectorr) + if (dateCondition) { + [...dateCondition.children].forEach(btn => { + let conditionActive; + if (selectorr === '#date-search-conditions') { + conditionActive = date; + } else { + conditionActive = playAmount; + } + if (btn.dataset.date_playAmount_condition == conditionActive) { + btn.classList.add("vui_button--active") + } else { + btn.classList.remove("vui_button--active"); + } + }) + } + }); } function routerGo(query) { @@ -268,7 +281,7 @@ query }); setTimeout(() => { - getDate(); + getFromQuery(); updateComponent(); searchBtn.click(); }); @@ -276,10 +289,10 @@ // 日期过滤点击事件 function clickDateCondition(evt) { - let datecondition = evt.target.dataset.datecondition; + let datecondition = evt.target.dataset.date_playAmount_condition; if (datecondition === 'none') { // 时间不限 - let { date, date_range, ...query } = route.query; + let { date, date_range, ...query } = route.query; // 删除date和date_range属性 routerGo(query); } else if (datecondition === 'custom') { // 自定义日期范围,弹出日期选择弹窗 @@ -316,21 +329,24 @@ } // 播放量过滤点击事件 function clickPlayAmountCondition(evt) { - let datecondition = evt.target.dataset.datecondition; - if (datecondition === 'none') { + let playAmountcondition = evt.target.dataset.date_playAmount_condition; + if (playAmountcondition === 'none') { // 时间不限 - let { date, date_range, ...query } = route.query; + let { playAmount, play_Amount, ...query } = route.query; routerGo(query); - } else if (datecondition) { + } else if (playAmountcondition) { // 固定日期范围选择 - let endTime = Date.now(); - let timeMap = { - 'day': 86400000, - 'week': 604800000, - 'month': 2592000000, - 'year': 31536000000 + let Map = { + '1k': 1000, + '5k': 5000, + '1w': 10000, + '5w': 50000 } - filterByDate(datecondition, endTime - timeMap[datecondition], endTime); + // filterByDate(datecondition, endTime - timeMap[datecondition], endTime); + let { page, o, ...query } = route.query; + query.playAmount = playAmountcondition; + query.play_Amount = Map[playAmountcondition] + routerGo(query); } } @@ -343,7 +359,7 @@ // 隐藏分页按钮 function changePagenationBtn() { - if (date !== 'none') { + if (date !== 'none' || playAmount !== 'none') { let pagenationBtnList = document.querySelectorAll('.vui_pagenation--btn-num'); if (pagenationBtnList.length > 0) { for (let btn of pagenationBtnList) { @@ -383,6 +399,7 @@ let _responseJson = await originFetch(url, options).then(response => { return response.json(); }); + debugger if (_responseJson.data && _responseJson.data.result) { if (_responseJson.data.result.length < pageSize) { finished = true; From cafbc914bc9c2bbae3350d7e36cdbf4c6d7a7859 Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:10:40 +0800 Subject: [PATCH 3/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index a0b8ce1..319be28 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -68,14 +68,19 @@ let date = 'none'; let playAmount = 'none'; - let dateRange = []; + let dateRange = ['946656000','1893427200']; // 2000年到2030年 + let play_Amount = 10; function getFromQuery() { - let queryObj = getQueryObject(); - date = queryObj.date || 'none'; - dateRange = queryObj.date_range || []; // 填充默认值 - if (date !== 'none') { - dateRange = dateRange.split('_'); - } + debugger + let queryObj = getQueryObject(); + date = queryObj.date || 'none'; + dateRange = queryObj.date_range || ['946656000','1893427200']; // 填充默认值 1708491642_1709096442 + if (date !== 'none') { + dateRange = dateRange.split('_'); + } + + playAmount = queryObj.playAmount || 'none'; + play_Amount = queryObj.play_Amount || 10; } getFromQuery(); @@ -407,6 +412,7 @@ } responseJson = _responseJson; let list = responseJson.data.result.filter(ele => ele.pubdate >= dateRange[0] && ele.pubdate <= dateRange[1]); + list = list.filter(ele => ele.play >= play_Amount); result = result.concat(list); } else { // 没有更多数据了 From 0280afe4985b5a6977849ef85d149d36db693c6f Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:11:31 +0800 Subject: [PATCH 4/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index 319be28..cecda31 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -228,6 +228,9 @@ }, { name: '5w', title: '5万以上' + }, { + name: '10w', + title: '1万以上' }] } list[selector].forEach(function (ele) { @@ -345,7 +348,8 @@ '1k': 1000, '5k': 5000, '1w': 10000, - '5w': 50000 + '5w': 50000, + '10w': 100000 } // filterByDate(datecondition, endTime - timeMap[datecondition], endTime); let { page, o, ...query } = route.query; From b90fac0329bfd4ea193163ba647522615085eda8 Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:11:55 +0800 Subject: [PATCH 5/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index cecda31..75e4d7a 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -230,7 +230,7 @@ title: '5万以上' }, { name: '10w', - title: '1万以上' + title: '10万以上' }] } list[selector].forEach(function (ele) { From 8d5002bf64340fc5e0b6c975aee4462be3b161c2 Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:38:24 +0800 Subject: [PATCH 6/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index 75e4d7a..c4bbbd4 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -71,7 +71,7 @@ let dateRange = ['946656000','1893427200']; // 2000年到2030年 let play_Amount = 10; function getFromQuery() { - debugger + // debugger let queryObj = getQueryObject(); date = queryObj.date || 'none'; dateRange = queryObj.date_range || ['946656000','1893427200']; // 填充默认值 1708491642_1709096442 @@ -408,7 +408,7 @@ let _responseJson = await originFetch(url, options).then(response => { return response.json(); }); - debugger + // debugger if (_responseJson.data && _responseJson.data.result) { if (_responseJson.data.result.length < pageSize) { finished = true; From 5be0575e8fef26487de1226c19b175757a002cab Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:13:26 +0800 Subject: [PATCH 7/7] Update bilibili-search-filter-by-time.js --- bilibili-search-filter-by-time.js | 875 +++++++++++++++--------------- 1 file changed, 441 insertions(+), 434 deletions(-) diff --git a/bilibili-search-filter-by-time.js b/bilibili-search-filter-by-time.js index c4bbbd4..7529dcb 100644 --- a/bilibili-search-filter-by-time.js +++ b/bilibili-search-filter-by-time.js @@ -19,8 +19,8 @@ // ==/UserScript== (function () { - // 设置样式 - let css = ` + // 设置样式 + let css = ` @media (max-width: 1099.9px) { #i_cecream .video-list-item { display:block!important; @@ -47,458 +47,465 @@ } } ` - GM_addStyle(css) - GM_addStyle(GM_getResourceText('css')); + GM_addStyle(css) + GM_addStyle(GM_getResourceText('css')); - // 获取过滤日期 - function getQueryObject(url) { - url = url == null ? unsafeWindow.location.href : url - const search = url.substring(url.lastIndexOf('?') + 1) - const obj = {} - const reg = /([^?&=]+)=([^?&=]*)/g - search.replace(reg, (rs, $1, $2) => { - const name = decodeURIComponent($1) - let val = decodeURIComponent($2) - val = String(val) - obj[name] = val - return rs - }) - return obj - } - let date = 'none'; - let playAmount = 'none'; + // 获取过滤日期 + function getQueryObject(url) { + url = url == null ? unsafeWindow.location.href : url + const search = url.substring(url.lastIndexOf('?') + 1) + const obj = {} + const reg = /([^?&=]+)=([^?&=]*)/g + search.replace(reg, (rs, $1, $2) => { + const name = decodeURIComponent($1) + let val = decodeURIComponent($2) + val = String(val) + obj[name] = val + return rs + }) + return obj + } + let date = 'none'; + let playAmount = 'none'; - let dateRange = ['946656000','1893427200']; // 2000年到2030年 - let play_Amount = 10; - function getFromQuery() { - // debugger - let queryObj = getQueryObject(); - date = queryObj.date || 'none'; - dateRange = queryObj.date_range || ['946656000','1893427200']; // 填充默认值 1708491642_1709096442 - if (date !== 'none') { - dateRange = dateRange.split('_'); - } + let dateRange = ['946656000', '1893427200']; // 2000年到2030年 + let play_Amount = 10; + function getFromQuery() { + // debugger + let queryObj = getQueryObject(); + date = queryObj.date || 'none'; + dateRange = queryObj.date_range || ['946656000', '1893427200']; // 填充默认值 1708491642_1709096442 + if (date !== 'none') { + dateRange = dateRange.split('_'); + } - playAmount = queryObj.playAmount || 'none'; - play_Amount = queryObj.play_Amount || 10; - } - getFromQuery(); + playAmount = queryObj.playAmount || 'none'; + play_Amount = queryObj.play_Amount || 10; + } + getFromQuery(); - // 返回json结果 - let responseJson = null; - // 过滤的结果 - let result = []; - // 日期过滤的页码 - let actualPage = 1; - // 显示数量 - let actualPageSize = 21; - // b站对应页面 - let requestPage = 1; - // 数量 - let pageSize = 0; - // 没有更多数据 - let finished = false; - // 最大页码 - let maxPage = 1; - // 自定义日期选择弹窗 - let fp = null; + // 返回json结果 + let responseJson = null; + // 过滤的结果 + let result = []; + // 日期过滤的页码 + let actualPage = 1; + // 显示数量 + let actualPageSize = 21; + // b站对应页面 + let requestPage = 1; + // 数量 + let pageSize = 0; + // 没有更多数据 + let finished = false; + // 最大页码 + let maxPage = 1; + // 自定义日期选择弹窗 + let fp = null; - // 重写fetch,拦截fetch请求 - const originFetch = fetch; - unsafeWindow.fetch = async function (url, options) { - // 只针对视频搜索接口 - let params = options && options.params; - if (url.indexOf('x/web-interface/wbi/search/type') > -1 && params.search_type === 'video' && (date !== 'none' || playAmount !== 'none')) { - // 暂停上报 - const originReportObserver = unsafeWindow.reportObserver; - unsafeWindow.reportObserver = null; - actualPage = params.page; - pageSize = params.page_size; - if (result.length < actualPage * actualPageSize) { - await requestData(url, options); - } - let responseResult = result.slice((actualPage - 1) * actualPageSize, actualPage * actualPageSize); - let response = new Response(); - response.json = function () { - return new Promise(resolve => { - responseJson.data.page = +actualPage; - responseJson.data.result = responseResult; - resolve(responseJson); - }) - } - setTimeout(() => { - changePagenationBtn(); - }, 0); - unsafeWindow.reportObserver = originReportObserver; - return response; - } else { - return originFetch(url, options); - } - } + // 重写fetch,拦截fetch请求 + const originFetch = fetch; + unsafeWindow.fetch = async function (url, options) { + // 只针对视频搜索接口 + let params = options && options.params; + if (url.indexOf('x/web-interface/wbi/search/type') > -1 && params.search_type === 'video' && (date !== 'none' || playAmount !== 'none')) { + // 暂停上报 + const originReportObserver = unsafeWindow.reportObserver; + unsafeWindow.reportObserver = null; + actualPage = params.page; + pageSize = params.page_size; + if (result.length < actualPage * actualPageSize) { + await requestData(url, options); + } + let responseResult = result.slice((actualPage - 1) * actualPageSize, actualPage * actualPageSize); + let response = new Response(); + response.json = function () { + return new Promise(resolve => { + responseJson.data.page = +actualPage; + responseJson.data.result = responseResult; + resolve(responseJson); + }) + } + setTimeout(() => { + changePagenationBtn(); + }, 0); + unsafeWindow.reportObserver = originReportObserver; + return response; + } else { + return originFetch(url, options); + } + } - // 获取vue实例、vue-router实例 - let app = null, router = null, route = null, searchBtn = null; - document.addEventListener('DOMContentLoaded', function () { - searchBtn = document.querySelector('.search-button'); - app = document.querySelector('#i_cecream').__vue_app__; - router = app.config.globalProperties.$router; - route = app.config.globalProperties.$route; - if (route.name === 'video') { - insertComponent('date-search-conditions'); - insertComponent('playAmount-search-conditions'); - } else { - removeComponent(); - } - router.afterEach(route => { - if (route.name === 'video') { - insertComponent('date-search-conditions'); - insertComponent('playAmount-search-conditions'); - } else { - removeComponent(); - } - }) - // const vnode = route.matched.find(ele => ele.name == 'video').instances.default._; + // 获取vue实例、vue-router实例 + let app = null, router = null, route = null, searchBtn = null; + document.addEventListener('DOMContentLoaded', function () { + searchBtn = document.querySelector('.search-button'); + app = document.querySelector('#i_cecream').__vue_app__; + router = app.config.globalProperties.$router; + route = app.config.globalProperties.$route; + if (route.name === 'video') { + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); + } else { + removeComponent(); + } + router.afterEach(route => { + if (route.name === 'video') { + insertComponent('date-search-conditions'); + insertComponent('playAmount-search-conditions'); + } else { + removeComponent(); + } + }) + // const vnode = route.matched.find(ele => ele.name == 'video').instances.default._; - // 重写replace方法,拦截跳转,更新route,初始化数据 - const routerReplace = router.replace; - router.replace = function (toRoute) { - // 筛选条件改变 - if (!toRoute.query.date || toRoute.query.date === 'none' || !toRoute.query.page) { - route = toRoute; - result = []; - actualPage = 1; - requestPage = 1; - pageSize = 0; - finished = false; - return routerReplace.call(this, toRoute); - } - } - }) + // 重写replace方法,拦截跳转,更新route,初始化数据 + const routerReplace = router.replace; + router.replace = function (toRoute) { + // 筛选条件改变 + if (!toRoute.query.date || toRoute.query.date === 'none' || !toRoute.query.page) { + route = toRoute; + result = []; + actualPage = 1; + requestPage = 1; + pageSize = 0; + finished = false; + return routerReplace.call(this, toRoute); + } + } + }) - // 插入日期过滤组件 - function insertComponent(selector) { - if (document.querySelector('#'+selector)) { - return; - } - let element = document.createElement('div'); - element.id = selector; - element.className = 'search-condition-row'; + // 插入日期过滤组件 + function insertComponent(selector) { + if (document.querySelector('#' + selector)) { + return; + } + let element = document.createElement('div'); + element.id = selector; + element.className = 'search-condition-row'; - let clickCondition; - if (selector === 'date-search-conditions') { - clickCondition = clickDateCondition - } else { - clickCondition = clickPlayAmountCondition - } + let clickCondition; + if (selector === 'date-search-conditions') { + clickCondition = clickDateCondition + } else { + clickCondition = clickPlayAmountCondition + } - element.addEventListener('click', clickCondition); - let fragment = document.createDocumentFragment(); - let list = { - 'date-search-conditions': [{ - name: 'none', - title: '时间不限' - }, { - name: 'day', - title: '过去1天内' - }, { - name: 'week', - title: '过去1周内' - }, { - name: 'month', - title: '过去1月内' - }, { - name: 'year', - title: '过去1年内' - }, { - name: 'custom', - title: '自定日期范围' - }], - 'playAmount-search-conditions': [{ - name: 'none', - title: '播放量不限' - }, { - name: '1k', - title: '1千以上' - }, { - name: '5k', - title: '5千以上' - }, { - name: '1w', - title: '1万以上' - }, { - name: '5w', - title: '5万以上' - }, { - name: '10w', - title: '10万以上' - }] - } - list[selector].forEach(function (ele) { - let button = document.createElement('button'); - button.textContent = ele.title; - button.className = 'vui_button vui_button--tab mt_sm mr_sm'; - button.dataset.date_playAmount_condition = ele.name; - if (selector === 'date-search-conditions' && ele.name === date) { - button.className += ' vui_button--active'; - } - if (selector === 'playAmount-search-conditions' && ele.name === playAmount) { - button.className += ' vui_button--active'; - } - fragment.appendChild(button); - }); - element.appendChild(fragment); - document.querySelector('.more-conditions').appendChild(element); - } - // 移除日期过滤 - function removeComponent() { - const dateCondition = document.querySelector('#date-search-conditions') - if (dateCondition) { - document.querySelector('.more-conditions').removeChild(dateCondition); - } + element.addEventListener('click', clickCondition); + let fragment = document.createDocumentFragment(); + let list = { + 'date-search-conditions': [{ + name: 'none', + title: '时间不限' + }, { + name: 'day', + title: '过去1天内' + }, { + name: 'week', + title: '过去1周内' + }, { + name: 'month', + title: '过去1月内' + }, { + name: 'year', + title: '过去1年内' + }, { + name: 'custom', + title: '自定日期范围' + }], + 'playAmount-search-conditions': [{ + name: 'none', + title: '播放量不限' + }, { + name: '1k', + title: '1千以上' + }, { + name: '5k', + title: '5千以上' + }, { + name: '1w', + title: '1万以上' + }, { + name: '5w', + title: '5万以上' + }, { + name: '10w', + title: '10万以上' + }] + } + list[selector].forEach(function (ele) { + let button = document.createElement('button'); + button.textContent = ele.title; + button.className = 'vui_button vui_button--tab mt_sm mr_sm'; + button.dataset.date_playAmount_condition = ele.name; + if (selector === 'date-search-conditions' && ele.name === date) { + button.className += ' vui_button--active'; + } + if (selector === 'playAmount-search-conditions' && ele.name === playAmount) { + button.className += ' vui_button--active'; + } + fragment.appendChild(button); + }); + element.appendChild(fragment); + document.querySelector('.more-conditions').appendChild(element); + } + // 移除日期过滤 + function removeComponent() { + const dateCondition = document.querySelector('#date-search-conditions') + if (dateCondition) { + document.querySelector('.more-conditions').removeChild(dateCondition); + } - const Condition2 = document.querySelector('#playAmount-search-conditions') - if (Condition2) { - document.querySelector('.more-conditions').removeChild(Condition2); - } - } - // 更新日期按钮状态 - function updateComponent() { - ['#date-search-conditions', '#playAmount-search-conditions'].forEach(selectorr => { - const dateCondition = document.querySelector(selectorr) - if (dateCondition) { - [...dateCondition.children].forEach(btn => { - let conditionActive; - if (selectorr === '#date-search-conditions') { - conditionActive = date; - } else { - conditionActive = playAmount; - } - if (btn.dataset.date_playAmount_condition == conditionActive) { - btn.classList.add("vui_button--active") - } else { - btn.classList.remove("vui_button--active"); - } - }) - } - }); - } + const Condition2 = document.querySelector('#playAmount-search-conditions') + if (Condition2) { + document.querySelector('.more-conditions').removeChild(Condition2); + } + } + // 更新日期按钮状态 + function updateComponent() { + ['#date-search-conditions', '#playAmount-search-conditions'].forEach(selectorr => { + const dateCondition = document.querySelector(selectorr) + if (dateCondition) { + [...dateCondition.children].forEach(btn => { + let conditionActive; + if (selectorr === '#date-search-conditions') { + conditionActive = date; + } else { + conditionActive = playAmount; + } + if (btn.dataset.date_playAmount_condition == conditionActive) { + btn.classList.add("vui_button--active") + } else { + btn.classList.remove("vui_button--active"); + } + }) + } + }); + } - function routerGo(query) { - router.replace({ - 'name': 'video', - query - }); - setTimeout(() => { - getFromQuery(); - updateComponent(); - searchBtn.click(); - }); - } + function routerGo(query) { + router.replace({ + 'name': 'video', + query + }); + setTimeout(() => { + getFromQuery(); + updateComponent(); + searchBtn.click(); + }); + } - // 日期过滤点击事件 - function clickDateCondition(evt) { - let datecondition = evt.target.dataset.date_playAmount_condition; - if (datecondition === 'none') { - // 时间不限 - let { date, date_range, ...query } = route.query; // 删除date和date_range属性 - routerGo(query); - } else if (datecondition === 'custom') { - // 自定义日期范围,弹出日期选择弹窗 - if (!fp) { - fp = evt.target.flatpickr({ - clickOpens: false, - maxDate: 'today', - mode: 'range', - onChange: function (selectedDates) { - if (selectedDates.length == 2) { - let startTime = +selectedDates[0]; - let endTime = +selectedDates[1]; - if (startTime == endTime) { - endTime += 86400000; - } - endTime = Math.min(Date.now(), endTime); - filterByDate(datecondition, startTime, endTime); - } - } - }); - } - fp.open(); - } else if (datecondition) { - // 固定日期范围选择 - let endTime = Date.now(); - let timeMap = { - 'day': 86400000, - 'week': 604800000, - 'month': 2592000000, - 'year': 31536000000 - } - filterByDate(datecondition, endTime - timeMap[datecondition], endTime); - } - } - // 播放量过滤点击事件 - function clickPlayAmountCondition(evt) { - let playAmountcondition = evt.target.dataset.date_playAmount_condition; - if (playAmountcondition === 'none') { - // 时间不限 - let { playAmount, play_Amount, ...query } = route.query; - routerGo(query); - } else if (playAmountcondition) { - // 固定日期范围选择 - let Map = { - '1k': 1000, - '5k': 5000, - '1w': 10000, - '5w': 50000, - '10w': 100000 + // 日期过滤点击事件 + function clickDateCondition(evt) { + let datecondition = evt.target.dataset.date_playAmount_condition; + if (datecondition === 'none') { + // 时间不限 + let { date, date_range, ...query } = route.query; // 删除date和date_range属性 + routerGo(query); + } else if (datecondition === 'custom') { + // 自定义日期范围,弹出日期选择弹窗 + if (!fp) { + fp = evt.target.flatpickr({ + clickOpens: false, + maxDate: 'today', + mode: 'range', + onChange: function (selectedDates) { + if (selectedDates.length == 2) { + let startTime = +selectedDates[0]; + let endTime = +selectedDates[1]; + if (startTime == endTime) { + endTime += 86400000; + } + endTime = Math.min(Date.now(), endTime); + filterByDate(datecondition, startTime, endTime); + } } - // filterByDate(datecondition, endTime - timeMap[datecondition], endTime); - let { page, o, ...query } = route.query; - query.playAmount = playAmountcondition; - query.play_Amount = Map[playAmountcondition] - routerGo(query); + }); } + fp.open(); + } else if (datecondition) { + // 固定日期范围选择 + let endTime = Date.now(); + let timeMap = { + 'day': 86400000, + 'week': 604800000, + 'month': 2592000000, + 'year': 31536000000 + } + filterByDate(datecondition, endTime - timeMap[datecondition], endTime); + } + } + // 播放量过滤点击事件 + function clickPlayAmountCondition(evt) { + let playAmountcondition = evt.target.dataset.date_playAmount_condition; + if (playAmountcondition === 'none') { + // 时间不限 + let { playAmount, play_Amount, ...query } = route.query; + routerGo(query); + } else if (playAmountcondition) { + // 固定日期范围选择 + let Map = { + '1k': 1000, + '5k': 5000, + '1w': 10000, + '5w': 50000, + '10w': 100000 + } + // filterByDate(datecondition, endTime - timeMap[datecondition], endTime); + let { page, o, ...query } = route.query; + query.playAmount = playAmountcondition; + query.play_Amount = Map[playAmountcondition] + routerGo(query); + } } - function filterByDate(datecondition, startTime, endTime) { - let { page, o, ...query } = route.query; - query.date = datecondition; - query.date_range = `${Math.floor(startTime / 1000)}_${Math.floor(endTime / 1000)}`; - routerGo(query); - } + function filterByDate(datecondition, startTime, endTime) { + let { page, o, ...query } = route.query; + query.date = datecondition; + query.date_range = `${Math.floor(startTime / 1000)}_${Math.floor(endTime / 1000)}`; + routerGo(query); + } - // 隐藏分页按钮 - function changePagenationBtn() { - if (date !== 'none' || playAmount !== 'none') { - let pagenationBtnList = document.querySelectorAll('.vui_pagenation--btn-num'); - if (pagenationBtnList.length > 0) { - for (let btn of pagenationBtnList) { - btn.remove(); - } - } - let pagenationText = document.querySelector('.vui_pagenation--extend'); - if (pagenationText) { - pagenationText.remove(); - } + // 隐藏分页按钮 + function changePagenationBtn() { + if (date !== 'none' || playAmount !== 'none') { + let pagenationBtnList = document.querySelectorAll('.vui_pagenation--btn-num'); + if (pagenationBtnList.length > 0) { + for (let btn of pagenationBtnList) { + btn.remove(); + } + } + let pagenationText = document.querySelector('.vui_pagenation--extend'); + if (pagenationText) { + pagenationText.remove(); + } - let pagenationParent = document.querySelector('.vui_pagenation--btns'); - if (pagenationParent) { - let nextPagenation = pagenationParent.lastChild; - if (finished && actualPage === maxPage) { - nextPagenation.className += ' vui_button--disabled'; - nextPagenation.setAttribute('disabled', 'disabled') - } else { - nextPagenation.className = nextPagenation.className.replace(' vui_button--disabled', ''); - nextPagenation.removeAttribute('disabled'); - } - } - } - } + let pagenationParent = document.querySelector('.vui_pagenation--btns'); + if (pagenationParent) { + let nextPagenation = pagenationParent.lastChild; + if (finished && actualPage === maxPage) { + nextPagenation.className += ' vui_button--disabled'; + nextPagenation.setAttribute('disabled', 'disabled') + } else { + nextPagenation.className = nextPagenation.className.replace(' vui_button--disabled', ''); + nextPagenation.removeAttribute('disabled'); + } + } + } + } - // 请求数据保存 - async function requestData(url, options) { - while (true) { - const query = getQueryObject(url); - query.page = requestPage; - // 应该是浏览的偏移量,必须跟页码数量保持一致,不然会有重复数据 - query.dynamic_offset = (requestPage - 1) * pageSize; - // 请求加密 - Object.assign(query, encWbi(query, encWbiKeys)); - const urlObj = new URL(url); - url = `${urlObj.origin + urlObj.pathname}?${new URLSearchParams(query)}`; - let _responseJson = await originFetch(url, options).then(response => { - return response.json(); - }); - // debugger - if (_responseJson.data && _responseJson.data.result) { - if (_responseJson.data.result.length < pageSize) { - finished = true; - maxPage = actualPage; - } - responseJson = _responseJson; - let list = responseJson.data.result.filter(ele => ele.pubdate >= dateRange[0] && ele.pubdate <= dateRange[1]); - list = list.filter(ele => ele.play >= play_Amount); - result = result.concat(list); - } else { - // 没有更多数据了 - finished = true; - maxPage = actualPage; - } - requestPage++; - if (finished || result.length >= actualPage * actualPageSize) { - return; - } else { - let time = Math.round(Math.random() * 400) + 600; - await delay(time); - } - } - } + // 请求数据保存 + async function requestData(url, options) { + options.timeout = 20000; // 不管用,在拦截fetch之前已经用这个参数了 + let timeoutFLag = false; + setTimeout(()=>{ + timeoutFLag = true; // 防止超时 + }, 7000); - // 防止请求频繁,被封ip - function delay(n) { - return new Promise(function (resolve) { - setTimeout(resolve, n); - }); - } + while (true) { + const query = getQueryObject(url); + query.page = requestPage; + // 应该是浏览的偏移量,必须跟页码数量保持一致,不然会有重复数据 + query.dynamic_offset = (requestPage - 1) * pageSize; + // 请求加密 + Object.assign(query, encWbi(query, encWbiKeys)); + const urlObj = new URL(url); + url = `${urlObj.origin + urlObj.pathname}?${new URLSearchParams(query)}`; + let _responseJson = await originFetch(url, options).then(response => { + return response.json(); + }); - // 请求加密 - const encWbiKeys = { - wbiImgKey: "76e91e21c4df4e16af9467fd6f3e1095", - wbiSubKey: "ddfca332d157450784b807c59cd7921e" - } - function encWbi(st, dt) { - dt || (dt = {}); - var Et = getWbiKey(dt), - St = Et.imgKey, - wt = Et.subKey; - if (St && wt) { - for (var xt = getMixinKey(St + wt), kt = Math.round(Date.now() / 1e3), Ht = Object.assign({}, st, { - wts: kt - }), Wt = Object.keys(Ht).sort(), zt = [], Xt = /[!'\(\)*]/g, Qt = 0; Qt < Wt.length; Qt++) { - var Zt = Wt[Qt], - an = Ht[Zt]; - an && typeof an == "string" && (an = an.replace(Xt, "")), an != null && zt.push("".concat( - encodeURIComponent(Zt), "=").concat(encodeURIComponent(an))) - } - var mn = zt.join("&"), - bn = md5(mn + xt); - return { - w_rid: bn, - wts: kt.toString() - } - } - return null - } - function getWbiKey(st) { - if (st.useAssignKey) return { - imgKey: st.wbiImgKey, - subKey: st.wbiSubKey - }; - var dt = getLocal("wbi_img_url"), - Et = getLocal("wbi_sub_url"), - St = dt ? getKeyFromURL(dt) : st.wbiImgKey, - wt = Et ? getKeyFromURL(Et) : st.wbiSubKey; - return { - imgKey: St, - subKey: wt - } - } - function getLocal(st) { - try { - return localStorage.getItem(st) - } catch (dt) { - return null - } - } - function getKeyFromURL(st) { - return st.substring(st.lastIndexOf("/") + 1, st.length).split(".")[0] - } - function getMixinKey(st) { - var dt = [46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, - 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, - 57, 62, 11, 36, 20, 34, 44, 52], - Et = []; - return dt.forEach(function (St) { - st.charAt(St) && Et.push(st.charAt(St)) - }), Et.join("").slice(0, 32) - } + if (_responseJson.data && _responseJson.data.result) { + debugger + if (_responseJson.data.result.length < pageSize) { // 42 + finished = true; + maxPage = actualPage; + } + responseJson = _responseJson; + let list = responseJson.data.result.filter(ele => ele.pubdate >= dateRange[0] && ele.pubdate <= dateRange[1]); + list = list.filter(ele => ele.play >= play_Amount); + result = result.concat(list); + } else { + // 没有更多数据了 + finished = true; + maxPage = actualPage; + } + requestPage++; + if (timeoutFLag || finished || result.length >= actualPage * actualPageSize) { + return; + } else { + let time = Math.round(Math.random() * 400) + 600; + await delay(time); + } + } + } + + // 防止请求频繁,被封ip + function delay(n) { + return new Promise(function (resolve) { + setTimeout(resolve, n); + }); + } + + // 请求加密 + const encWbiKeys = { + wbiImgKey: "76e91e21c4df4e16af9467fd6f3e1095", + wbiSubKey: "ddfca332d157450784b807c59cd7921e" + } + function encWbi(st, dt) { + dt || (dt = {}); + var Et = getWbiKey(dt), + St = Et.imgKey, + wt = Et.subKey; + if (St && wt) { + for (var xt = getMixinKey(St + wt), kt = Math.round(Date.now() / 1e3), Ht = Object.assign({}, st, { + wts: kt + }), Wt = Object.keys(Ht).sort(), zt = [], Xt = /[!'\(\)*]/g, Qt = 0; Qt < Wt.length; Qt++) { + var Zt = Wt[Qt], + an = Ht[Zt]; + an && typeof an == "string" && (an = an.replace(Xt, "")), an != null && zt.push("".concat( + encodeURIComponent(Zt), "=").concat(encodeURIComponent(an))) + } + var mn = zt.join("&"), + bn = md5(mn + xt); + return { + w_rid: bn, + wts: kt.toString() + } + } + return null + } + function getWbiKey(st) { + if (st.useAssignKey) return { + imgKey: st.wbiImgKey, + subKey: st.wbiSubKey + }; + var dt = getLocal("wbi_img_url"), + Et = getLocal("wbi_sub_url"), + St = dt ? getKeyFromURL(dt) : st.wbiImgKey, + wt = Et ? getKeyFromURL(Et) : st.wbiSubKey; + return { + imgKey: St, + subKey: wt + } + } + function getLocal(st) { + try { + return localStorage.getItem(st) + } catch (dt) { + return null + } + } + function getKeyFromURL(st) { + return st.substring(st.lastIndexOf("/") + 1, st.length).split(".")[0] + } + function getMixinKey(st) { + var dt = [46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, + 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, + 57, 62, 11, 36, 20, 34, 44, 52], + Et = []; + return dt.forEach(function (St) { + st.charAt(St) && Et.push(st.charAt(St)) + }), Et.join("").slice(0, 32) + } })();