开发者

An extremely simple Greasemonkey re-direct script, wondering if there's a better way

I prefer the look and feel of Firefox 2, but Youtube doesn't. None of the Greasemonkey scripts I use w开发者_如何学Goill work there unless I click "return to the original page" (Youtube places me on a light-weight version due to my out-of-date browser). The only difference between the pages that I could spot was a &nofeather=True at the end of the "original" url. So I decided to try and write a Greasemonkey script that would automatically re-direct me. As you can see below, I know (more or less) nothing about writing one... and though my current solution works, I've been wondering if there's a better way of doing it.

// ==UserScript==  
// @name           Youtube Redirect  
// @namespace      ??  
// @include        http://www.youtube.com/watch?v*  
// @exclude        http://www.youtube.com/watch?v*&nofeather=True  
// ==/UserScript==

(function(){  
window.location.href = window.location.href + "&nofeather=True";  
})();

Any tips would be appreciated, and thanks for your time.


I would do window.location.replace(newURLHere) so that your back button still works.


Your current script should be fine, for what it does.

Although you don't need the function wrapping, so you can change:

(function(){  
window.location.href = window.location.href + "&nofeather=True";  
})();

To:

window.location.href = window.location.href + "&nofeather=True";  

Or, per Eric's answer:

window.location.replace (window.location.href + "&nofeather=True");

-- which prevents an extra, probably undesired, page from being added to the history.


Note that all of this works on modern versions of FF and GM. (Probably works on the obsolete versions, too; but I might have forgotten some old bug in that older stuff.)


However, using GM for redirects is not best, because most of the page has to load before GM fires. So, you are loading pages twice every time! (Not counting some images.)

A better approach would be to use an extension specifically designed for redirecting. You'll get a snappier response.

Redirector is a fine add-on. But it requires you to have an up-to-date version of Firefox -- which you should do anyway! (unless you like your machine secretely sending out spam without your knowledge? :) )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜