greasemonkey

How to convert a bookmarklet into a Greasemonkey userscript?

空扰寡人 提交于 2019-11-27 02:00:16
问题 Is there a easy way to do this. And is there anything that needs to be changed due to differences in how it is ran? 回答1: The easiest way to do this: Run the bookmarklet code through a URL decoder. so that javascript:alert%20('Hi%20Boss!')%3B , for example, becomes: javascript:alert ('Hi Boss!'); Strip the leading javascript: off. Result: alert ('Hi Boss!'); Add this code to the end of your Greasemonkey file. For example, create a file named, Hello World.user.js , with this code: // =

Save File using Greasemonkey

拈花ヽ惹草 提交于 2019-11-27 01:59:30
问题 I have some screen scraped tabular data that I want to export to a CSV file (currently I am just placing it in the clipboard), is there anyway to do this in Greasemonkey? Any suggestions on where to look for a sample or some documentation on this kind of functionality? Just to be clear, I don't want to write to the local file system (I know that is impossible in the sandbox), but present a downloadable file - which may also be impossible... 回答1: Maybe you can't write it to a local CSV, but

Find all instances of 'old' in a webpage and replace each with 'new', using a javascript bookmarklet

浪子不回头ぞ 提交于 2019-11-27 01:02:58
问题 What I want to do is replace all instances of 'old' in a webpage with 'new' in a JS bookmarklet or a greasemonkey script. How can I do this? I suppose jQuery or other frameworks are okay, as there're hacks to include them in both bookmarklets as well as greasemonkey scripts. 回答1: A function that is clobber-proof. That mean's this won't touch any tags or attributes, only text. function htmlreplace(a, b, element) { if (!element) element = document.body; var nodes = element.childNodes; for (var

How to simulate typing in input field using jQuery?

假如想象 提交于 2019-11-27 00:21:03
问题 What I want is to simulate typing in <input> field using javascript. I have the following code: var press = jQuery.Event("keydown"); press.ctrlKey = false; press.which = 65; $("#test").trigger(press); But when I load the page, the #test input field has no typed characters, the keycode of '65' represents 'A', but there is no 'A' input. Basically what I want is to automatically typing in the website using Greasemonkey. Please give me some ideas or some library with which I can use to do this.

Simulating a mousedown, click, mouseup sequence in Tampermonkey?

孤街浪徒 提交于 2019-11-27 00:19:36
I would like to simulate a whole click not just document.getElementsByClassName()[0].click(); How do I do that? Search results all seem to be about handling such events, not triggering them. Brock Adams 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")

How to replace lots of words in AJAX-driven page text, and in select attributes — using a Tampermonkey script?

我的梦境 提交于 2019-11-26 23:41:21
问题 I'm translating text/words/terms inside an HTML document using a tree walker to affect only text nodes: var replaceArry = [ [/View your user account/gi, 'Tu cuenta'], // etc. ]; var numTerms = replaceArry.length; var txtWalker = document.createTreeWalker ( document.body, NodeFilter.SHOW_TEXT, { acceptNode: function (node) { //-- Skip whitespace-only nodes if (node.nodeValue.trim() ) return NodeFilter.FILTER_ACCEPT; return NodeFilter.FILTER_SKIP; } }, false ); var txtNode = null; while

Synchronous GM_xmlhttpRequest acting asynchronously?

为君一笑 提交于 2019-11-26 23:39:34
问题 I'm trying to get a GM_xmlhttpRequest call to behave synchronously, but I can't get it to work like I expect: function myFunction (arg) { var a; GM_xmlhttpRequest ( { method: "GET", url: "http://example.com/sample/url", synchronous: true, onload: function (details) { a = details.responseText; } } ); return a; } b = myFunction (); alert (b); I never get anything back for b here; it's undefined. Is there some step that I'm missing here? I'm using v0.9.13 of Greasemonkey, and v9.0.1 of Firefox.

Add parameters to the URL (redirect) via a Greasemonkey/Tampermonkey/Userscript

陌路散爱 提交于 2019-11-26 23:08:25
I'd like to write a Greasemonkey/userscript that automatically adds .compact to URLs starting with https://pay.reddit.com/ so It automatically redirects me to the mobile version. I've been looking at similar userscripts, particularly this one: https://userscripts.org/scripts/review/112568 trying to figure out how to edit the replacement pattern, but I lack skills in this domain. How do I write a Greasemonkey script that redirects me from https://pay.reddit.com/* to https://pay.reddit.com/*.compact ? Thanks The script should do these things: Detect if the current URL is already to the compact

How to call Greasemonkey's GM_ functions from code that must run in the target page scope?

给你一囗甜甜゛ 提交于 2019-11-26 22:59:49
I asked a question and got an answer here: How to call this YouTube function from Greasemonkey? That code works and adds a button to the page, which captures the video time. But, the key part must run in the target-page scope -- where Greasemonkey's GM_ functions are not available. I want to use GM_setValue() to record the video time. How do I call GM_setValue() from my button's click handler? Here is the relevant part of the complete script (right-click to save) : ... ... //-- Only run in the top page, not the various iframes. if (window.top === window.self) { var timeBtn = document

Controlling Netflix (HTML5) playback with Tampermonkey/javascript

狂风中的少年 提交于 2019-11-26 22:59:37
问题 While watching a netflix video on a Netflix site, my goal is to have a userscript invoke the playback controls programmatically. Specifically, the volume, level, play/pause state, and time position of the video. I've been able to manipulate the html5 video element itself, but controlling that directly does not provide the needed netflix control bar feedback to the user. (i.e. video is paused, but the control bar still shows it as playing). My approach thus far has been to try and locate the