Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Gab Utils
- // @description Hide Gab 'Introduce Yourself' posts, click 'Read more'
- // @author gab.com/jfras
- // @version 0.0.8
- // @icon https://gab.com/favicon.ico
- // @namespace Violentmonkey Scripts
- // @match https://gab.com/*
- // @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
- // @run-at document-idle
- // ==/UserScript==
- const loadingSel = 'a._UuSG._3dGg1._3YbVp._3Ujf8'; // user name selector
- const readMore = 'button._2VJLs > span'; // 'Read more' button in long posts
- const introSel = 'a[href="/groups/12"]'; // 'Introduce Yourself' group link
- const DELAY = 350; // milliseconds delay
- var applyChanges = function()
- {
- const q = document.querySelector(introSel);
- if(q != null && q.innerText == 'Introduce Yourself') {
- var e = getParentTag(q, 'ARTICLE');
- // log(q, "ID:", e[0].dataset.id);
- if(e[0]) {
- e[0].style.display = 'none';
- log("'Introduce Yourself' post hidden");
- }
- }
- // // un-comment this block to enable auto-clicking 'Read more'
- // const r = document.querySelector(readMore);
- // if(r != null && r.innerText == 'Read more') {
- // var e = getParentTag(r, 'ARTICLE');
- // if(e[1] == 9 || e[1] == 14) {
- // r.click();
- // log("Clicked 'Read more'");
- // }
- // }
- };
- function checkLoading() {
- let targetNode = $(loadingSel);
- // Only add event listener if page is fully loaded
- if(targetNode && targetNode.length > 0) {
- window.addEventListener('scroll', () => {
- setTimeout(applyChanges, DELAY);
- });
- log("Ready");
- }
- // Otherwise, call self again after short delay
- else {
- setTimeout(checkLoading, DELAY);
- }
- }
- (function() {
- log('Loaded');
- checkLoading();
- })();
- function getParentTag(el, tag) {
- let i = 0;
- while(el.parentNode) {
- el = el.parentNode;
- if(el.tagName === tag) {
- return [el, i];
- }
- i++;
- }
- return [null, null];
- }
- function log(...args) {
- console.info(`%c ${GM.info.script.name} `,
- 'color: white; font-weight: bold; background: #21cf7a',
- ...args);
- }
Add Comment
Please, Sign In to add comment