3

I wanted to create a search add-on to right click and search tag text into Wikipedia/ but when i apply this code it only shows the option in context menu but nothing happens//

i don't know where the error is....

i was planning on right clicking it and making it search different words from the same page thispage and get results in a new tab... //

My code:

exports.main = function() {

var contextMenu = require("context-menu");
var tabs = require("tabs");
var Request = require('request');

var menuItem = contextMenu.Item({
    label: "Start Search",
    context: contextMenu.PageContext(),
    contentScript: 'self.on("click", function() {'+
                        'var text = window.getElementsByTagName(\"td\").toString();'+
                        'self.postMessage(text);'+
                        '});',
    onMessage: function(text) {
                    tabs.open("http://en.wikipedia.org/wiki/Special:Search="+text)
                }
    }) ;

}

Debby Dale
  • 65
  • 1
  • 5

2 Answers2

0

test this:

exports.main = function() {

    var contextMenu = require("context-menu");
    var tabs = require("tabs");     

    var menuItem = contextMenu.Item({
        label: "Start Search",
        context: contextMenu.PageContext(),
        contentScript: 'self.on("click", function() {'+
        'var elements=document.getElementsByTagName("td");' +
                "for(i=0;i<elements.length;i++) { " +
                "self.postMessage(elements);"+
                            "});",
        onMessage: function(elements) {
                        tabs.open("http://en.wikipedia.org/wiki/Special:Search"+elements);
                    }                        
        }) ;

    };
mgraph
  • 15,238
  • 4
  • 41
  • 75
  • thanks/ do you know where to enter the setInterval() so that i can make it loop.or something like setTimeout() – Debby Dale Jan 02 '12 at 20:15
0

I have found the following error in your script,

'var elements=document.getElementsByTagName('td'); " +

should be

'var elements=document.getElementsByTagName(\'td\'); " +
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187