ieatacid

Gab Utils

Sep 6th, 2020 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name                Gab Utils
  3. // @description         Hide Gab 'Introduce Yourself' posts, click 'Read more'
  4. // @author              gab.com/jfras
  5. // @version             0.0.8
  6. // @icon                https://gab.com/favicon.ico
  7. // @namespace           Violentmonkey Scripts
  8. // @match               https://gab.com/*
  9. // @require             https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
  10. // @run-at              document-idle
  11. // ==/UserScript==
  12.  
  13.  
  14. const loadingSel = 'a._UuSG._3dGg1._3YbVp._3Ujf8';      // user name selector
  15. const readMore = 'button._2VJLs > span';                // 'Read more' button in long posts
  16. const introSel = 'a[href="/groups/12"]';                // 'Introduce Yourself' group link
  17.  
  18. const DELAY = 350;                                      // milliseconds delay
  19.  
  20.  
  21. var applyChanges = function()
  22. {
  23.     const q = document.querySelector(introSel);
  24.     if(q != null && q.innerText == 'Introduce Yourself') {
  25.         var e = getParentTag(q, 'ARTICLE');
  26.         // log(q, "ID:", e[0].dataset.id);
  27.         if(e[0]) {
  28.             e[0].style.display = 'none';
  29.             log("'Introduce Yourself' post hidden");
  30.         }
  31.     }
  32.    
  33.     // // un-comment this block to enable auto-clicking 'Read more'
  34.     // const r = document.querySelector(readMore);
  35.     // if(r != null && r.innerText == 'Read more') {
  36.     //     var e = getParentTag(r, 'ARTICLE');
  37.     //     if(e[1] == 9 || e[1] == 14) {
  38.     //         r.click();
  39.     //         log("Clicked 'Read more'");
  40.     //     }
  41.     // }
  42. };
  43.  
  44. function checkLoading() {
  45.     let targetNode = $(loadingSel);
  46.  
  47.     // Only add event listener if page is fully loaded
  48.     if(targetNode && targetNode.length > 0) {
  49.         window.addEventListener('scroll', () => {
  50.             setTimeout(applyChanges, DELAY);
  51.         });
  52.         log("Ready");
  53.     }
  54.     // Otherwise, call self again after short delay
  55.     else {
  56.         setTimeout(checkLoading, DELAY);
  57.     }
  58. }
  59.  
  60. (function() {
  61.     log('Loaded');
  62.     checkLoading();
  63. })();
  64.  
  65. function getParentTag(el, tag) {
  66.     let i = 0;
  67.     while(el.parentNode) {
  68.         el = el.parentNode;
  69.         if(el.tagName === tag) {
  70.             return [el, i];
  71.         }
  72.         i++;
  73.     }
  74.     return [null, null];
  75. }
  76.  
  77. function log(...args) {
  78.     console.info(`%c ${GM.info.script.name} `,
  79.         'color: white; font-weight: bold; background: #21cf7a',
  80.         ...args);  
  81. }
  82.  
Add Comment
Please, Sign In to add comment