jQuery-UI is not working in my userscript without CSS, or with customization?

The problem with userscripts and jQuery-UI is that jQUI uses CSS with lots of background images, all loaded with relative paths. EG: … url(“images/ui-bg_dots-small_35_35414f_2x2.png”) … For security reasons, that relative path will seldom work out for a userscript. This means that to use jQUI in a userscript you can either: Load the required CSS off … 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

How to get an AJAX get-request to wait for the page to be rendered before returning a response?

In order for the AJAX get to “wait for the page to be rendered”, it would actually have to fully process the page, fetching and running all the included CSS and javascript files. That’s not easy and not recommended. Fortunately, you don’t need to do that anyway. Here are three better ways to approach this … Read more

Chrome 65 blocks cross-origin . Client-side workaround to force download?

According to the discussion blob: and data: URLs are unaffected, so here is a workaround using fetch and Blobs. Client-side force download media function forceDownload(blob, filename) { var a = document.createElement(‘a’); a.download = filename; a.href = blob; // For Firefox https://stackoverflow.com/a/32226068 document.body.appendChild(a); a.click(); a.remove(); } // Current blob size limit is around 500MB for browsers … Read more

Run Greasemonkey script on the same page, multiple times?

The simplest, most robust way is to use the waitForKeyElements() utility. Here is a complete script that uses jQuery and waitForKeyElements to alter Amazon search results: // ==UserScript== // @name _Amazon Search, alter results // @include http://www.amazon.com/s/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to … Read more

jQuery in Greasemonkey 1.0 conflicts with websites using jQuery

Greasemonkey 1.0, radically changed the way the sandbox works, busting thousands of scripts. This is a huge problem, and I hope you will join me in voicing your opinion/experiences on the principle bug report for this issue. The Greasemonkey blog claims that you can workaround the issue with the following: this.$ = this.jQuery = jQuery.noConflict(true); … Read more