I want to write a js code which will un-translate video names
It is copied from title to video block name, but without 10 last chars(without "- YouTube").
And when I try this code (I know that code must be inline but it's for greater review)
javascript:var tttl = document.createElement('script');
document.getElementsByTagName("body")[0].appendChild(tttl);
tttl.innerText = "document.getElementsByClassName(\"style-scope ytd-video-primary-info-renderer\")[5].innerText = document.title.slice(0,-10);";
In browser console it works, but with bookmark (add bookmark and in address paste my code) it isn't working correctly.
Based on your question, it seems like you want to execute a javascript code while browsing youtube.com.
For doing so you need to wrap your code inside a self-executing function.
javascript:(function(){var tttl = document.createElement('script');
document.getElementsByTagName("body")[0].appendChild(tttl);
tttl.innerText = "document.getElementsByClassName(\"style-scope ytd-video-primary-info-renderer\")[5].innerText = document.title.slice(0,-10);";})();
Edit 1:
The reason why this code is wrapped inside a self-executing function is that it defines the scope for the executing code and doesn't try to write on DOM with the return value of the last statement.
Example code for better understanding:
javascript:var name;name="Ashish";
As the statement name="Ashish" returns a value in javascript this will be printed on the browser if executed through address bar. Same is the case with the last statement in your code.