您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Sort Bilibili search results by date and display in a new table
当前为
// ==UserScript== // @name Bilibili 综合搜索按时间排序 // @namespace http://tampermonkey.net/ // @version 1.4 // @description Sort Bilibili search results by date and display in a new table // @author Zola // @match https://search.bilibili.com/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // Function to convert date strings to Date objects function parseDate(dateStr) { const parts = dateStr.split('-').map(Number); if (parts.length === 2) { // Current year date format const currentYear = new Date().getFullYear(); return new Date(currentYear, parts[0] - 1, parts[1]); } else if (parts.length === 3) { // Full date format with year return new Date(parts[0], parts[1] - 1, parts[2]); } return new Date(NaN); // Invalid date } // Function to sort search results by date function sortResults() { const items = Array.from(document.querySelectorAll('.bili-video-card')); const videoData = items.map(item => { const title = item.querySelector('.bili-video-card__info--tit').innerText.trim(); const dateStr = item.querySelector('.bili-video-card__info--date').innerText.trim().replace('· ', ''); const date = parseDate(dateStr); const link = item.querySelector('a').href; const thumbnail = item.querySelector('.bili-video-card__cover img').src; const author = item.querySelector('.bili-video-card__info--author').innerText.trim(); return { title, date, link, thumbnail, author }; }); // Sort video data by date, latest first videoData.sort((a, b) => b.date - a.date); // Create new table to display sorted results const newTable = document.createElement('table'); newTable.style.width = '100%'; newTable.style.borderCollapse = 'collapse'; newTable.innerHTML = ` <thead> <tr> <th style="border: 1px solid #ddd; padding: 8px;">Thumbnail</th> <th style="border: 1px solid #ddd; padding: 8px;">Title</th> <th style="border: 1px solid #ddd; padding: 8px;">Date</th> <th style="border: 1px solid #ddd; padding: 8px;">Author</th> </tr> </thead> <tbody> ${videoData.map(video => ` <tr> <td style="border: 1px solid #ddd; padding: 8px;"><img src="${video.thumbnail}" alt="Thumbnail" style="width: 100px;"></td> <td style="border: 1px solid #ddd; padding: 8px;"><a href="${video.link}" target="_blank">${video.title}</a></td> <td style="border: 1px solid #ddd; padding: 8px;">${video.date.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' })}</td> <td style="border: 1px solid #ddd; padding: 8px;">${video.author}</td> </tr> `).join('')} </tbody> `; // Replace original content with new table const container = document.querySelector('.video-list'); if (container) { container.innerHTML = ''; container.appendChild(newTable); } } // Execute the sort function after the page loads window.addEventListener('load', sortResults); })();