I use a Userscript to change certain features of YouTube and I'm trying to block the "select all" in thetext field
share link, where it puts the video address:
the reason is that i don't need it https://
and i do that copy/paste often
The text field only appears in the DOM after clicking the button Share. I have managed to remove the property focus
with the script below, but the "select all" is still active:
// Botón "Share"
$('button[data-trigger-for="action-panel-share"]').on('click', function() {
window.setTimeout (function(){
// Input field con la URL - no hay onclick, pero por si acaso
$("input[name=share_url]").prop('onclick',null).prop('focus',null);
},300);
});
I've tried looking for share_url
it in the Firefox JavaScript Debugger but I haven't found the property that I need to remove to get the desired behavior...
As a workaround, I just tried to replace the content of the input
, but it automatically returns to its original value (!!!).
var nueva_url = $("input[name=share_url]").val();
nueva_url = nueva_url.replace('https://','');
$("input[name=share_url]").val(nueva_url);
PS: The YT page does not come with jQuery by default, but for testing it is possible to inject it through the console using the following script :
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = "//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
head.appendChild(script);
You can counter it with a
off
.You could automate that process without needing to worry about the events of the text box containing the URL (and even without worrying about the field because the short URL can also be found in a tag
link
withrel="shortlink"
).Aside from the option to use a
prompt
that you mention in the comment, you could also use the JavaScript clipboard API if you're using a modern browser (Chrome 42+, IE10+, Firefox 41+, Opera 29+, but not Safari) how specified in this other question .The code in jQuery would be simple:
Or alternatively without jQuery:
Now, you no longer have to worry about the different events associated with the text box, and you achieve the same goal with just one click.