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.

  1. // ==UserScript==
  2. // @name Add italki.com Teacher List Filter
  3. // @namespace https://greasyfork.org/en/users/85671-jcunews
  4. // @version 1.0.1
  5. // @description Add buttons to filter teacher list. Currently, it only applies when the web browser is pointing to https://www.italki.com/partners.
  6. // @author jcunews
  7. // @match https://www.italki.com/partners
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(t, list, prevEleCount, filteredUids, items) {
  12.  
  13. function filterUser(item) {
  14. filteredUids.push(parseInt(this.getAttribute("uid")));
  15. localStorage.filteredUids = JSON.stringify(filteredUids);
  16. item = this.parentNode.parentNode.parentNode.parentNode;
  17. item.parentNode.removeChild(item);
  18. prevEleCount--;
  19. }
  20.  
  21. function filterList(i, link, uid, btn) {
  22. clearTimeout(t);
  23. if ((prevEleCount < 0) || (items.length !== prevEleCount)) {
  24. if (prevEleCount < 0) prevEleCount = 0;
  25. for (i = items.length-1; i >= 0; i--) {
  26. if (!items[i].querySelector(".filter")) {
  27. link = items[i].querySelector("A");
  28. uid = parseInt(link.pathname.match(/\d+/)[0]);
  29. if (filteredUids.indexOf(uid) >= 0) {
  30. list.removeChild(items[i]);
  31. } else if (btn = items[i].querySelector(".btn")) {
  32. link = btn.cloneNode(true);
  33. link.textContent = "X";
  34. link.title = "Filter this teacher";
  35. link.classList.add("filter");
  36. link.style.cssText = "font-weight: bold; color: red";
  37. link.setAttribute("uid", uid);
  38. link.removeAttribute("href");
  39. link.removeAttribute("ui-sref");
  40. link.onclick = filterUser;
  41. btn.parentNode.insertBefore(link, btn);
  42. }
  43. }
  44. }
  45. }
  46. prevEleCount = items.length;
  47. t = setTimeout(filterList, 200);
  48. }
  49.  
  50. prevEleCount = -1;
  51. filteredUids = localStorage.filteredUids || "[]";
  52. try {
  53. filteredUids = JSON.parse(filteredUids);
  54. } catch(t) {
  55. filteredUids = [];
  56. }
  57. items = document.getElementsByClassName("teacher-item");
  58. t = 0;
  59.  
  60. (function init(filter, btn) {
  61. if (list = document.querySelector(".teacher-list")) {
  62. filterList();
  63. if (filter = document.querySelector(".panel-body > .filter > form > div:nth-child(2)")) {
  64. btn = document.createElement("BUTTON");
  65. btn.textContent = "Reset Teacher Filter";
  66. btn.className = "btn";
  67. btn.style.cssText = "margin-left: 2ex; padding: 0";
  68. btn.onclick = function() {
  69. filteredUids = [];
  70. localStorage.filteredUids = "[]";
  71. };
  72. filter.insertBefore(btn, filter.lastElementChild);
  73. }
  74. } else setTimeout(init, 100);
  75. })();
  76.  
  77. })();