admin管理员组文章数量:1431799
When viewing a torrent page, the title of the tab is:
Bitsoup The Best site for your Torrent appetite :: Details for torrent "ABC"
where "ABC" is the name of the torrent file.
Unfortunately, when I have 3+ tabs open, I can not see what the name of the torrent file is.
I am attempting to create a Greasemonkey script to truncate, or split, the title, so that it only displays the torrent-name, and not the beginning part.
I am aware that you can modify the title associated with a page by using document.title = ...
but I am unsure of what to assign it to.
When viewing a torrent page, the title of the tab is:
Bitsoup The Best site for your Torrent appetite :: Details for torrent "ABC"
where "ABC" is the name of the torrent file.
Unfortunately, when I have 3+ tabs open, I can not see what the name of the torrent file is.
I am attempting to create a Greasemonkey script to truncate, or split, the title, so that it only displays the torrent-name, and not the beginning part.
I am aware that you can modify the title associated with a page by using document.title = ...
but I am unsure of what to assign it to.
Share Improve this question edited Jun 28, 2012 at 21:38 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Jun 28, 2012 at 21:18 John SmithJohn Smith 892 gold badges3 silver badges9 bronze badges 1-
4
document.title = document.title.substr(76);
? If it's off by one or two just modify the number, this just fetches everything after the specified character index. – TheZ Commented Jun 28, 2012 at 21:22
2 Answers
Reset to default 4You could use a regular expression, perhaps:
document.title = document.title.match(/"([^"]+)"/)[1]
This regex uses grouping to matches the first thing that is between quotes, and assigns it to the title
(without the quotes).
Using a substr method is by far the simplest if you know that the beginning of the title will always be identical. For example, with the title you gave:
document.title = document.title.substr(76);
If it is not a static title, then RegEx would be the next most logical route. To match the last set of quotes and ignore potential whitespace:
document.title = document.title.match(/"([^"]+)"\s*$/)[1];
本文标签: greasemonkeyHow can I modify the title of a site using JavaScriptStack Overflow
版权声明:本文标题:greasemonkey - How can I modify the title of a site using JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745577323a2664411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论