Userscripts Support

Boo Berry

Moderator + Beta Tester
Moderator
Right, so with userscripts being on the way to being supported, I've come up with a sample script that forces YouTube to use HTTPS instead of HTTP...

Code:
// ==UserScript== 
// @name        YouTube HTTPS 
// @version     2.0
// @author		A Test Script
// @description	Forces HTTPS on YouTube
// @include		http*://*.youtube.com/*
// @grant		GM_xmlhttpRequest
// @grant		GM_addStyle
// @browsers	chrome.exe;firefox.exe
// @run-at		document-start
// @priority	9001
// ==/UserScript== 
  
// Redirects you from HTTP to HTTPS 
if (location.href.match(/http:/) ){ 
    var newUrl = location.href.replace("http://","https://"); 
      
    if(top.location==location.href){ 
        window.location.href = newUrl; 
        window.navigate(newUrl); 
        self.location=newUrl; 
        top.location=newUrl; 
    } 
} 
  
if (location.href.match(/redirect\?q=/) ){ 
    function redirectThrough(){ 
        top.location = $('#baseDiv p').eq(0).children('a').eq(0).html(); 
    } 
      
    doJQuery(redirectThrough); 
}
As you can see, a basic userscript. However, I've added a custom tag @browsers that specifies the processes that should use this userscript separated by a semicolon. I'm thinking when userscripts are fully supported, a UI feature will be needed to edit/customize the userscript, especially for specifying browsers against the browsers list in Adguard. :p

Also the assistant would probably have to intercept user.js files on websites to install them (even if the assistant is hidden/not shown) or some type of custom function for that.
 
Last edited by a moderator:

avatar

Administrator
Staff member
Administrator
We were thinking about @browsers tag too, it is important in our case.

What for intercepting .user.js files -- maybe. First interface will be as simple as possible:)
 

Boo Berry

Moderator + Beta Tester
Moderator
What for intercepting .user.js files -- maybe. First interface will be as simple as possible:)
As long as you can toggle scripts on and off, along with some way to edit scripts (or what GM does, add a default program to edit scripts like Notepad) I'll be fine with that. :) The browser tag might need a UI function to add/remove browsers that are available in Adguard (enabled browsers) to the script though.
 

halcyonboy

New Member
Hi there,

So i've been happily using this method to get Youtube Center running within IE now for the last month or so, using IE11. But now in the last week or so for some reason its just stopped working completely. I can't seem to see the script in any of the other browsers i have running either, as if the script is no longer being injected. This is quite frustrating as it was running perfectly, and now isn't. Can anyone offer any insight into this? Why would the filter injection just stop working?
 

Boo Berry

Moderator + Beta Tester
Moderator
Yeah, the injected was changed in 5.8 in preparation of supporting userscripts officially in a future version. Avatar, is it still possible to inject the userscript in 5.8?
 
Last edited by a moderator:

avatar

Administrator
Staff member
Administrator
Yeah, the injected was changed in 5.8 in preparation of supporting userscripts officially in a future version. Avatar, is it still possible to inject the userscript in 5.8?
Adguard now supports javascript-injection rules out of the box (#%# prefix rules).

Youtube control center rule:
Code:
youtube.com#%#window.addEventListener('DOMContentLoaded', function() { var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("src", "https://userscripts.org/scripts/source/114002.user.js"); var p = (document.body || document.head || document.documentElement); p.appendChild(script); }, false);
Beta-version with full userscripts support coming soon (week or two).
 

Boo Berry

Moderator + Beta Tester
Moderator
Nice! I notice there's a delay before the script kicks in, I assume this won't be an 'issue' with the official support? A week or two? Man, you guys are quick!
 

avatar

Administrator
Staff member
Administrator
Nice! I notice there's a delay before the script kicks in, I assume this won't be an 'issue' with the official support? A week or two? Man, you guys are quick!
Unfortunately we are not so quick :)

Looks like we need one more week to prepare beta-version.
 

Boo Berry

Moderator + Beta Tester
Moderator
To anyone curious about the status of userscripts support, it's in the 5.9 beta currently being tested by us beta testers. It works near-perfectly too! But keep in mind there may be some scripts that won't work in Internet Explorer. Fortunately YouTube Center works for all browsers I've tried thus far!

You guys will love 5.9 when it's released! ;)
 

Boo Berry

Moderator + Beta Tester
Moderator
Is there a list of what Greasemonkey functions Adguard supports?

I might one found one more Greasemonkey function that Adguard may have to eventually support; the GM_registerMenuCommand (aka User Script Commands menu items) function to add support for custom dialogs/options/menu items for specific running user scripts. An example of this being needed is the YousableTubeFix userscript - you can't customize or change the scripts settings without support for this.

Maybe a Script Settings button can be added to the Assistant (or perhaps a custom script button) to invoke said options/menus?

Also, I'm beginning to see the need to specify which browser(s) can use user scripts (extensions) and which ones shouldn't.

Thoughts?
 
Last edited by a moderator:

avatar

Administrator
Staff member
Administrator
Is there a list of what Greasemonkey functions Adguard supports?

I might one found one more Greasemonkey function that Adguard may have to eventually support; the GM_registerMenuCommand (aka User Script Commands menu items) function to add support for custom dialogs/options/menu items for specific running user scripts. An example of this being needed is the YousableTubeFix userscript - you can't customize or change the scripts settings without support for this.

Maybe a Script Settings button can be added to the Assistant (or perhaps a custom script button) to invoke said options/menus?

Also, I'm beginning to see the need to specify which browser(s) can use user scripts (extensions) and which ones shouldn't.

Thoughts?
I should find some time to write documentation:)

The list of the functions supported:
GM_setValue
GM_getValue
GM_getResourceText
GM_getResourceURL
GM_xmlhttpRequest
GM_addStyle
GM_log (just a safe version of console.log)

GM_registerMenuCommand is an empty function for now.

What for the browsers support tag. We will definitely add it in Adguard 6.
 

GunGunGun

New Member
Hi avatar, do you think you can emulate GM_CopyToClipboard with ZeroClipboard, ZeroClipboard uses flash to change clipboard, if browser turn off click to play then I click possible, right ?
 

avatar

Administrator
Staff member
Administrator
Hi avatar, do you think you can emulate GM_CopyToClipboard with ZeroClipboard, ZeroClipboard uses flash to change clipboard, if browser turn off click to play then I click possible, right ?
Not sure, ZeroClipboard is rather "heavy" library.

What do you think about this implementation:
Code:
function GM_CopyToClipboard(text) {
  window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
It's ugly but it works:)
 

avatar

Administrator
Staff member
Administrator
Your method seem really nice, and after some tries with ZeroClipboard I think it will not work, that is sad :(
I've added a task for devs to add support for GM_CopyToClipboard.
We'll do it in the patch planned for 5.10.
 
Top