Greasy Fork is available in English.

Askfm only images

Only show images on askfm

  1. // ==UserScript==
  2. // @name Askfm only images
  3. // @version 1
  4. // @description Only show images on askfm
  5. // @author Benjababe
  6. // @match https://ask.fm/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/476679
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. window.onload = () => {
  14. console.log("Askfm images running...");
  15.  
  16. //gets latest loaded page on change
  17. let cb = (mutationList) => {
  18. let newTarget = document.querySelector(".item-pager"),
  19. newPages = newTarget.getElementsByClassName("item-page"),
  20. lastItemPage = newPages.item(newPages.length - 1);
  21. onlyShowImages(lastItemPage);
  22. }
  23.  
  24. //looks for any changes in answers page
  25. let observer = new MutationObserver(cb);
  26. let target = document.querySelector(".item-pager");
  27. observer.observe(target, { attributes: true });
  28.  
  29. let itemPages = Array.from(target.getElementsByClassName("item-page"));
  30. itemPages.forEach((itemPage) => onlyShowImages(itemPage));
  31. }
  32. })();
  33.  
  34. let onlyShowImages = (itemPage) => {
  35. let answers = Array.from(itemPage.getElementsByClassName("item"));
  36. answers.forEach((answer) => {
  37. //image element in the answer
  38. let img = answer.querySelector(".streamItem_visual");
  39. //hide if doesn't exist
  40. if (img == null) {
  41. answer.style.display = "none";
  42. }
  43. });
  44. }