Belfry filtering buttons

adds some filtering buttons to the belfry comic listing

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Belfry filtering buttons
// @description adds some filtering buttons to the belfry comic listing
// @namespace   https://sleazyfork.org/en/users/96703-justrunmyscripts
// @match       *://*belfrycomics.net/*
// @grant       none
// @version     1.0
// @author      justrunmyscripts
// ==/UserScript==

const filterColumns = (category) => {
  elems = document.querySelectorAll('.column span > a');
  
  if (category === '') {
    elems.forEach(e => e.parentNode.style.visibility = 'visible');    
    return;
  }
  
  elems.forEach(e => e.parentNode.style.visibility = 'hidden');

  elems = document.querySelectorAll('.column em.warn');
  elems.forEach(e => {
    if (e.textContent.indexOf(category) !== -1 ) {
      e.parentNode.style.visibility = 'visible';    
    }
  });  
}
window.filterColumns = filterColumns;

const createButton = (value) => {
  b = document.createElement('button');
  b.textContent = value ? value : '*';
  b.onclick = () => {filterColumns(value)};
  return b;
}

const insertButtons = (targetElem) => {
  buttonContainer = document.createElement('div');
  
  for (const value of ['','A', 'L', 'N', 'V', 'X']) {
    b = createButton(value);
    buttonContainer.appendChild(b);
  }

  parent = targetElem.parentNode;

  parent.insertBefore(buttonContainer, targetElem);
}
targetElem = document.querySelector('.widehead');
insertButtons(targetElem);

window.insertButtons = insertButtons