Is On-The-Fly string replacement possible using GreaseMonkey and Firefox

0

I have looked for means to stop Brightcove videos from autostarting in Firefox and have come to the conclusion it isn't possible without external programming via something like Grease Monkey. However, I'm not proficient in javascript let alone GM. So I thought I'd ask here first whether what I want to do is feasible, or whether it's a fool's errand.

What I want to accomplish is have a site specific script executed to replace a string value on the run in that site's code. Specifically, what I am looking for is something GM-style that would do this:

if site_domain = 'www.SiteWithAutoPlayVideos.com'
  then replace_all('<param name="autoStart"             value="true" />',
                   '<param name="autoStart"             value="false" />');

Having looked through Super User for anything GreaseMonkey that might relate, I see notices that the sandbox GM executes scripts in has to remain separate for security reasons. So, I suspect I might be in for disappointment. BUT if it is accomplishable and somebody here can confirm it, then I will do my best to struggle through the learning curve and get this noisome little problem put to rest.

Yes, I have tried Flash Block and FlashDisable in order to attack this issue with no avail.

Gary M. Mugford

Posted 2014-06-01T02:05:21.527

Reputation: 255

You can modify the DOM from a GM script. It's certainly possible, if a little unintuitive. If you want any help on actually writing the script, feel free to drop by the Root Access chatroom (or the JavaScript one on SO's chat). Otherwise, I would suggest you look into enabling Firefox's built-in plugin click-to-play functionality first, assuming it's a flash video. – Bob – 2014-06-01T02:16:49.553

Yes. Greasemonkey can do this, but it can get tricky. You'll want to use MutationObserver to catch both the <param> and maybe also its parent node. – Brock Adams – 2014-06-01T03:11:22.877

@BrockAdams If the offending node isn't added after the initial load, then it should be sufficient to remove it on the page load. However, whether that's fast enough to happen before it takes effect is questionable. – Bob – 2014-06-01T03:18:52.710

@Bob, Using MutationObserver, the <param> will be modified before the video finishes loading. If that's good enough then: (1) catch the parent too, (2) Bust the parent load (dummy URL ought to do it), (3) fix the <param>, (4) restore the parent node. – Brock Adams – 2014-06-01T03:25:13.427

@Bob - The problem with the plugin click to play is that it asks you about the site and after you affirm, never asks again. If it DID ask each time, I could live with the double-click process. Also, the site has several links on it to pages with the damnable autoplay video's. As I've said, I've tried the obvious flash blocking add-ins, including the Click to Play Per-Element. The player (Brightcove's player) is impervious to them all. – Gary M. Mugford – 2014-06-01T05:58:52.197

@BrockAdams (and Bob too), I think you've pointed me in the direction of the library. Now's the time to dig into the manual and find a working example and modify it. Knowing that MutationObserver is involved will probably be a huge leg up. Thank you both for taking the time to give me some hope ... and some work to do [G]. – Gary M. Mugford – 2014-06-01T06:02:00.957

@GaryM.Mugford If you're interested, you can use my script as an example. It uses the old (now deprecated) Mutation Events (as opposed to the new MutationObserver), but it works for its purpose. Also, if the Flash blockers don't work, it's probably not Flash. Might be a different plugin (Silverlight? VLC?) or HTML5 video (not likely if it uses param tags). Click-to-play does ask again, for me - maybe you have different settings. This is getting a bit long-winded for comments, so, again, feel free to drop into [chat].

– Bob – 2014-06-01T07:04:08.873

@Bob, thanks for your offer. I took a quick look at your script and it seems a little off-centre for my needs. That's undoubtedly because I'm starting from zero and just don't see the connection in replacing text rather than the picture objects you present. But like I say, I can't see the tree in the forest just yet. Thanks for the effort. As to Super User Chat, I'm even more lost there [G]. Ultimately, while it would be good to conquer GreaseMonkey, I'm thinking I'll pay a Javascript programmer over at Fiverr.com to write this one for me. – Gary M. Mugford – 2014-06-01T15:36:38.627

@Bob, the site in question is www.sportsnet.ca. Click any link that takes you to a new page that has a brightcove player on it and look at the page source. Right click on the playing video, if it autostarts, and you will see the Flash player menu. At least that was the case with Pale Moon, Google Chrome and IE. It's obviously a propietary player of some sort. All I want to do is turn off AutoStart. Sigh. But thanks for the encouragement and (multiple) offers to help. – Gary M. Mugford – 2014-06-01T15:42:42.373

@Bob, DID try to modify and use the script, replacing the namespace and include with www.sportsnet.ca/* and replacing the text find and replace with the two strings from my code. Enabled the script and enabled GreaseMonkey and then went to site and clicked on a link and up came the autostart player ... and it played automatically. I think I've taken up too much of everybody's time on this. Thanks Bob and Brock and sorry for having wasted your time. – Gary M. Mugford – 2014-06-01T16:03:27.883

No answers