greasemonkey

How can I intercept XMLHttpRequests from a Greasemonkey script?

为君一笑 提交于 2019-11-26 05:51:22
问题 I would like to capture the contents of AJAX requests using Greasemonkey. Does anybody know how to do this? 回答1: The accepted answer is almost correct, but it could use a slight improvement: (function(open) { XMLHttpRequest.prototype.open = function() { this.addEventListener("readystatechange", function() { console.log(this.readyState); }, false); open.apply(this, arguments); }; })(XMLHttpRequest.prototype.open); Prefer using apply + arguments over call because then you don't have to

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

给你一囗甜甜゛ 提交于 2019-11-26 05:38:25
问题 I only want to use a tiny part of jQuery-UI (Menus) in a userscript I am making. jQuery-UI offers custom downloads, but I cannot find any links to specific modules, that I can @require in the script. Does anyone host the individual modules? Also, I have tried just requiring code.jquery.com/ui/1.11.1/jquery-ui.js , and the script crashes. Do I need to include some CSS with it as well? And also do some messy looking changes, like according to this answer? Will that code be different for

How to use greasemonkey to selectively remove content from a website

人盡茶涼 提交于 2019-11-26 04:26:47
问题 The content I am trying to modify has a series of <div> entries, and within each of these are other <div> entries. There are no id tags to help here. What I want the script to do is inspect the content of each of these <div> entries and look for some text. This will be used to determine whether the whole \'\' entry is deleted/hidden or not. Is this possible? How? Below is an example. There are several of these in the page, and I want to delete/hide the ones where the text inside the <div

Removing an anonymous event listener

大城市里の小女人 提交于 2019-11-26 03:39:53
问题 Is there anyway to remove an event listener added like this: element.addEventListener(event, function(){/* do work here */}, false); Without replacing the element? 回答1: There is no way to cleanly remove an event handler unless you stored a reference to the event handler at creation. I will generally add these to the main object on that page, then you can iterate and cleanly dispose of them when done with that object. 回答2: You could remove the event listener like this: element.addEventListener

How do I get the information from a meta tag with JavaScript?

主宰稳场 提交于 2019-11-26 03:35:25
问题 The information I need is in a meta tag. How can I access the \"content\" data of the meta tag when property=\"video\" ? HTML: <meta property=\"video\" content=\"http://video.com/video33353.mp4\" /> 回答1: You can use this: function getMeta(metaName) { const metas = document.getElementsByTagName('meta'); for (let i = 0; i < metas.length; i++) { if (metas[i].getAttribute('name') === metaName) { return metas[i].getAttribute('content'); } } return ''; } console.log(getMeta('video')); 回答2: The

How can I use jQuery in Greasemonkey?

余生长醉 提交于 2019-11-26 03:22:24
问题 I tried putting this line but it doesn\'t work: // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js jQuery doesn\'t work in Greasemonkey at all. Is there other way to use jQuery in Greasemonkey? -- For all the people who have the same problem, you must upload the file to greasespot then install it from there. The Create New Script option wouldn\'t work! 回答1: Perhaps you don't have a recent enough version of Greasemonkey. It was version 0.8 that added @require . // @require

Detect iFrame embedding in Javascript

蹲街弑〆低调 提交于 2019-11-26 02:54:55
问题 I have an application that has a certain page -- let\'s call it Page A. Page A is sometimes a top-level page, but also sometimes is embedded as an iframe within page B. All pages come from the same server and there are no cross-domain issues. I have a greasemonkey script that runs on page A. How can the greasemonkey script detect whether page A is within the iframe context or not? 回答1: Looking at frame length breaks down generally if page A itself has frames (I know this might not be the case

Fire Greasemonkey script on AJAX request

做~自己de王妃 提交于 2019-11-26 01:58:55
问题 I am working on a user script and I\'ve just found that the script is not run when the main page makes AJAX requests. Is there any way to fire the user script both on main page load and on AJAX requests? 回答1: The smart way to rerun the script's code on AJAX requests, is to focus on the key bits of the page and check for changes. For example, suppose a page contained HTML like so: <div id="userBlather"> <div class="comment"> Comment 1... </div> <div class="comment"> Comment 2... </div> ... <

Event when window.location.href changes

≯℡__Kan透↙ 提交于 2019-11-26 01:45:27
I'm writing a Greasemonkey script for a site which at some point modifies location.href . How can I get an event (via window.addEventListener or something similar) when window.location.href changes on a page? I also need access to the DOM of the document pointing to the new/modified url. I've seen other solutions which involve timeouts and polling, but I'd like to avoid that if possible. popstate event : The popstate event is fired when the active history entry changes. [...] The popstate event is only triggered by doing a browser action such as a click on the back button (or calling history

Accessing Variables from Greasemonkey to Page & vice versa

扶醉桌前 提交于 2019-11-26 01:44:11
问题 I have the following code in test.js which is run right before </body>: alert(\'stovetop\'); alert(greasy); I have the following code in test.user.js : (function () { \'use strict\'; var greasy = \'greasy variable\'; document.title = \'greasy title\'; }()); \'stovetop\' gets alerted so I know the page javascript works, and document.title gets changes so I know that the script javascript works. However, on the webpage I get the error: Error: ReferenceError: greasy is not defined Source File: