Belfry filtering buttons

adds some filtering buttons to the belfry comic listing

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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