Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ben Os
Ben Os
20,008 Points

Script works on console but not on Chrome Tampermonkey

I ran inner essence of the function of the following script in non strict mode in console just fine but it doesn't run in Chrome Tampermonkey after I saved it (when it's enabled) and fully restarted the browser. Tampermonkey itself is also enabled of course... Maybe I'm missing something here by means of strict Js (which I've yet to learn)?

(function fbPurity () {
    'use strict';

    var chat = document.querySelector(".noGrip");
    chat.style.display = "none";

})();

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hello Ben Aharoni

I'm not familiar with Tampermonkey. Looks like it's a tool for creating userscript (greasemonkey) scripts. We don't teach that tool, so I'm afraid I won't be able to assist you with any problems specific to Tampermonkey.

The 'use strict'; statement should have no effect on this. Are there any specific errors you are seeing? Your code looks like it's specific to a particular page (or DOM) since it references a particular class name.

Ben Os
Ben Os
20,008 Points

Hi dear Dave! While there were no errors the problem was, as clued from your answer, that I didn't configure the matched page right... The script was setted to work with the default tampermonkey test page. My mistake was when I first created the script (that hides an annoying feature in Facebook pages), I thought that if I create it in facebook.com it will then automatically be applied to all pages in Facebook, but of course I was wrong and now when the match is:

// @match      https://www.facebook.com/*

It does work on all FB's pages.

So, thank you for giving me this direction!

Ben,