This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Filtering trends and schedulers
#1
Hi everyone,

I've created today such helpful tool for filtering list of trends and schedulers in Trends and Schedulers pages. This is a javascript code which could be used for this task. It must be added to Custom Javascript:
Code:
// SEARCH INPUT IN TRENDS AND SCHEDULERS
$(function(){
  if (document.body.classList.contains('usermode')) return;
 
  const sidebar = document.querySelector(".sidebar");
 
  if (!sidebar) return;
 
  const getItems = () => {
    listItems = [...document.querySelectorAll(".sidebar li")].filter(item => {
      return !["divider", "holidays-menu-item", "group"].some(className => item.classList.contains(className));
    });
      spans = listItems.map(item => item.querySelector("span"));
  }
 
  const input = document.createElement("input");
  input.placeholder = "Search";
  input.style.width = "100%";
  input.style.boxSizing = "border-box";
  input.style.padding = "5px";
  input.style.marginBottom = "10px";
  input.style.borderRadius = "5px";
  input.style.position = "sticky";

  input.style.top = 0;
 
  let listItems, spans;
 
  input.addEventListener("input", ({target: { value }}) => {
    if (!listItems) getItems();
   
      listItems.forEach((item, i) => {
      const spanValue = spans[i].textContent.toLowerCase();
      const inputValue = value.toLowerCase();
      const match = spanValue.match(inputValue);
        if (match) item.style.display = "block";
      else item.style.display = "none";
    });
  });
  sidebar.prepend(input);
});

Attached Files Thumbnail(s)
   
Done is better than perfect
Reply


Forum Jump: