I would like to run this TamperMonkey script on all YouTube.com sites exclusively:
// ==UserScript==
// @name YouTubeFakeScriptName
// @version 0.3
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
// Insert any JavaScript here.
Here's the problem, it's not scoped to YouTube only. I have tried many alternatives:
// @namespace http://youtube.com
// @namespace https://youtube.com
// @namespace https://youtube.com/
// @namespace https://youtube.com/*
// @namespace youtube.com
// @namespace *
// @namespace */youtube.com/*
Similarly with @include, here is what it said on http://tampermonkey.net/documentation.php
The pages on that a script should run. Multiple tag instances are allowed.
Please note that @include
doesn't support the URL hash parameter. Please visit this forum thread for more information: click.
Code:
// @include http://tampermonkey.net/*
// @include http://*
// @include https://*
// @include *
Along with many other possibilities, but I cannot seem to make scope only apply to YouTube, I can either:
- apply all TamperMonkey code to all websites
- apply no TamperMonkey code to all websites
- Have TamperMonkey script appear when extension is pressed
- And be Green
- And be Red
- Have TamperMonkey script not appear when extension is pressed
This last option is even odder, using match has strange behavior; I cannot even get my script to even appear when clicking the extension button if I use either:
// @match https://youtube.com/*
// @match *
But the script does appear if I don't use @match at all or use:
// @match */*
Additional: I can confirm that using the following produces no script in the extension upon clicking Tampermonkey:
// ==UserScript==
// @name YouTubeRandomAppHere
// @match https://youtube.com/*
// @version 0.3
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
The solution required a few steps which are added to the original post at the bottom, so that others may learn as well. Thank you for your help.
remove @namespace add both:
// @match *://*.youtube.com/*
// @noframes
Note:
The best way to specify sites in Tampermonkey is with the
@match
directive. (Or use@include
for more options but less performance and "safety".)YouTube almost always uses the
www.
subdomain, so directives like// @match https://youtube.com/*
will almost never match.
Occasionally,
http://
still works.From your description, you probably don't want the script to work on iframed or embedded content.
So you want directive(s) that match the following URL patterns and exclude everything else:
See the Match Patterns documentation. The pattern that does all that is:
Putting it all together: