mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2015
Posts: 2
Z
zotexa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Z
Joined: Nov 2015
Posts: 2
Hey guys, I don't have much experience with mIRC scripting and so forth but I've been messing around and tweaking random scripts for an IRC channel me and some friends use.

Long story short, is there a way to grab the URL of the background image of a web page via mIRC scripts only? I was going to use a javascript one but js4mirc crashed mIRC so I don't think I'll be running that :p

Essentially the script I want is that when people type a certain command (in this case it'll be !m) it'll grab the background image of the website (which changes on every load) and post it into the channel.

We already had a script for it but the website we were using to get the images went down and the creator of the bot is inactive so I've been trying to recreate it myself to no avail. Any help is greatly appreciated!

Joined: May 2015
Posts: 133
K
Vogon poet
Offline
Vogon poet
K
Joined: May 2015
Posts: 133
This can be achieved using sockets, there is a fantastic tutorial here: http://mircscripting.info/forum/viewtopic.php?t=83&sid=8bca8f0c879dd35d0eb3bda8adbc3f00

Once you figure that out, you can output the url of the image to chat.


twitter @keyeslol
Joined: Nov 2015
Posts: 2
Z
zotexa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Z
Joined: Nov 2015
Posts: 2
That definitely seems like what I'd need but how would I configure it to grab only the background image? I don't want to grab the whole page, just the background image which isn't hosted on the site.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
By the way, js4mIRC wouldn't have helped you because it doesn't have any support for DOM access or making web requests. Sockets is the right approach. You want to make a web request for the page and, based on how the page is structured, either pull it from the associated CSS file or directly from HTML.

If you're programming this for a specific website, you may be able to shortcircuit a lot of those requests by making assumptions about where that background image URL is being stored (which CSS file, for instance). But if you're trying to make a generic function that can pull a background image from ANY website, note that this is actually not a trivial task and requires being able to parse the entire DOM, CSS, and in some cases, evaluate JavaScript. In other words, you need a full browser.

Note that someone may come in here and lend you a COM ($com) script to do this more easily, as $com() allows you to run an IE browser and pull information from the DOM. This is the foundation of SReject's JSON script, so if you are knowledgeable with COM / JS, you may want to look at that approach.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
To clearify; my JSON script does not create an instance of an IE browser, nor create instances of the DOM or similar. It uses wscript.exe to access window's jscript engine, and various native libraries for making web requests when necessary.
--

As far as COM+DOM, this is QUITE difficult to do without creating a full instance of IE and then only limited information is available. I've tried a few times to make an html parser using an IE browser instance and there's roadblocks all along the way.


I am SReject
My Stuff
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I was referring to the foundation of using IE's COM objects. I think in my last attempt at this, it wasn't overly difficult. The "InternetExplorer.Application" object has a Navigate() method, at which point you should be able to access the Document property. You might have trouble hiding the window (I forget if it requires a visible window) but there are other ways to workaround that part.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard