JavDB 收藏导出

导出“想看”和“看过”,进入这两个页面的第一页点击右上角的“开始导出”即可,导出为格式为 JSON。

Per 28-05-2023. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         JavDB 收藏导出
// @namespace    https://gist.github.com/nini22P/021f2db060aab1785151d1a0c142714a
// @version      1.1
// @description  导出“想看”和“看过”,进入这两个页面的第一页点击右上角的“开始导出”即可,导出为格式为 JSON。
// @match        https://javdb.com/users/*
// @grant        GM_xmlhttpRequest
// @grant        GM_listValues
// @license MIT
// ==/UserScript==

let allVideoTitles = JSON.parse(localStorage.getItem('videoTitles')) || [];
let allowExport = JSON.parse(localStorage.getItem('allowExport')) || false;
let exportButton = null;

function extractVideoTitles() {
  const videoTitleElements = document.querySelectorAll('.video-title');
  const videoTitles = Array.from(videoTitleElements).map((element) => {
    const title = element.textContent.trim(); // Remove leading and trailing whitespace
    const [id, ...titleWords] = title.split(' '); // Split the title into ID and title words
    const formattedTitle = titleWords.join(' '); // Join the title words back together
    return { id, title: formattedTitle };
  });
  return videoTitles;
}

function scrapeAllPages() {
  const videoTitles = extractVideoTitles();
  allVideoTitles = allVideoTitles.concat(videoTitles);
  localStorage.setItem('videoTitles', JSON.stringify(allVideoTitles)); // Save the video titles to local storage
  const nextPageButton = document.querySelector('.pagination-next');
  if (nextPageButton) {
    nextPageButton.click();
    setTimeout(() => scrapeAllPages(), 2000); // Wait for 2 seconds before scraping again
  } else {
    exportVideoTitles();
  }
}

function exportVideoTitles() {
  allowExport = false;
  localStorage.setItem('allowExport', JSON.stringify(allowExport)); // Disable export after exporting
  allVideoTitles.sort((a, b) => a.id.localeCompare(b.id)); // Sort the video titles by ID
  const json = JSON.stringify(allVideoTitles);
  const jsonBlob = new Blob([json], { type: 'application/json' });
  const jsonUrl = URL.createObjectURL(jsonBlob);
  const downloadLink = document.createElement('a');
  let fileName = '';
  if (window.location.href.includes('/watched_videos')) {
    fileName = 'watched_videos'
  } else if (window.location.href.includes('/want_watch_videos')) {
    fileName = 'want_watch_videos'
  }
  downloadLink.href = jsonUrl;
  downloadLink.download = `${fileName}.json`;
  document.body.appendChild(downloadLink);
  downloadLink.click();
  localStorage.removeItem('videoTitles'); // Remove the video titles from local storage after exporting
  exportButton.textContent = '导出完毕'; // Update the export button text
}

function startExport() {
  const allImages = document.querySelectorAll('img'); //移除图像增加速度
  allImages.forEach((image) => { 
    image.remove();
  });
  allowExport = true;
  localStorage.setItem('allowExport', JSON.stringify(allowExport)); // Enable export
  exportButton.textContent = '导出中...'; // Update the export button text
  scrapeAllPages();
}

function createExportButton() {
  const navbarEnd = document.querySelector('.navbar-end');
  exportButton = document.createElement('button');
  exportButton.textContent = '开始导出';
  exportButton.addEventListener('click', startExport);
  navbarEnd.appendChild(exportButton);
}

if (window.location.href.includes('/watched_videos') || window.location.href.includes('/want_watch_videos')) {
  createExportButton();
  if (allowExport) {
    startExport();
  }
}