How to change the style of a specific site with a Tampermonkey script? - greasemonkey

Everytime I access a specific site like www.abc.com I want the background color to be red. How do I implement this condition in a tempermonkey script? Or is there a better way to do this?

In Tampermonkey the easiest way to change a style is to use the function GM.addStyle. Keep in mind you'll have to add the accordingly grant-tag in the header.
// ==UserScript==
// #name change the style of a specific site
// #match https://www.example.com/*
// #grant GM.addStyle
// ==/UserScript==
GM.addStyle("body{background-color:red!important}");

Related

#exclude in userscript not working as expected

I have a userscript that I would like to run for a particular domain, but not for a particular page.
For example, I want to stop the script from running when the URL contains documentMode=edit:
https://blah.itglue.com/2443511/docs/8093867#documentMode=edit&version=draft
I tried this:
// #exclude https://blah.itglue.com/*/docs/*#documentMode=edit
// #exclude https://blah.itglue.com/.*/docs/.*documentMode=edit&.*
// #match https://blah.itglue.com/*
However, the script still runs and I'm not sure what I'm doing wrong. I can see the URL added to exclude in Tampermonkey.
I checked this in a regex live editor and the above URL matches perfectly. I refreshed the page but the userscript is still applied....
However, if I use this, it stops the script loading on the page:
/(^[^:\/#\?]*:\/\/([^#\?\/]*\.)?blah\.itglue\.com(:[0-9]{1,5})?\/.*$)/
I don't want the script to stop working on the root domain though.....

My Greasemonkey script runs on every site except the one I want it to?

I'm trying to set up a script to run on Quora, but it's running on every other site instead.
I have the #include directive in the metadata block, and under script settings/include, it's set to include *, and I can't see any way to remove that.
Here's a thread about the same issue I'm having, but there's no #exclude directive to remove (although I did try putting #exclude * before the #include, but that didn't fix anything). I also checked my formatting against the answer here and I don't see any typos.
Here's my metadata block.
// ==UserScript==
// #name Quora fixer
// #namespace quora
// #include https://www.quora.com/*
// #version 1
// #grant none
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// #description prevents links from opening in a new tab
// #run-at document-idle
// ==UserScript==
First, see and follow My very simple Greasemonkey script is not running?.
If the script is running on every other page, and there are no Quora-specific #excludes, then the script most-likely is running on Quora -- just not doing what you expect.
Other issues or actions:
You are using #grant none and #require-ing jQuery. This leads to conflicts and javascript crashes on sites like Quora. Use #grant GM_addStyle.
If the Script Settings tab (not to be confused with the User Settings tab) shows differently than the actual script source, then either you are not looking at the same file Greasemonkey is, or Greasemonkey and/or Firefox has become corrupted/confused. In that case:
Uninstall the Greasemonkey script.
Completely clear the browser cache.
Shutdown Firefox completely. Use Task Manager, or equivalent, to verify that there is no Firefox thread/task/process in memory.
Go to your Firefox profile folder.
Enter the gm_scripts folder therein.
If there are any subfolders left over from the script you just uninstalled, delete them. In your case, the folders should have names similar to Quora_fixer.
Restart Firefox.
Make sure the script is not listed.
Install the Greasemonkey script afresh.
If it still doesn't work, create a new Firefox profile or try a different computer altogether.
Once the script fires on Quora and no relevant errors show on Firefox's Browser Console (see the first link above), then if the script still does not do what you expect, you may need to apply AJAX-aware techniques.

Greasemonkey #exclude does nothing

Greasemonkey script excludes do nothing, for some reason. They do not even seem to be recognized by Greasemonkey, and I would like to know why.
I have to go into the preferences for each script and add the excludes manually if I want the desired behavior. Apparently I'm getting the syntax correct, since a simple script like (there's nothing special about my choice of domain names, and I've checked it with others):
// ==UserScript==
// #name Delete Adsense Junk
// #exclude http://en.wikibooks.org/*
// #exclude https://en.wikibooks.org/*
// #include http://weather.org/*
// #include https://weather.org/*
// #version 1
// ==/UserScript==
alert("Alert!");
tells me all about where the script will and won't execute when I go to install it. Firefox wants to run the script on every page unless I navigate to the preferences for that script and change the user excludes though. The list of script excludes is empty and the include is just the wildcard. Is there some option that should be enabled/disabled that I'm missing? The user excludes seem to work normally. I'm just trying to figure out why Greasemonkey is ignoring the directives that I put in the script.
The script runs on the page and on all its frames. The alert box tells you which domain it is from (at least in FF). For example on YouTube it also runs for https://plus.google.com and https://s.ytimg.com. So for YouTube I get a total of 3 alerts and if youtube.com is excluded still 2 alerts.
Check out this post to see how to exclude them.

How to change web-page without link?

How to change web-page without link, using greasemonkey? Is it even possible? For e.g. , I am on http://www.google.com/ and how can I get to http://www.youtube.com without a link?
// ==UserScript==
// #name _Redirect foo.
// #include http://www.google.com/
// ==/UserScript==
//--- Do it this way to keep Google in history (back button).
window.location.href = 'http://www.youtube.com/';
//--- Or, do it this way to keep Google out of history.
window.location.replace ('http://www.youtube.com/');
Use the redirect:
Put this HTML redirect code between and tags of your HTML code.
< meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">
source: http://www.web-source.net/html_redirect.htm
content is the number of seconds.
Here's an example where it refeshes the page: http://www.adelazzam.com/as.html

Need to have separate "complete" Drupal theme for each page on a site

I want to build a Drupal demonstration site where I can create several custom themes and display each on a separate page of the site. Access can be either via links or menu items. The "simpler" the solution the better.
Create a custom block that executes PHP code. The following code snippet should show the current page in the theme set in $custom_theme.
global $custom_theme, $theme;
// If $theme is set, init_theme() will not initialize the custom theme.
unset($theme);
// Set the theme you want to use.
$custom_theme = "garland";
init_theme();
There is also a module that allows you to change the used theme based on some rules (in example, the content type being showed, the URL of the page being viewed, etc): the project page is http://drupal.org/project/themekey.

Resources