Bunkr Filter

Filter bunker images and videos by size and type

目前為 2023-02-20 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bunkr Filter
// @version      1.0
// @description  Filter bunker images and videos by size and type
// @match        https://bunkr.is/a/*
// @match        https://bunkr.ru/a/*
// @match        https://bunkr.su/a/*
// @icon         https://bunkr.su/images/logo.svg
// @grant        none
// @namespace https://greasyfork.org/users/1030442
// ==/UserScript==


let filtering = 'None';
let sizeFilter = 0;

const imageFormats = ['.png', '.jpg', '.jpeg', '.gif'];
const videoFormats = ['.mp4', '.mov', '.flv', '.webm'];

const imageBoxes = document.querySelectorAll('.grid-images_box a[href$="' + imageFormats.join('"], .grid-images_box a[href$="') + '"]');
const videoBoxes = document.querySelectorAll('.grid-images_box a[href$="' + videoFormats.join('"], .grid-images_box a[href$="') + '"]');
const otherBoxes = document.querySelectorAll('.grid-images_box a:not(' + Array.from(imageBoxes).map(box => `:is(${box.tagName.toLowerCase()}[href="${box.getAttribute('href')}"])`).concat(Array.from(videoBoxes).map(box => `:is(${box.tagName.toLowerCase()}[href="${box.getAttribute('href')}"])`)).join(', ') + ')');

const filterOptions = ['Show All', 'Filter Images', 'Filter Videos', 'Filter Other'];
const filterDropdown = document.createElement('select');
filterDropdown.style.cssText = 'padding:5px;color:black;max-height:30px; max-width: 150px; border-radius:2px';
filterOptions.forEach((text, index) => {
  const option = document.createElement('option');
  option.textContent = text;
  option.value = index;
  filterDropdown.appendChild(option);
});

filterDropdown.addEventListener('change', () => {
  const selectedIndex = parseInt(filterDropdown.value);
  switch (selectedIndex) {
    case 1:
      filtering = 'Images';
      break;
    case 2:
      filtering = 'Videos';
      break;
    case 3:
      filtering = 'Other';
      break;
    default:
      filtering = 'None';
  }
  filterBoxes();
});

const minSizeInput = document.createElement('input');
minSizeInput.type = 'number';
minSizeInput.min = '0';
minSizeInput.placeholder = 'size in MB';
minSizeInput.style.cssText = 'padding:5px;color:black; max-height:30px; max-width: 150px; border-radius:2px';
minSizeInput.addEventListener('change', () => {
  sizeFilter = minSizeInput.value;
  filterBoxes();
});

function filterBoxes() {
  if (filtering === 'Videos') {
    videoBoxes.forEach(box => toggleView(box.parentElement.parentElement));
    imageBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
    otherBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
  } else if (filtering === 'Images') {
    imageBoxes.forEach(box => toggleView(box.parentElement.parentElement));
    videoBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
    otherBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
  } else if (filtering === 'Other') {
    otherBoxes.forEach(box => toggleView(box.parentElement.parentElement));
    imageBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
    videoBoxes.forEach(box => box.parentElement.parentElement.style.display = 'none');
  } else {
    imageBoxes.forEach(box => toggleView(box.parentElement.parentElement));
    videoBoxes.forEach(box => toggleView(box.parentElement.parentElement));
    otherBoxes.forEach(box => toggleView(box.parentElement.parentElement));
  }
}

function toggleView(box) {
  const [sizeValue, sizeUnit] = box.children[1].children[1].textContent.trim().split(' ');
  const sizeInMB = convertToMB(parseFloat(sizeValue), sizeUnit);
  const show = sizeInMB >= sizeFilter;
  box.style.display = show ? 'block' : 'none';
}

function convertToMB(sizeValue, sizeUnit) {
  const multiplier = sizeUnit.toLowerCase() === 'gib' || sizeUnit.toLowerCase() === 'gb'
    ? 1024
    : sizeUnit.toLowerCase() === 'mib' || sizeUnit.toLowerCase() === 'mb'
      ? 1
      : sizeUnit.toLowerCase() === 'kib' || sizeUnit.toLowerCase() === 'kb'
        ? 1 / 1024
        : 1;
  return sizeValue * multiplier;
}

const sizeContainer = document.createElement('div');
const sizeContainerTitle = document.createElement('p')
sizeContainerTitle.innerText = 'Filter by Size'
sizeContainer.appendChild(sizeContainerTitle)
sizeContainer.appendChild(minSizeInput);

const typeContainer = document.createElement('div')
const typeContainerTitle = document.createElement('p')
typeContainerTitle.innerText = 'Filter by Type'
typeContainer.appendChild(typeContainerTitle)
typeContainer.appendChild(filterDropdown)


sizeContainer.style.cssText = 'display: flex; flex-direction:column; align-items:center;border:2px solid white; padding:10px; border-radius:4px'
typeContainer.style.cssText = 'display: flex; flex-direction:column; align-items:center;border:2px solid white; padding:10px; border-radius:4px'


const filtersBox = document.createElement('div');
filtersBox.style.cssText = 'display:flex;flex-direction:row;align-items:center;justify-content:center;gap:20px;padding:10px;';
filtersBox.appendChild(typeContainer);
filtersBox.appendChild(sizeContainer);

document.querySelector('.friends').appendChild(filtersBox);