Add italki.com Teacher List Filter

Add buttons to filter teacher list. Currently, it only applies when the web browser is pointing to https://www.italki.com/partners.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Add italki.com Teacher List Filter
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.0.1
// @description  Add buttons to filter teacher list. Currently, it only applies when the web browser is pointing to https://www.italki.com/partners.
// @author       jcunews
// @match        https://www.italki.com/partners
// @grant        none
// ==/UserScript==

(function(t, list, prevEleCount, filteredUids, items) {

  function filterUser(item) {
    filteredUids.push(parseInt(this.getAttribute("uid")));
    localStorage.filteredUids = JSON.stringify(filteredUids);
    item = this.parentNode.parentNode.parentNode.parentNode;
    item.parentNode.removeChild(item);
    prevEleCount--;
  }

  function filterList(i, link, uid, btn) {
    clearTimeout(t);
    if ((prevEleCount < 0) || (items.length !== prevEleCount)) {
      if (prevEleCount < 0) prevEleCount = 0;
      for (i = items.length-1; i >= 0; i--) {
        if (!items[i].querySelector(".filter")) {
          link = items[i].querySelector("A");
          uid = parseInt(link.pathname.match(/\d+/)[0]);
          if (filteredUids.indexOf(uid) >= 0) {
            list.removeChild(items[i]);
          } else if (btn = items[i].querySelector(".btn")) {
            link = btn.cloneNode(true);
            link.textContent = "X";
            link.title = "Filter this teacher";
            link.classList.add("filter");
            link.style.cssText = "font-weight: bold; color: red";
            link.setAttribute("uid", uid);
            link.removeAttribute("href");
            link.removeAttribute("ui-sref");
            link.onclick = filterUser;
            btn.parentNode.insertBefore(link, btn);
          }
        }
      }
    }
    prevEleCount = items.length;
    t = setTimeout(filterList, 200);
  }

  prevEleCount = -1;
  filteredUids = localStorage.filteredUids || "[]";
  try {
    filteredUids = JSON.parse(filteredUids);
  } catch(t) {
    filteredUids = [];
  }
  items = document.getElementsByClassName("teacher-item");
  t = 0;

  (function init(filter, btn) {
    if (list = document.querySelector(".teacher-list")) {
      filterList();
      if (filter = document.querySelector(".panel-body > .filter > form > div:nth-child(2)")) {
        btn = document.createElement("BUTTON");
        btn.textContent = "Reset Teacher Filter";
        btn.className = "btn";
        btn.style.cssText = "margin-left: 2ex; padding: 0";
        btn.onclick = function() {
          filteredUids = [];
          localStorage.filteredUids = "[]";
        };
        filter.insertBefore(btn, filter.lastElementChild);
      }
    } else setTimeout(init, 100);
  })();

})();