Save images to hard disk WITHOUT prompt?

It is possible when using Tampermonkey or Violentmonkey (Firefox or Chrome). Those userscript managers have added a GM_download method. You can use it like this: // ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match http*://*/* // @grant GM_download // … Read more

UserScripts & Greasemonkey: calling a website’s JavaScript functions

Background Doesn’t Greasemonkey inject my extensions JavaScript already? Can someone clarify this for me please. Greasemonkey executes your scripts in a sandbox, which is a restricted environment without direct access to the JavaScript in the page. Earlier versions of Greasemonkey injected scripts directly into the page, but this introduced serious security vulnerabilities. In the old … Read more

Using ECMAScript 6

In Chrome, most of the ES6 features are hidden behind a flag called “Experimental JavaScript features”. Visit chrome://flags/#enable-javascript-harmony, enable this flag, restart Chrome and you will get many new features. Arrow functions are not yet implemented in V8/Chrome, so this flag won’t “unlock” arrow functions. Since arrow functions are a syntax change, it is not … Read more

How to change a class CSS with a Greasemonkey/Tampermonkey script?

For this, just use the CSS cascade. Add a style sheet to the page with GM_addStyle(). Note: We use the !important flag to cover certain potential conflicts. Use @run-at document-start (or use Stylus, see below) to minimize “flicker” associated with changing styles after the initial render. A complete script: // ==UserScript== // @name _Override banner_url … Read more

Simulating a mousedown, click, mouseup sequence in Tampermonkey?

Send mouse events. Like so: //— Get the first link that has “stackoverflow” in its URL. var targetNode = document.querySelector (“a[href*=’stackoverflow’]”); if (targetNode) { //— Simulate a natural mouse-click sequence. triggerMouseEvent (targetNode, “mouseover”); triggerMouseEvent (targetNode, “mousedown”); triggerMouseEvent (targetNode, “mouseup”); triggerMouseEvent (targetNode, “click”); } else console.log (“*** Target node not found!”); function triggerMouseEvent (node, eventType) { … Read more

Can a website know if I am running a userscript?

Yes, in theory, a site can deduce the presence of scripts in various situations. This is not foolproof and usually is way too much trouble for the negligible “threat” to the site. (Then again, some webmasters can be obsessive-paranoids about such things. 😉 ) Some methods, depending on what the script does (in no particular … Read more

Why is window (and unsafeWindow) not the same from a userscript as from a tag?

See “Are Chrome user-scripts separated from the global namespace like Greasemonkey scripts?”. Both Chrome userscripts/content-scripts and Greasemonkey scripts are isolated from the page’s javascript. This is done to help keep you from being hacked, but it also reduces conflicts and unexpected side-effects. However, the methods are different for each browser… Firefox: Runs scripts in an … Read more