Recent posts by Adrian
|
May 17, 2007
|
Topic: Script development / Conversion to Creammonkey? Unfortunately that script makes use of GM_xmlhttpRequest, which is not available in Creammonkey. I guess it could be possible to rewrite it to use a real xmlhttp object, but that's more work than I am willing to do at the moment... |
|
May 5, 2007
|
Topic: Script development / Scripts and Explorer Although trixie claims to be Greasemonkey for IE, due to IE's odd [lack of] javascript support and poor DOM implementation, most scripts will not work properly unless the author designs them to be compatible. So, unfortunately, most of the best scripts don't work. Besides, it's more likely just a nasty security hole waiting to destroy your computer. |
|
May 3, 2007
|
Topic: Userscripts.org discussion / Safari overflow issue Just started browsing this forum using Safari, and I noticed the css overflow rule in the <pre> tags don't seem to be working. A little research tells me that Safari and Opera do not support the overflow-x property. Instead, you should use the following:
overflow:auto; overflow-x:auto; overflow-y:visible; |
|
May 3, 2007
|
Topic: Ideas and script requests / Inline Flash Mp3 Player All you would have to do is change it so it loads the player onclick. You can do this by stripping out the load code and put it into a separate function. Example:
And that's it! |
|
Apr 30, 2007
|
Topic: Script development / For MySpace-ers For all those of you on MySpace who have used one of the Add Image Links scripts, the newest version of MySpace - Add Image Links 2 is on its way out! In fact, it's already in Release Candidacy and I need people to test it to make sure it looks and works properly. You can download it and help me out by giving feedback. (Make sure you disable the old version first before installing.) This version has a customizable interface available via a GUI popup window, and the full documentation is included. To get to the Preferences dialog, right-click on the monkey in the statusbar and choose User Script Commands -> Edit Image Links. There are lots of cool new features like Smart Links and Quick Links, be sure to check out them all and give whatever feedback you think of. |
|
Apr 27, 2007
|
Topic: The Banana Bar / How to make a script? Just download a simple script from this site that you like and play around with it until it does something cool. Hopefully you know at least a little bit of JavaScript, but there are plenty of websites out there that will teach you how, just google it! A good reference website out there is Mozilla's Core JavaScript 1.5 Reference in case you need to know more specifics about global functions or object methods. A good place for reading about GM-specific things, check out Dive Into Greasemonkey and the Greasemonkey wiki. |
|
Apr 27, 2007
|
Topic: Script development / eBay Snipe Script Do you have a DateAdd function in your script? If so, I'm assuming you're using something similar to this:
function DateAdd(timeU,byMany,dateObj) {
var millisecond=1;
var second=millisecond*1000;
var minute=second*60;
var hour=minute*60;
var day=hour*24;
var year=day*365;
var newDate;
var dVal=dateObj.valueOf();
switch(timeU) {
case "ms": newDate=new Date(dVal+millisecond*byMany); break;
case "s": newDate=new Date(dVal+second*byMany); break;
case "mi": newDate=new Date(dVal+minute*byMany); break;
case "h": newDate=new Date(dVal+hour*byMany); break;
case "d": newDate=new Date(dVal+day*byMany); break;
case "y": newDate=new Date(dVal+year*byMany); break;
}
return newDate;
}
In which case, you would want to set the date like so:
var date = DateAdd('d', 1, new Date());
Otherwise, just use: var date = new Date(new Date() + 24*60*60*1000); |
|
Apr 24, 2007
|
Topic: Script development / eBay Snipe Script One thing you could do is include the esteal.com page in your script and perform a check for it near the top which would automatically log you in if you're not already. How to store the username/password, on the other hand, is a different matter altogether. But at least you can read the cookies since the script is working on esteal.com. Also, you should change your ebay include line.
// @include http://cgi.ebay.* to // @include http://cgi.ebay.tld/* This prevents the script from being run on potentially malicious sites such as http://cgi.ebay.h4x0r.stealzurpws.info/.
The tld is a shorthand to mean any top-level domain, such as .com, .net, or .co.uk.
|
|
Apr 24, 2007
|
Topic: Ideas and script requests / Explorer-like folder browsing Perhaps you want something like the Firefly extension? |
|
Apr 24, 2007
|
Topic: Ideas and script requests / YouTube pause/play From my experience, Greasemonkey isn't very good at working with embedded objects such as flash. My suggestion here is to just send this request to YouTube. |
|
Apr 24, 2007
|
Topic: Script development / eBay Snipe Script You can't get cookies for a different site than the one the script is running on. But even so, wouldn't it be a really bad thing to have your password stored in a plaintext cookie? You may as well just write them into your script... P.S. you should surround code in <pre> tags to prevent all those formatting problems |
|
Apr 23, 2007
|
Topic: Script development / Working with .aspx generated pages It really doesn't matter which path you choose, since xpath utilizes the DOM to find nodes. The difference is, xpath is rather a programming-ish language all in its own, while more complicated to learn it takes a lot fewer lines of code to use. So whether you want to learn both xpath and javascript, or just slightly more javascript is really the question here. The only downside to using xpath is that it would only work on firefox and not other browsers (at this time). |
|
Apr 10, 2007
|
Topic: Script development / newbie redirect link-help needed Yes, you can. Try the following code:
$x("//a[img[contains(@src, '/thumbs/')]]").forEach(function(a) {
a.href = a.href.replace("/thumbs/", "/");
});
This code uses $x from the Standard Function Library.
|
|
Apr 9, 2007
|
Topic: Script development / Playing sound? It's an XPCNativeWrapper issue. You're trying to set a property ("removed") on an embed object. Try this instead:
Note that I also used innerHTML to create the embed because I think there's an issue regarding javascript access to embed tags as well. |
|
Apr 9, 2007
|
Topic: Ideas and script requests / POSTing with GM_xmlhttpRequest You can definitely do a POST request with GM_xmlhttpRequest. Here's an example:
Note the "Content-type" header and the data field. This example should turn the URL above into a POST instead of a GET. |
|
Apr 4, 2007
|
Topic: Script development / Returning a Value from GM_xmlhttpRequest The problem is, GM_xmlhttpRequest's onload function has a delay. It actually executes after the script's code finishes, so there is no way to return the value to the main script, it all has to be done in the onload function. I would suggest you check out this useful snippet I posted on the forums a little while back for handling variables, but you'll probably have to redesign your code so it works in a forward flow instead of back and forth flows using return values. |
|
Apr 4, 2007
|
Topic: Ideas and script requests / MAKE THIS FOR MYSPACE!!! This script, while it would be awesome, would definitely not be easy to do with a user script. The script would have to search all the comments on myspace to find all the ones they've posted. It would probably be easier to run it as a server-side script that stores the comments in a database. But if anyone is up to the task, all one would have to do is scan the user's friends for comments they've posted on their profiles. And this wouldn't work for private profiles, either... |
|
Mar 29, 2007
|
Topic: Userscripts.org discussion / Formatting for descriptions etc? HTML? Markdown? BBCode? The way it's set up now is fairly good. All you really have to escape when writing HTML code is < to < and & to &. After your first post with HTML, you'll learn how it works... Which is why we have a handy edit button on all our posts :) But, one thing you could do is escape HTML code only if it's inside a |
|
Mar 29, 2007
|
Topic: Script development / For anybody having scope issues with GM_xmlhttpRequest Johan, that solution is wonderful, as I did notice the potential conflict involving event listeners with my method. That way should work quite well under most circumstances. |
|
Mar 28, 2007
|
Topic: Script development / For anybody having scope issues with GM_xmlhttpRequest I'm sure quite a few of us have come across the issue of not being able to easily pass variables to time-delayed functions, such as GM_xmlhttpRequest or setTimeout. Especially if these functions are run inside of a recurring function, or inside a loop. So I've created an object class you can use with these functions:
function Scope(o) {
var scope = this;
for (a in o)
this[a] = o[a];
this.callback = function(r) {scope.func.call(scope, r);};
}
This simple class saved me from a lot of headaches with incorrect values. To use it, simply follow the example below:
// you may use as many variables as you'd like, but `func' MUST be set to your callback function
var scope = new Scope({myVar:some_variable, func:myCallback});
GM_xmlhttpRequest({
method:'GET',
url:'http://www.somewhere.com/something.xml',
onload:scope.callback
});
function myCallback(request) {
alert(this.myVar); // variables from the Scope object are now found in the `this' object
...
}
This works because the variables are copied to the object, thus retaining their current values. And the object will never lose scope as long as the callback function is referenced by the GM_xmlhttpRequest handler. Enjoy! |
|
Mar 28, 2007
|
Topic: Script development / Optimize? Your script seems fairly optimized. The only thing I would recommend you change is where you copy the innerHTML of the home_infobar only to re-generate it later. It seems like all you're doing is moving it somewhere else, so it would be much faster (and easier) to do this instead:
thisElement = document.getElementById("home_infoBar")
// (line removed) // tempHTML = thisElement.innerHTML; //save the homeinfo bar so we can re-generate it
thisElement.parentNode.removeChild(thisElement); //delete it from the top
// thisElement still exists at this point, but it is not attached to the DOM tree
// (line removed) // var tempDiv = document.createElement("div");
// (line removed) // tempDiv.innerHTML = '<div id="home_infoBar" class="section">' + tempHTML
// then re-attach thisElement instead of tempDiv
As far as the difference between elem.style.display = 'none'; and elem.parentNode.removeChild(elem);, it's really a matter of preference. The former causes the element to simply not display on the page, whereas the latter actually removes it from the DOM tree. If you choose the style method, if you (or another scripter) wanted to, they could re-display the element.
|
|
Mar 27, 2007
|
Topic: Script development / Replacing an image with a different image Just change the SRC attribute: elem.src = "http://somwhere.com/new-image.jpg"; As for finding it, just go through all the images on a page until you find the one that matches: var images = document.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
var elem = images[i];
if (elem.src == "http://somwhere.com/old-image.jpg")
elem.src = "http://somwhere.com/new-image.jpg";
}
|
|
Mar 26, 2007
|
Topic: Script development / Removing images after "__________________" string Whoops, I wonder how that got in there. *blush* |
|
Mar 26, 2007
|
Topic: Script development / How to read onclick events? Well, first of all, your example didn't come out right. Try to enclose it in <pre> tags, and escape the <'s with <. If your event is assigned via var onclick = elem.getAttribute("onclick");
elem.href = 'javascript: ' + onclick;
Hope this helps. |
|
Mar 25, 2007
|
Topic: Script development / Removing images after "__________________" string Well, for that piece of HTML, try the following code:var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
if (divs[i].textContent && divs[i].firstChild && divs[i].firstChild.nodeType == 3 && divs[i].firstChild.data.indexOf('__________________') != -1) {
var images = divs[i].getElementsByTagName("img");
for (var j = 0; j < images.length; j++) {
images[j].style['display'] = 'none';
// images[j].nextChild.style['display'] = 'none'; // uncomment to remove the <br /> tags
}
}
}
But if the text before the images ever changes, that code will stop working...It's a lot harder to find comment nodes in the DOM tree, but they are preserved there if you wanted to try and find them. Just look for a node with a nodeType of 8. EDIT: Fixed the code so it works, as per below, for future reference. |
