userscripts

window.load doesn't fire always on chrome?

你说的曾经没有我的故事 提交于 2019-11-27 07:11:42
问题 I have this userscript: // ==UserScript== // @name test // @namespace test // @description show's an alert on load // @include http://* // @include https://* // ==/UserScript== window.addEventListener('load', function(){alert("loaded");}, false); This works fine on Firefox on all pages but doesn't work at all on Chrome at some occasions. One example is this website: http://lexin.nada.kth.se/lexin/ Entering the link in the address and hitting enter, loads the page normally but no alert is

Apply a Greasemonkey/Tampermonkey/userscript to an iframe?

本秂侑毒 提交于 2019-11-27 05:16:21
The title is pretty much the question: Is it possible to add a Greasemonkey script to an iframed website? If so, how? Thank you. In Greasemonkey (And Tampermonkey and most userscript engines) a script will fire on an iframe automatically if it meets the @include , @exclude , and/or @match directives. And, a popular question is how to stop Greasemonkey from firing on iframes . So, if your script had a match like: @match https://fiddle.jshell.net/* It would fire on jsFiddle "output" pages whether or not they appeared in an iframe. If you wanted to fire on a JUST iframed content: Then you would

How to override the alert function with a userscript?

瘦欲@ 提交于 2019-11-27 04:55:04
On site there is code like that (its site on LAN) <script language="JavaScript" type="text/javascript"> alert("ble"); </script> I try to disable that alert using GM. I was trying to do this unsafeWindow.alert=function() {}; but I see the alert and get this error Error: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: file:///C:/Documents%20and%20Settings/arokitnicki/Dane%20aplikacji/Mozilla/Firefox/Profiles/sm4bsods.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/components/greasemonkey.js ::

Cross-origin XHR from a user script in Google Chrome

纵饮孤独 提交于 2019-11-27 04:37:44
问题 Has anybody had any luck performing cross origin XHRs from a user script in Google Chrome? The requests go through to the server (I can see them in the logs) but, the readystatechanged event is never fired. Extension permissions don't seem to be doing the trick. Neither is JSONP. 回答1: Current versions of Chrome (13.0.781 or later) now support most or all of the GM_xmlhttpRequest()Doc functionality -- including cross-domain requests . See Issue 18857: Support cross-site XMLHttpRequest in

How can two instances of a userscript communicate between frames?

北慕城南 提交于 2019-11-27 04:34:43
Refer to the technique of having the same JavaScript to run in both a web page and an iframe, as described in this answer : For example, suppose you have this page at domain_A.com: <html> <body> <iframe src="http://domain_B.com/SomePage.htm"></iframe> </body> </html> If you set your @match directives like this: // @match http://domain_A.com/* // @match http://domain_B.com/* Then your script will run twice -- once on the main page and once on the iframe as though it were a standalone page. What are the options to have the two instances of the script to communicate with each other? This would be

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: // =

Is there any way of passing additional data via custom events?

无人久伴 提交于 2019-11-27 01:23:23
I need to pass data between two autonomic userscripts - ideally w/o touching the unsafeWindow object - and I thought using custom events would be the way to go. I thought of something like this (let us disregard the MSIE model for the purpose of the example): addEventListener("customEvent", function(e) { alert(e.data); }); var custom = document.createEvent("HTMLEvents"); custom.initEvent("customEvent", true, true); custom.data = "Some data..."; dispatchEvent(custom); This works nicely in the standard javascript environment and within one userscript, but when the event is fired by the

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

Native javascript equivalent of jQuery :contains() selector

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 23:13:34
问题 I am writing a UserScript that will remove elements from a page that contain a certain string. If I understand jQuery's contains() function correctly, it seems like the correct tool for the job. Unfortunately, since the page I'll be running the UserScript on does not use jQuery, I can't use :contains(). Any of you lovely people know what the native way to do this is? http://codepen.io/coulbourne/pen/olerh 回答1: This should do in modern browsers: function contains(selector, text) { var elements