Userscripts Support

Discussion in 'Feature Requests (Adguard for Windows)' started by Boo Berry, Jul 16, 2013.

  1. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    I decided to split this request from my original post requesting userscripts support so I could elaborate a bit about this, and weigh the pros and cons. To me, userscripts go hand-in-hand with adblocking capabilities so it makes sense to me. So at any rate, any userscripts support should include the following;

    - All GM_ functions supported by Greasemonkey/Scriptish/Tampermonkey/Violentmonkey/etc.
    - Full unsafeWindow access for Chrome, Chromium, Opera, etc.
    - Tags supported by Greasemonkey (including @include, @match, @name, @exclude, @domain, etc.).
    - Custom tag to specify browser you want a specific userscript to work with (@browsers) setup like @browsers firefox, chrome, opera, ie in addition to a all option to work for all browsers. If there's no @browsers tag present, default to all.
    - Auto-update of userscripts with customizable variables (check every 12 hours, every day, every 2 days, every week, etc.)
    - Store userscripts in a directory that can be edited by global users with the option of per-user settings.
    - Ability to edit/modify existing userscripts with either an interface or a setting to setup a default external editor like Notepad or Notepad++.
    - Reload scripts button to reload scripts if you've been editing them.
    - Ability to write new userscripts with a default template in place.
    - Some kind of intercept for installing userscripts (user.js files) within every browser.
    - Perhaps some type of addition to the Assistant to toggle userscript(s) on a page/domain/etc.
    - A "scripts for this site" feature to the Assistant to search userscripts.org for scripts for the domain you're on at that moment.

    Now, those basic settings would give desirable userscript functionality. There is one more request to userscripts support which would be nice at some point, but isn't exactly needed to get userscripts to work;

    - Userstyles (Stylish) support for Firefox and Chrome. Of course, this would require perhaps the custom @browsers tag to specify the browser you want the userstyle(s) to work for. Fortunately, you can install *most* userstyles as userscripts so this isn't badly needed as long as that continues.

    It's quite a list, isn't it? I want to weigh the pros and cons of this idea now.

    Pros:

    - Would provide a cross-browser setup where you wouldn't need to bother with extensions for those browsers thus bringing additional overhead to the browser itself.
    - It'd spare you the hassle of updating userscripts if you have a lot of userscripts and you use more than 3 browsers.
    - There is no actively developed cross-browser Greasemonkey-like application which can potentially be very appealing to users which provides an additional incentive to purchase a Adguard license. With SSL filtering coming and if userscripts were supported, why would anyone consider similar applications like Ad Muncher? ;)
    - This goes with the above in a way, but supporting userscripts (and SSL filtering) would give Adguard way more exposure on tech sites, perhaps like Neowin.
    - There's also no actively developed Greasemonkey-like application for Internet Explorer. There's IEPro which does work to an extent in Internet Explorer but it's a few years old and very buggy and bloated with BHO crap.
    - Would provide new features to websites (like YouTube) and allow users to customize websites to their hearts content, thus giving the user the ultimate user experience and control over their internet experience.


    Cons:

    - As of right now (haven't tried IE11 yet) userscript support is limited in Internet Explorer. This will probably change in the future (again, would need to test IE11 of its capabilities). But when using IEPro there's a good deal of userscripts that I've tested that works fine. Would need some kind of warning for IE users for this 'issue'.
    - Would require updates whenever there's new Greasemonkey GM_ functions and/or tags to add.
    - Might add more overhead to filtering/browsing, but probably won't be noticeable if you already use a Greasemonkey extension of some type.

    Thoughts? Anything I didn't cover? Anymore pros and cons to add? I'd like to get feedback on this idea, thanks. :D
     
  2. rickyoh

    rickyoh Beta Tester

    Joined:
    Feb 3, 2012
    Messages:
    564
    the one application to parse them all approach is very interesting. userscripts can be used to combat pesky advertising/web features that cannot be defeated by filtration rules alone(countdown timers come to mind). if Adguard can be able to support them natively then, as you hinted, it would be a game changer in the market. therefore i support this request. Thanks for proposing this.
     
  3. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    I have made some research on this topic and have found a workaround.

    You can emulate a user-script support with Adguard standard CSS rules. This looks ugly, but it works and we use it in our own filters.

    For example, look at this rule from spyware filter:

    Javascript code we inject is highlighted.
    This rule injects a javascript emulating Google Analytics objects. We do this because some websites need google analytics objects to work properly.

    You can use this method to inject any javascript code to the web page.

    Just one thing to remember: rule must not contain any line breaks.
     
    Last edited by a moderator: Jul 22, 2013
  4. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Ah, it might be worth porting these two simple userscripts to completely remove ads (and the ad spaces on the right side) from Outlook (Hotmail) and Yahoo! Mail (when SSL filtration support is released)...

    http://userstyles.org/styles/15137/remove-hotmail-outlook-ads-2013
    http://userstyles.org/styles/58924/yahoo-mail-remove-ads-better

    Sadly, I don't think it'll be possible porting an elaborate userscript like YouTube Center using this method. :p If we could get Ads Skipper ported, that'd take care of some of the ad redirects. :D
     
    Last edited by a moderator: Jul 22, 2013
  5. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    This is for yahoo:

    Code:
    mail.yahoo.com###adg_start_style_inject </style> <style type="text/css">#shellcontent{right:0!important} #theAd, #theMNWAd, #slot_MON, #slot_LREC, #slot_MIP, #slot_MON_sent, .darla, .ch_mod, .gxBoom, .boom, #trendmastr-main, #masSearchAd {display:none!important;visibility:hidden!important;} .panescroll #toolbar {right:0 !important;}</style> <style type="text/css"> #adg_end_style_inject
    
     
  6. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    This is for hotmail:

    Code:
    mail.live.com###adg_start_style_inject </style> <style type="text/css">#MainContent { width:100% !important; }</style> <style type="text/css"> #adg_end_style_inject
    
     
  7. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    Try this for youtube:
    Code:
    youtube.com###adg_start_script_inject </style> <script type="text/javascript" src="https://dl.dropboxusercontent.com/u/13162258/YouTube%20Center/YouTubeCenter.user.js"></script> <style type="text/css"> #adg_end_script_inject
    
    But I am not sure it will work.
     
  8. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Yahoo! Mail works, thanks! :D I can't test Outlook since it's SSL, but I'm sure it'll work fine in 5.7. :D Can YouTube Center/Ads Skipper be ported too or are they too large and complex?

    EDIT: YouTube Center works fine in Chrome, but not IE (curse you IE!). Can't you not use a local userscript file too this way for faster loading?
     
    Last edited by a moderator: Jul 22, 2013
  9. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    You can try to download script and than use a rule like this:
    Code:
    youtube.com###adg_start_script_inject </style> <script type="text/javascript" src="file:///C:/Downloads/youtube.center.user.js"></script> <style type="text/css"> #adg_end_script_inject
    
     
  10. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Doesn't work with local scripts, oh well. :p Still, with how well userscripts work with Adguard already I could alter the requests above to *better* manage them, local script support and hopefully get the YouTube one to work in IE (it works in IE + IEPro).
     
  11. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Okay, I found a better userscript to use with Yahoo! Mail. Why is it better? Because it only removes the white ad-space on the right side, like the Outlook script does - and the Easylist portion of the filter will take care of the other ad elements. Here is the link to the userscript and I've already converted it for use in Adguard...

    Code:
    mail.yahoo.com###adg_start_style_inject </style> <style type="text/css">.panescroll #shellcontent{right:0!important} .panescroll #toolbar {right:0 !important;}</style> <style type="text/css"> #adg_end_style_inject
    Can this and the Outlook code above be added to the official filters? Reason being anyone using Yahoo! Mail and/or Outlook probably doesn't want to see those right ad-spaces. :p
     
  12. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Can you guys please, please, please add support for the local file userscript loading type of thing? I ask because I've now got YouTube Center loading perfectly (even in IE) using the following...

    Code:
    youtube.com###adg_start_script_inject </style> <script type="text/javascript" src="http://userscripts.org/scripts/source/114002.user.js"></script> <style type="text/css"> #adg_end_script_inject
    However, this adds a second or so latency of loading the YouTube pages because it has to download the userscript each time. Specifying a local file in this case would mean almost instant loading.

    I'm thinking adding local file support probably won't need much coding. :p
     
  13. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    This is browser security restriction, not ours.

    I suggest you to place the script to the dropbox and use dropbox download link in our rule (just remove &dl=1 parameter from the link).
     
  14. rickyoh

    rickyoh Beta Tester

    Joined:
    Feb 3, 2012
    Messages:
    564
    not to draw out the point here, but seeing as how a major hurdle(https filtering) is almost done and dusted and as Venom has previously indicated there are some userscripts that are too elaborate to implement as css rules(an example is one i linked you to in this post ) is it possible, in your view, to be able to implement addon functionality in Adguard that is equivalent to what greasemonkey does in firefox ? i find such functionality in Adguard would be an exciting prospect and would truly give Adguard 360° of freedom when it comes to blocking ads.
     
  15. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Okay, here's a question I have (blame my curiosity) for anyone who wants to answer, why does the newer versions of the YouTube Center userscript, when using Adguard's 'injection' method, fail to work in Internet Explorer + Adguard 5.7 beta where it'll work in all other browsers?

    Link to the userscript I'm using: https://dl.dropboxusercontent.com/s/sa5atgkbw4ipy6i/YouTubeCenter.user.js
     
  16. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,077
    The problem is that this javascript is not cross-browser.

    It uses __defineGetter__ function that is supported by Google Chrome and Firefox, but not by Internet Explorer.

    Pros:
    Injecting javascript is rather easy.

    Cons:
    Existing popular userscripts are not cross-browser.
    Userscripts functionality is supported by Google Chrome out-of-the-box.

    --
    I will think about javascript plugin system for Adguard, it could be really interesting feature.
    But we should also provide a number of our own plugins bundled with Adguard (empty plugins list is not good).
     
  17. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    Bummer, but not surprising. I wonder if IE11 does? Doubtful. But I'll find out once the Windows 8.1 RTM leaks. I've reported the 'issue' to the script developer, but I doubt anything can be done without forking the script.

    Let's not sugar coat it, it's because of Internet Explorer. :p All other browsers (using Webkit/Blink/Gecko rendering engines) more-or-less support userscripts - even Safari.

    True, but as far as I know the native Chrome support isn't as good as Greasemonkey/Tampermonkey.

    A "FlashBlock" and/or "JavaBlock" type of plugin would be neat. Also a "Force HTTPS Everywhere" type of plugin too. "Ad Skipper" and/or "NoScript" plugin, anyone? :p
     
    Last edited by a moderator: Aug 26, 2013
  18. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    And it seems I might be wrong again. According to this article IE11 *may* in fact support __defineGetter__ afterall.

     
  19. rickyoh

    rickyoh Beta Tester

    Joined:
    Feb 3, 2012
    Messages:
    564
    this would be most welcome. rather than pushing css rules beyond their limits, fire(stubborn script based ads) can be fought with fire(javascript plugins) not to mention adding such functionality as has been mentioned by Venom(NoScript, Ad Skipper, etc) i hope that you will approve this system for future Adguard builds. Hopefully this system will prove to be as flexible as the greasemonkey model.
     
  20. Boo Berry

    Boo Berry Moderator + Beta Tester Moderator

    Joined:
    May 30, 2012
    Messages:
    2,508
    I just installed the Windows 8.1 Pro Preview as I wait for the RTM to leak, and I was indeed right. IE11 does support __defineGetter__ and __defineSetter__ so the userscript functions correctly. I'm actually shocked on how much Microsoft has improved IE over the last few years. It's not that bad of a browser, but I rather use Chrome/Firefox anyways. ;)

    If userscript support is added, just say IE11 is required for the best chance of it working correctly. :p

    EDIT: IE11 in 8.1 RTM does indeed support both, along with SPDY and WebGL... among other things.
     
    Last edited by a moderator: Aug 29, 2013