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.

01.02.2018 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
  })();

})();