Erome Filter

Filter images and videos in Erome

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Erome Filter
// @version      1.0
// @description  Filter images and videos in Erome
// @match        https://www.erome.com/a/*
// @icon         https://www.erome.com/favicon.ico
// @grant        none
// @namespace    https://greasyfork.org/users/1030442
// ==/UserScript==

const albumElement = document.querySelector('[id^="album_"]');
const videoDivs = albumElement.querySelectorAll('div > div > .video');
const imageDivs = albumElement.querySelectorAll('div > div > div > img.img-front');

if (videoDivs.length > 0 && imageDivs.length > 0) {
  const userInfoElement = document.querySelector('.user-info.text-right');
  const selectElement = document.createElement('select');
  const options = [
    { value: 'all', text: `Show All (${imageDivs.length + videoDivs.length})` },
    { value: 'images', text: `Show Images (${imageDivs.length})` },
    { value: 'videos', text: `Show Videos (${videoDivs.length})` },
  ];

  selectElement.addEventListener('change', function() {
    const selectedOption = this.value;
    if (selectedOption === 'images') {
      videoDivs.forEach(div => div.parentElement.parentElement.style.display = 'none');
      imageDivs.forEach(div => div.parentElement.parentElement.parentElement.style.display = '');
    }
    if (selectedOption === 'videos') {
      videoDivs.forEach(div => div.parentElement.parentElement.style.display = '');
      imageDivs.forEach(div => div.parentElement.parentElement.parentElement.style.display = 'none');
    }
    if (selectedOption === 'all') {
      imageDivs.forEach(div => div.parentElement.parentElement.parentElement.style.display = '');
      videoDivs.forEach(div => div.parentElement.parentElement.style.display = '');
    }
  });

  options.forEach(option => {
    const { value, text } = option;
    const optionElement = document.createElement('option');
    optionElement.value = value;
    optionElement.text = text;
    selectElement.appendChild(optionElement);
  });

  userInfoElement.prepend(selectElement);
}