Stips user blocker.

REALY block users on Stips!

  1. // ==UserScript==
  2. // @name Stips user blocker.
  3. // @namespace http://stips.co.il
  4. // @version 0.1
  5. // @description REALY block users on Stips!
  6. // @author Avishai
  7. // @match https://stips.co.il/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=co.il
  9. // @grant none
  10. // @license GNU AGPLv3
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16. script()
  17.  
  18. //https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
  19.  
  20. async function waitForElement(selector, timeout = null, location = document.body) {
  21. return new Promise((resolve) => {
  22. let element = document.querySelector(selector);
  23. if (element) {
  24. return resolve(element);
  25. }
  26.  
  27. const observer = new MutationObserver(async () => {
  28. let element = document.querySelector(selector);
  29. if (element) {
  30. observer.disconnect()
  31. resolve(element);
  32. } else {
  33. if (timeout) {
  34. async function timeOver() {
  35. return new Promise((resolve) => {
  36. setTimeout(() => {
  37. observer.disconnect();
  38. resolve(false);
  39. }, timeout);
  40. });
  41. }
  42. resolve(await timeOver());
  43. }
  44. }
  45. });
  46.  
  47. observer.observe(location, {
  48. childList: true,
  49. subtree: true,
  50. });
  51. });
  52. }
  53.  
  54. var currentPath = window.location.pathname;
  55. setInterval(script, 50);
  56.  
  57.  
  58. async function script() {
  59. if(window.location.pathname !== currentPath) {
  60. currentPath = window.location.pathname;
  61.  
  62. if(window.location.pathname.includes("ask")) {
  63. await waitForElement("#elastic-layer-content > div.single-layer.layer-0.ng-star-inserted.visible > app-dynamic-component > app-item-screen > div > div > div.item-screen-content-below-card > div.item-list.ng-star-inserted > app-item-list > app-item:nth-child(3)")
  64. console.log("FOUND!!!")
  65. const answers = document.querySelectorAll("app-item")
  66. const list = getList()
  67. if(!list.length) return
  68. answers.forEach(ans => {
  69. list.forEach(id => {
  70. if(ans.querySelector("a")?.href.includes(id)){
  71. ans.remove()
  72. return
  73. }
  74. })
  75.  
  76. })
  77. } else if(window.location.pathname.includes("profile")) {
  78. const myId = window.localStorage.getItem("ng2-webstorage|userservice.appuser_a_token").split(".")[0].split("\"")[1] || ""
  79. const id = window.location.pathname.split("/profile/")[1]
  80. const list = getList()
  81.  
  82. if(myId != id) {
  83. let username = document.querySelector("app-user-profile").querySelector(".nickname")
  84. if(!username){
  85. await waitForElement("app-user-profile .nickname")
  86. }
  87. username = document.querySelector("app-user-profile").querySelector(".nickname")
  88. const button = document.createElement("button")
  89. const list = getList()
  90.  
  91.  
  92. if(list.includes(id)){
  93. button.innerText = "unblock"
  94. button.addEventListener("click", () => removeUserFromList(id))
  95.  
  96. } else {
  97. button.innerText = "block"
  98. button.addEventListener("click", () => addUserToList(id))
  99. }
  100. username.appendChild(button)
  101.  
  102. }
  103.  
  104. await waitForElement("div .list-single-item")
  105. const thanksWallMessages = document.querySelectorAll("div .list-single-item")
  106. thanksWallMessages.forEach(msg => {
  107. list.forEach(id => {
  108. if(msg.querySelector("a")?.href.includes(id)){
  109. msg.remove()
  110. return
  111. }
  112. })
  113. })
  114. }
  115. }
  116. }
  117.  
  118. function getList() {
  119. const storage = window.localStorage.getItem("blockedUsers")
  120. let list = JSON.parse(storage || '[]')
  121. if(!Array.isArray(list)){
  122. list = []
  123. }
  124. return list
  125. }
  126.  
  127. function addUserToList(id) {
  128. const list = getList()
  129. if(!list.includes(id)){
  130. list.push(id)
  131. }
  132. window.localStorage.setItem("blockedUsers", JSON.stringify(list))
  133. window.location.reload()
  134.  
  135.  
  136. }
  137.  
  138. function removeUserFromList(id) {
  139. let list = getList()
  140. if(list.includes(id)){
  141. list = list.filter(ids => ids != id)
  142. }
  143. window.localStorage.setItem("blockedUsers", JSON.stringify(list))
  144. window.location.reload()
  145. }
  146. })();