Tampermonkey script not updating - userscripts

I am having issues getting my script to auto-update. If I force a check for an update, then it picks up the new version just fine. However, I am unable to get this to automatically notify me whenever a new update is available.
My script has the following metadata:
// ==UserScript==
// #name PortalScript
// #namespace PortalScript
// #version 2.1.0.9
// #description Contains customizations to be applied to the portal
// #author Tristan Lee
// #match https://test-support.portal.dev
// #grant none
// #downloadURL https://rawgit.com/tristanlee85/supportportal/master/supportportal.js
// #updateURL https://rawgit.com/tristanlee85/supportportal/master/supportportal.js
// ==/UserScript==
Tampermonkey is set to check for updates every hour. However, the version in the repository may be 2.1.0.10, but after hours since the version change, I am never notified that an update is available.
I also don't believe #updateURL is necessary here since #downloadURL is specified, but I added it as a check since only having #downloadURL didn't work either.

Related

Dose Tampermonkey can run script before the page loaded?

I'm trying to use tampermonkey to refresh a website, its works except the server was busy, and the respond time is long, may i know can the script run before the page fully loaded?
I would also wanna now can the script work on any website without the #match / #include?
Many thanks.
// #name TEST
// #version 1
// #grant none
// #match http://busy.example.com
// ==/UserScript==
setTimeout(
function(){
document.location = "http://example.com";
}, 10
);

removing an element with a userscript

First attempt at a userscript, and despite finding numerous examples on the internet of how to remove elements from a page, none of them work (and this looks like one of the most basic applications of a userscript, too).
Using violentmonkey-2.12.8 on this page:
https://www.zerohedge.com/economics/2020-greatest-hits-most-popular-articles-past-year-and-look-ahead
I want to remove the "exitModalOverlay" div (disabling it in the developer tools does exactly what I want), which blacks out the page (preventing me from reading it).
I will insert one of the more common techniques I have found (which doesn't work). I would appreciate any method which does. Thanks.
// ==UserScript==
// #namespace confused
// #name zehohedge_remove_subscription_popup
// #version 1
// #description removes the overlay div that asks to subscribe
// #match https://www.zerohedge.com/*
// #grant none
// #noframes
// ==/UserScript==
var todelete = document.getElementById('exitModalOverlay');
if (todelete) { todelete.parentNode.removeChild(todelete); }
Based on the post & comments, it seems the element is loaded/created after the DOM. In that case, you would need to run the script after page loading is complete.
Although when testing on the link provided with JavaScript enabled (https://www.zerohedge.com/economics/2020-greatest-hits-most-popular-articles-past-year-and-look-ahead), the element does not appear, here is an example of how you can remove the item.
It is possible there are other factors involved (e.g. browser, country, login, cookies etc).
ViolentMonkey by default runs on document-end which is after DOM loaded but before all external elements are loaded.
Setting the userscript to run at document-idle will run after everything is loaded.
// ==UserScript==
// #namespace confused
// #name zehohedge_remove_subscription_popup
// #version 1
// #description removes the overlay div that asks to subscribe
// #match https://www.zerohedge.com/*
// #grant none
// #noframes
// #run-at document-idle
// ==/UserScript==
// find element
const todelete = document.getElementById('exitModalOverlay');
// remove element if found
if (todelete) { todelete.remove(); }
Removing the element is not the only way to get rid of an element. You can also use CSS to achieve a similar outcome by setting its display to none. For example:
// ==UserScript==
// #namespace confused
// #name zehohedge_remove_subscription_popup
// #version 1
// #description removes the overlay div that asks to subscribe
// #match https://www.zerohedge.com/*
// #grant GM_addStyle
// #noframes
// ==/UserScript==
const css = `
#exitModalOverlay {
display: none;
}`;
GM_addStyle(css);
Using JavaScript to apply CSS to the element without GM_addStyle (although not as good as above)
// ==UserScript==
// #namespace confused
// #name zehohedge_remove_subscription_popup
// #version 1
// #description removes the overlay div that asks to subscribe
// #match https://www.zerohedge.com/*
// #grant none
// #noframes
// #run-at document-idle
// ==/UserScript==
// find element
const todelete = document.getElementById('exitModalOverlay');
// remove element if found
if (todelete) { todelete.style.display = 'none'; }
📌 It is worth noting that CSS applies all the time (unless over-written specifically), even if an element is created later, while JavaScript applies at the time it runs and will not apply to elements created later (without additional methods to cause it to run again).
Maybe so...
window.onload = function() {
var todelete = document.querySelector('#exitModalOverlay');
todelete.outerHTML = '';
}
or
window.onload = function() {
var todelete = document.querySelector('#exitModalOverlay');
todelete.remove();
}

Tampermonkey script not auto-updating

At the top of my script I have the following:
// ==UserScript==
// #name Test script
// #description testing auto-update
// #namespace http://tampermonkey.net/
// #author newbie
// #version 1.0.0
// #updateURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// #downloadURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// #match http://awebsite.com/*
// #run-at document-end
// #grant GM_getResourceText
// #grant GM_addStyle
// #grant GM_xmlhttpRequest
// #grant GM_getResourceURL
// #grant GM_xmlhttpRequest
// ==/UserScript==
Please note that these values are just for example.
When I make changes on the script and increase the version number on github and then push the changes to master it updates the raw script link, however I don't get auto-updates from Tampermonkey as in popups saying the script has an update. It will only update if I manually go to the link and reinstall the script to update it.
How can I make this auto-update with popups?
I am not an expert at userscripts, can only tell from my experience making TamperMonkey work:
In order for TamperMonkey to update, I had to copy&paste the URL into Update URL: on the script's Settings tab:
(Make sure ☒ Check for updates is turned on, obviously.)
Then if you manually Check for userscript updates on the TamperMonkey icon, you should see a proper popup.

Tampermonkey script that runs only in incognito?

Is it possible to make any script into a script that only runs on www.example.com, Only if the website is being accessed from an incognito window? (chrome)
I've added a isIncognito flag to Tampermonkey's GM_info. So you now can check the incognito mode like this:
// ==UserScript==
// #name testIncognito
// #namespace http://tampermonkey.net/
// #version 0.1
// #description enter something useful
// #match http://*/*
// #copyright 2012+, You
// ==/UserScript==
if (GM_info.isIncognito) {
alert([ GM_info.scriptHandler, 'detected incognito mode #', window.location.href ].join(' '));
}
Please not that this at the moment only is available at TM beta version 3.0.3353 and higher.

Greasemonkey Script Version Constant

I defined the version of my user script in the meta block, like this:
// ==UserScript==
// #name Script Name
// #description Something about what this script does
// #include http://www.example.com/
// #version 5.3.0
// #run-at document-end
// ==/UserScript==
Is there a way to get the version number that I defined? I want to be able to do something like alert("This is version " + SCRIPT_VERSION + ".");.
If you upgrade to Greasemonkey 0.9.16 (just released), you can use the brand new GM_info object.
You can add this to your script example, above:
var myVersion = GM_info.script.version;
console.log ('Version: ', myVersion, myVersion === "5.3.0");
Which would output this to the console:
Version: 5.3.0 true
For GM versions prior to 0.9.16, you'd have to either read your own script in as a #resource or use encapsulation techniques as shown in "Knowing Your Own Metadata".

Resources