Belfry filtering buttons

adds some filtering buttons to the belfry comic listing

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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