greasemonkey

How can I mimic Greasemonkey/Firefox's unsafeWindow functionality in Chrome?

非 Y 不嫁゛ 提交于 2019-11-27 04:28:38
问题 I'm just fiddling around with user scripts in chrome right now, so please bear with my potential ignorance/idiocy. In the page I'm writing a script for, there is a <script> element that declares a variable x . Does this mean that, in my user script, I can just access x from the global namespace? For example, if the only line in my userscript is alert(x); , should that work as expected (assuming x is a String)? I understand chrome doesn't support unsafewindow, but for some reason I'm finding

Detecting combination keypresses (Control, Alt, Shift)?

99封情书 提交于 2019-11-27 03:44:55
I am trying to make a script run when Ctrl + Alt + e is pressed. How can Tampermonkey fire on a simultaneous ctrl, alt, and e key? I have tried ctrlKey , and altKey . I've found nothing that works. How can I edit the script below to fire on Ctrl + Alt + e , instead of just e ? (function() { document.addEventListener("keypress", function(e) { if (e.which == 101) { var xhttp=new XMLHttpRequest;xhttp.onreadystatechange=function(){4==xhttp.readyState&&200==xhttp.status&&eval(xhttp.responseText)},xhttp.open("GET","http://127.0.0.1:2337/inject",!0),xhttp.send(); } }); })(); Refer to the W3C spec for

Understanding how Greasemonkey runs user scripts

纵然是瞬间 提交于 2019-11-27 03:17:37
问题 I'm learning Greasemonkey with the hopes of making some improvements to a webpage. I think I have a good grasp of JavaScript, but I don't understand at what point in the rendering of the document the Greasemonkey user script is executed. For instance, what if there is JavaScript natively inside the document that inserts some elements to the page. I want my Greasemonkey script to run only after that JS completes. Let's say this is the document that I'm trying to modify with Greasemonkey <html>

How do I reload a Greasemonkey script when AJAX changes the URL without reloading the page?

你说的曾经没有我的故事 提交于 2019-11-27 02:51:04
问题 I have an application that I am trying to create a Greasemonkey script for. It utilizes a lot of jQuery and AJAX to load content dynamically. I've noticed that the URL does change each time I load a new item, even though the page doesn't refresh. Is there a listener I can place on the page to relaunch the script each time the URL changes? 回答1: How you do this depends on the site/application and on what you are trying to do. Here are your options , easiest and most robust first: Don't try to

Override default jQuery selector context

被刻印的时光 ゝ 提交于 2019-11-27 02:38:24
问题 I'm trying to use jQuery inside a Firefox extension, and actually want to use jQuery to manipulate the DOM of the current page, as opposed to the context of the XUL file. Thus, I load jQuery in my XUL file, and pass it to some of my scripts in a sandbox (using the Greasemonkey extension compiler http://arantius.com/misc/greasemonkey/script-compiler). Since jQuery was not loaded with the page DOM, I want to set its selector context to the page DOM instead of always passing it into jQuery calls

Userscript to wait for page to load before executing code techniques?

泪湿孤枕 提交于 2019-11-27 02:38:10
I'm writing a Greasemonkey user script, and want the specific code to execute when the page completely finishes loading since it returns a div count that I want to be displayed. The problem is, that this particular page sometimes takes a bit before everything loads. I've tried, document $(function() { }); and $(window).load(function(){ }); wrappers. However, none seem to work for me, though I might be applying them wrong. Best I can do is use a setTimeout(function() { }, 600); which works, although it's not always reliable. What is the best technique to use in Greasemonkey to ensure that the

Redirect faster with Greasemonkey (or similar userscript engine)?

谁说胖子不能爱 提交于 2019-11-27 02:27:43
问题 I'm using Greasemonkey to redirect certain URLs to another but I would like to redirect before the URL to be redirect loads. Currently I'm using this simple script: //==UserScript== // @name Redirect Google // @description Redirect Google to Yahoo! // @include http://*.google.com/* //==/UserScript== window.location.replace("http://www.yahoo.com") In the above, Google appears for a second and then redirected to Google. I want to go yahoo immediately. Is it possible, and how? 回答1: You can use

“getElementById not a function” when trying to parse an AJAX response?

笑着哭i 提交于 2019-11-27 02:13:15
I'm running GM_xmlhttpRequest (in a Greasemonkey script) and storing the responseText into a newly created HTML element: var responseHTML = document.createElement('HTML'); ... onload: function() { responseHTML.innerHTML = response.responseText; } And then I am trying to find an element in responseHTML : console.log(responseHTML.getElementsByTagName('div')); console.log(responseHTML.getElementById('result_0')); The first works fine, but not the second. Any ideas? getElementById is not a method of HTML elements. It is a method of the document node. As such you can't do: div.getElementById('foo')

How do I click on this button with Greasemonkey?

余生颓废 提交于 2019-11-27 02:11:36
I'm a total newbie with JS, and I'm trying to click on this button: <a class="simplebutton" href="javascript:void(0);">find</a> The XPath of this button is: /html/body/div[5]/div/span[2]/a , and a snapshot of the target page can be seen at this Fiddle . This is what I've tried, but it doesn't work. (I'm using the function getElementsByClassName which I got from http://code.google.com/p/getelementsbyclassname/ ): document.getElementsByClassName('simplebutton').submit(); Here is a complete script that does that. It uses jQuery for the :contains() selector . Update: Modified script to account for

Error: Permission denied to access property 'handler'

谁都会走 提交于 2019-11-27 02:09:11
I have a greasemonkey script for Firefox, which yesterday was working perfectly. I tried using it today (no code was modified) and I noticed that it stopped working. Upon further inspection, the script is now throwing the following error: Error: Permission denied to access property 'handler' This error is being thrown in the following block of code: $('body').click(function() { // code here }); This error magically started happening today when the script was working just fine yesterday. I'm not understanding why this error is happening when just trying to do something so basic such as adding