|
|
Hey everyone, very new to scripting, so I hope you will please pardon my ignorance :) I'm trying to remove video ads that are played before a game is loaded. The source calls adoverlay.js in the <head>, which holds the game until the ad is done playing. I made my own testvideoblock.js, which basically runs the same function as adoverlay.js, with the ad portions stripped out. Instead, it always returns the boundary case, which is to just timeout after 33 seconds and play the game no matter what (but I changed it in my testvideoblock.js file to timeout after 1 second, thus almost instantaneously.) So now heres my user script which calls testvideoblock.js var script=document.evaluate("//head//script[@src='adoverlay.js']",document,null,9,null).singleNodeValue;
if (script)
{
var script2=document.createElement("script");
script2.type="text/javascript";
script2.src="C:\\Users\\testvideoblock.js";
head.appendChild(script2);
}
Basically, what I was going for was that it searches the document in the header for the script that references adoverlay.js, and replaces it with my own js file on my computer. Heres the thing: I know I am doing something wrong. This is not only because it doesnt work (the video still plays), but I am a total newbie and I am probably making several fundamental errors. Can you not call a local js file from the browser? How could I make this script more fluid? (instead of a user.js file calling a js file, maybe put them both together so I dont always worry about deleting the local copy from C:\users\)</head> |
|
|
You can't link to local files in JavaScript [that would be dangerous! :)] also, you're not doing any replacing in there. Regardless though, replacing a <script> element will not undo the code contained in it. Rather, you have to figure out what it does, and undo it with your own code (in the script itself, or you can attach remote scripts e.g. hosted online). Alternatively, if adoverlay.js does absolutely nothing good at all, you can use AdBlock Plus to "ban" it from ever loading on your computer. Sweet, right? :-) |
|
|
I'm not sure if you can call a local js file or not. One problem I see is your xpath query. 2 slashes is a no-no.
var script=document.evaluate("//script[@src='adoverlay.js']",document,null,9,null).singleNodeValue;
Anything from the error console? Avg is right, you can't change the script because it's already been executed by the time Gm gets to it. What you can do (possibly) is change the timer variable with unsafeWindow.timer=0 or something. |
|
|
Agreed. Your approach is what is flawed, not necessarily the code (but JoeSimmons is right about the xpath). Userscripts are already locally stored JavaScript files, so you shouldn't have to call up another. Just make your userscript do what your other file is supposed to. |
|
|
Can you post the source of |
|
|
Blocking the js file with AdBlock doesnt let the game load. Thats what started me on this quest :)
Since I might as well make it more specific since it might help
Heres the original js file:
http://www.addictinggames.com/jsource/videoAdEm...
After looking more at the code I stripped out of it, I dont know how well a job I did. Heres the only part I modified from videoAdEmbed.js and made my testvideoblock.js
function writeDivAndPlayAd(dc_ref){
timeoutID = setTimeout( "playerTrouble('default timeout in writeDivAndPlayAd()')", 0 );
}
Since it calls playerTrouble, and since that calls setTimeout, and since that message automatically loads embedGameinDiv, I figured it might work (although I could strip other stuff out of there, I was going to make it work first before stripping more out)
EDIT: Now that I have looked at it, could I just make timeoutID=0 and forget about calling the function, then add in another line in the function that just says embedGameInDiv(); ? |
|
|
I think you're overthinking this. // ==UserScript== // @name Addicting Games - Remove Ad // @namespace RunningBlind // @include http://www.addictinggames.com/* // ==/UserScript== unsafeWindow.embedGameInDiv(); Only tested a few times, but it seems to work. |
|
|
Thanks running blind, that worked great. I guess I have a lot to learn :) |
|
|
I'm going to post this as my own script, and be sure to give you credit. Is that okay? |
|
|
Yea sure, you simplified it more than I ever could. Even a small name drop would be big news for me :) |
|
|
Okay. It's up. |