0

The goal is to remove (not hide) all HTML elements based on a match to their name or class with a userscript. Here is a portion of the userscript in question. It doesn't remove the elements. What should be changed?

// ==UserScript==
// @name        Clean Giveaway sites
// @version     1.0
// @namespace   namespace
// @description Remove junk from giveaway sites
// @include     http://udemy.com/*
// @include     http://udemyar.com/*
// @include     http://www.udemy.com/*
// @include     http://www.udemyar.com/*
// @include     https://udemy.com/*
// @include     https://udemyar.com/*
// @include     https://www.udemy.com/*
// @include     https://www.udemyar.com/*
// @grant       none
// ==/UserScript==

var killit = document.querySelectorAll('c_header__left');
if (killit[0]) {
  killit[0].parentNode.removeChild(killit[0]);
}


var killit = document.querySelectorAll('c_header__right');
if (killit[0]) {
  killit[0].parentNode.removeChild(killit[0]);
}


var killit = document.querySelectorAll('more-from-instructor ud-react-loader ud-component--more-courses-by-instructor--app ud-react-loaded');
if (killit[0]) {
  killit[0].parentNode.removeChild(killit[0]);
}

1 Answers1

1

Are you looking for tags ? Because that's what you're asking querySelectorAll to fetch. Basicly if you have <c_header__left>...</c_header__left> in your code, querySelectorAll('c_header__left') should find it.

I assume you are looking for elements with the class c_header__left and in that cas you must prepend the string with a point.

The string you pass to querySelector and querySelectorAll has the same syntax for finding items as CSS

More clarity

Try

var killit = document.querySelectorAll('.c_header__left');
Mouradif
  • 2,666
  • 1
  • 20
  • 37