Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to have Firefox add-on which recognizes a website page and automatically redirects to link in the page identified its XPath.

Once example where it will be useful is the news aggregator sites like DZone. Whenever I click a DZone RSS feed's link it goes the DZone website and only after clicking the link it jumps to the actual blog/news page. I want to automatically jump to the actual content/blog/news page when I land the DZone site.

Let me know if there such an add-on available for Firefox.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Sounds it would be easy to create Greasemonkey userscript to do so.

Greasemonkey scripts are launched only on URLs matching the expreession you provide (so you can write sth like "http://dzone.com/*), and they are executed once page is loaded (top be more more detailed: when DOMContentLoaded event fires).

Writing a script should be easy with just plain JavaScript and XPath. You need to read some value by XPath like you say, and then to do the redirect, set window.location = ....

If I understood you correctly, you can use the following code - works for me in Firefox 7.0.1 / Greasemonkey 0.9.11

// ==UserScript==
// @name           Dzone Automatic Redirect
// @namespace      userscript_dzone
// @include        http://www.dzone.com/links/rss/*
// ==/UserScript==

   var XPathTools = 
   {
      getElementByXpath : function(xpath, referenceNode)
      {
         var xPathResult = document.evaluate (xpath, referenceNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
         return xPathResult.singleNodeValue;
      }
   };

   var xpath = "//div[@id='linkDetails']//div[@class='ldTitle']/a";
   var url = XPathTools.getElementByXpath(xpath,document);
   window.location = url;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.