The little adverts that appear on the bottom of YouTube clips irritate me. I never actually look at them for more time than is required to hit the X at the top right corner, so I wrote this script to do it automatically.
It's a very simple script, but I searched the forum and couldn't find that anybody else had posted one to do the job, so maybe you'll like it. It seems to work every time, though it may need a bit of massaging to work on your PC. I'll tell you what to do. If you leave the ad on screen for a period, it remains there, but goes dim. This script doesn't recognise the dimmed version, but it doesn't need to, as it deals with the ad within half a second - long before it goes dim.
I run an AHK script all the time, so I just added this to the bottom of that script, so I can start it with a hotkey.
SetTitleMatchMode 2 ; this is set for the entire script file ; Other code and utilities inserted here #u:: ; get rid of adverts on Youtube ifwinactive, YouTube Settimer, ScanTime, 500 Return ScanTime: ; Runs every half-second { ifWinNotActive, YouTube { Settimer, ScanTime, off SoundBeep ; beeps twice to let you know the script is exiting Sleep 200 SoundBeep Return } ImageSearch, AdButtonX, AdButtonY, 450, 500, 830, 650, C:\Pix\AdCross.bmp if(ErrorLevel = 0) { AdButtonX += 6 AdButtonY += 8 MouseGetPos, AdX, AdY ; Read the mouse position Click %AdButtonX%, %AdButtonY% MouseMove %AdX%, %AdY% ; Put the mouse back where it was } Return }
As you see, there's not much to it.
When #u is pressed, it checks that YouTube is active, then starts routine ScanTime, which runs twice per second.
The routine checks that Youtube is active, and exits if it is not, it exits with a "Beep...Beep" to let you know it's closing.
If YouTube is up, the routine scans the bit of the screen where the advert appears. The object of the scan is an image, on my disk at ...
C:\Pix\AdCross.bmp
On my screen, the area scanned is from top-left ( 450, 500 ) to bottom right ( 830, 650 ). This is something you may have to change, depending on your screen display.
The image that it is searching for is the picture of the "X" that appears at the top right of the advert. If it finds it, it moves the mouse to the middle of the cross and clicks it.
I'm sorry, Folks, I don't know how to attach the image file, so you'll have to make it yourselves. It's easy peasy!
Display YouTube and wait for the advert to come up. Hit the PrtSc key.
Bring up MS Paint
Past the screen image into Paint. Hit Esc to get rid of the selection.
Magnify the cross several times - to the maximum is good.
Hit the Select tool and make a selection box around the cross.
Warning: The cross has a dark surround, which you don't want, as that part is semi-transparent, and may be a different colour on your screen. All you want is the cross itself, with a one-pixel, light coloured surround. The interior of the cross is colour=0x7F7F7F, and the surround is colour=0xDFDFDF. You don't want anyrthing outside of that.
When you have selected only the required part, hit Ctrl-C to copy it.
Exit Paint, and don't bother to save it.
Start Paint again.
The screen is white, but it is way too big. Move to the extreme bottom right corner of the white screen (you may have to use the scroll bars) and click on the resize button, and drag it to the top left corner, so that the white screen is only about a pixel big.
Now paste the image of the cross (which is being held in scratchpad).
Save the image as a .bmp file. In my case, I saved it to
c:\Pix\AdCross.bmp
If you save it somewhere else, change the path in the script.
As a guide, my file contains 450 bytes.
That's it - if you made the image right, it should work OK.
When you go onto YouTube, press #u, and the script will exit when you exit YouTube.
I apologise if this is a bit like sucking eggs, but I wanted it to be understandable by newbies as well as the geniuses that inhabit this site.