0

I'm using a javascript rss search script as a searchable telephone/address list for work. I have it working as a Chrome popup extension on the toolbar with manifest version:1 but I can't get it to work with version:2. In version:1 the xml database file doesn't need to be named in the manifest but it seems it does in version:2 but for the life of me I can't work out where it's supposed to go. I don't want it to be uploaded to a server or anything as we just need it to work locally which it's doing fine with version:1.

I tried searching for a manifest file to copy but most answers reference the older manifest version e.g. Chrome Extension Manifest 'Matches'

I expect it's something simple that I'm missing so if someone could help it would be much appreciated.

Here's my manifest code: Revised code below:

          {
  "name": "Telephone Search",
  "version": "2.0",
  "description": "Tel Test.",

  "browser_action": {
    "default_icon": "icon.png",
    "default_title": "Addresses",
    "default_popup": "index.html"
    },
  "content_scripts": [
    {
      "matches": [
      "http://*/*",
      "file://*/*",
      "<all_urls>"
      ],
      "js": [
      "combinedTipue.js"
      ]
    }
  ],
  "permissions": [
    "tabs",
    "http://*/*",
    "file://*/*",
    "<all_urls>"
  ],
  "manifest_version": 2
 }

The xml file tipue_data.xml is in a couple of places where I've been trying to get it work!!


@ Rob W In case you meant the .js scripts I've added them below: (Sorry if they should have been put in 'comments' and not 'answers' but there was a character limit)

tipue.js combinedTipue.js

    function setFocus(){
document.getElementById("searchBox").focus();
}
// Tipue JS 4.2
//
// Tipue JS Copyright (C) 2002-2007 Tri-State Consultants
// Tipue JS is open source and released under the GNU General Public License
// Start tipue_set code
// Tipue JS 4.2
//
// Tipue JS Copyright (C) 2002-2007 Tri-State Consultants
// Tipue JS is open source and released under the GNU General Public License
//
// Tipue JS Set
// General
data = 'tipue_data.xml';
data_source = 1;
results_location = 'results.html';


// Results 


per_page = 10;
context = 1;
context_seed = 100;
descriptive_length = 25;
rank_seed = 3;
include_num = 0;
include_url = 1;
header_links = 1;
bold_query = 1;
bold_title = 1;
bold_footer = 1;


// Search


common_words = 'a about an are as at be by do for from how I in is it of on that the this to was what when where who will with';
stemming = 'javascript^js checkboxes^checkbox';
spell = 'tipu^Tipue endshet^Endsheet';


// Text


tl_1 = 'Your search - ';
tl_2 = ' - did not match any documents.<p>Suggestions:<p>Make sure all keywords are spelled correctly.<br>Try different or more general keywords.';
tl_3 = 'Previous';
tl_4 = 'Next';
tl_5 = 'to';
tl_6 = 'of';
tl_7 = 'for';
tl_8 = 'Did you mean:';
tl_9 = 'The following common words have been excluded from your search:';
tl_10 = 'Blank search.';
tl_11 = '<p>Powered by <a href="http://www.tipue.com" target="_blank">Tipue</a>';
tl_12 = 'Results';


// XML


xml_pages = 'page';
xml_title = 'title';
xml_url = 'url';
xml_content = 'content';

// End tipue_set code
tid = window.location.search;
rd = tid.indexOf('?d=');
rn = tid.indexOf('&n=');
if (rn == -1) {
    dit = tid.substring(rd + 3);
    tn = 0;
} else {
    dit = tid.substring(rd + 3, rn);
    tn = parseInt(tid.substring(rn + 3));
}
dit = dit.replace(/\+/g, ' ');
dit = decodeURIComponent(dit);

dit = dit.replace(/\s+/g, ' ');
od = dit;
hd = dit;

dit = dit.replace(/ and /gi, ' ');
dit = dit.replace(/- /gi, '-');
dit = dit.replace(/\s+/g, ' ');


nr = per_page;
r_l = results_location;
b_q = bold_query;
b_t = bold_title;
b_f = bold_footer;
ct = context;
c_s = context_seed;
seed = rank_seed;
ct_l = descriptive_length;
c_w = common_words;

tr = new Array();
co = 0;
nd = 0;
nc = 0;
sp_l = '';
cw_l = '';

if (data_source < 2) {
    s = new Array();
    if (window.ActiveXObject) {
        xmldoc = new ActiveXObject("Microsoft.XMLDOM");
        xmldoc.async = false;
        xmldoc.onreadystatechange = function () {
            if (xmldoc.readyState == 4) get_xml();
        }
        xmldoc.load(data);
    } else if (window.XMLHttpRequest) {
        client = new XMLHttpRequest();
        client.open("GET", data, false);
        client.send(null);
        xmldoc = client.responseXML;
        get_xml();
    }
}

function get_xml() {
    if (document.implementation && document.implementation.createDocument) xmldoc.normalize();
    if (data_source == 0) {
        pages = xmldoc.getElementsByTagName("item");
        for (c = 0; c < pages.length; c++) {
            rs = pages[c];
            es_0 = rs.getElementsByTagName("title")[0].firstChild.data;
            es_0 = es_0.replace(/\^|\~/g, '');
            es_1 = rs.getElementsByTagName("link")[0].firstChild.data;
            es_1 = es_1.replace(/\^|\~/g, '');
            es_2 = rs.getElementsByTagName("description")[0].firstChild.data;
            es_2 = es_2.replace(/\^|\~/g, '');
            s[c] = es_0 + '^' + es_1 + '^' + es_2 + '^0^0';
        }
    }
    if (data_source == 1) {
        pages = xmldoc.getElementsByTagName(xml_pages);
        for (c = 0; c < pages.length; c++) {
            rs = pages[c];
            es_0 = rs.getElementsByTagName(xml_title)[0].firstChild.data;
            es_0 = es_0.replace(/\^|\~/g, '');
            es_1 = rs.getElementsByTagName(xml_url)[0].firstChild.data;
            es_1 = es_1.replace(/\^|\~/g, '');
            es_2 = rs.getElementsByTagName(xml_content)[0].firstChild.data;
            es_2 = es_2.replace(/\^|\~/g, '');
            if (rs.getElementsByTagName("open").length > 0) es_3 = rs.getElementsByTagName("open")[0].firstChild.data;
            else es_3 = '0';
            if (rs.getElementsByTagName("rank").length > 0) es_4 = rs.getElementsByTagName("rank")[0].firstChild.data;
            else es_4 = '0';
            s[c] = es_0 + '^' + es_1 + '^' + es_2 + '^' + es_3 + '^' + es_4;
        }
    }
}

dit = dit.replace(/\^/g, '');
dit = dit.replace(/^\s+/, '');
dit = dit.replace(/\s+$/, '');
if (seed < 1) seed = 1;
if (seed > 9) seed = 10;

v_d = false;
if (dit == '' || dit == ' ') v_d = true;

t_m = 0;
if (dit.charAt(0) == '"' && dit.charAt(dit.length - 1) == '"') t_m = 1;

if (t_m == 0 && !v_d) {
    if (c_w.length > 0) {
        cw = c_w.split(' ');
        for (i = 0; i < cw.length; i++) {
            pat = new RegExp("\\b" + cw[i] + "\\b", 'gi');
            rn = dit.search(pat);
            if (rn != -1) {
                pat_1 = new RegExp("\\+" + cw[i] + "\\b", 'gi');
                pat_2 = new RegExp("\\-" + cw[i] + "\\b", 'gi');
                rn_1 = dit.search(pat_1);
                rn_2 = dit.search(pat_2);
                if (rn_1 == -1 && rn_2 == -1) {
                    cw_l += '<b>' + cw[i] + '</b>, ';
                    dit = dit.replace(pat, '');
                }
            }
        }
        if (cw_l.length > 0) {
            cw_l = cw_l.replace(/\s+$/, '');
            if (cw_l.charAt(cw_l.length - 1) == ',') cw_l = cw_l.substr(0, cw_l.length - 1);
            dit = dit.replace(/\s+/g, ' ');
            dit = dit.replace(/^\s+/, '');
            dit = dit.replace(/\s+$/, '');
            if (dit == '' || dit == ' ') v_d = true;
            hd = dit;
        }
    }

    if (spell.length > 0) {
        cw = spell.split(' ');
        for (i = 0; i < cw.length; i++) {
            wt = cw[i].split('^');
            pat = new RegExp("\\b" + wt[0] + "\\b", 'i');
            rn = dit.search(pat);
            if (rn != -1) {
                if (sp_l.length < 1) sp_l = dit;
                pat = new RegExp(wt[0], 'i');
                sp_l = sp_l.replace(pat, wt[1]);
            }
        }
    }

    if (stemming.length > 0) {
        cw = stemming.split(' ');
        for (i = 0; i < cw.length; i++) {
            wt = cw[i].split('^');
            pat = new RegExp("\\b" + wt[0] + "\\b", 'i');
            rn = dit.search(pat);
            if (rn != -1) {
                dit = dit.replace(pat, wt[0] + '~' + wt[1]);
            }
        }
    }

    dit = dit.replace(/ or /gi, '~');
    dit = dit.replace(/\"/gi, '');
    ct_d = 0;
    w_in = new Array();
    wt = dit.split(' ');
    for (i = 0; i < wt.length; i++) {
        w_in[i] = 0;
        if (wt[i].charAt(0) == '-') w_in[i] = 1;
        pat = new RegExp("\\~", 'i');
        rn = wt[i].search(pat);
        if (rn != -1) w_in[i] = 2;
        wt[i] = wt[i].replace(/^\-|^\+/gi, '');
    }

    a = 0;
    for (c = 0; c < s.length; c++) {
        es = s[c].split('^');
        rk = 1000;
        if (es[3] == null) es[3] = '0';
        if (es[4] == null) es[4] = '0';
        if (parseInt(es[4]) > 10) es[4] = '10';
        pa = 0;
        nh = 0;
        for (i = 0; i < w_in.length; i++) {
            if (w_in[i] == 0) {
                nh++;
                nt = 0;
                pat = new RegExp("\\b" + wt[i] + "\\b", 'i');
                rn = es[0].search(pat);
                if (rn != -1) {
                    rk -= seed * 3;
                    rk -= parseInt(es[4]);
                    nt = 1;
                    if (ct == 1) ct_d = 1;
                }
                rn = es[2].search(pat);
                if (rn != -1) {
                    rk -= seed;
                    rk -= parseInt(es[4]);
                    nt = 1;
                }
                if (nt == 1) pa++;
            }
            if (w_in[i] == 1) {
                pat = new RegExp("\\b" + wt[i] + "\\b", 'i');
                rn = es[0].search(pat);
                if (rn != -1) pa = 0;
                rn = es[2].search(pat);
                if (rn != -1) pa = 0;
            }
            if (w_in[i] == 2) {
                nh++;
                nt = 0;
                w_o = wt[i].split('~');
                pat = new RegExp("\\b" + w_o[0] + "\\b", 'i');
                pat_2 = new RegExp("\\b" + w_o[1] + "\\b", 'i');
                rn = es[0].search(pat);
                rn_2 = es[0].search(pat_2);
                if (rn != -1 || rn_2 != -1) {
                    rk -= seed / 2;
                    rk -= parseInt(es[4]);
                    nt = 1;
                    if (ct == 1) ct_d = 1;
                }
                rn = es[2].search(pat);
                rn_2 = es[2].search(pat_2);
                if (rn != -1 || rn_2 != -1) {
                    rk -= seed / 2;
                    rk -= parseInt(es[4]);
                    nt = 1;
                }
                if (nt == 1) pa++;
            }
        }

        if (pa == nh && nh != 0) {
            es_c = '';
            ci_e = es[2].split(' ');
            if (ci_e.length < ct_l) {
                es_c = es[2];
            } else {
                for (i = 0; i < ct_l; i++) {
                    es_c += ci_e[i] + ' ';
                }
            }
            es_c = es_c.replace(/^\s*|\s*$/g, '');
            if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
            es_c += ' ...';

            if (ct == 1 && ct_d == 0) {
                ct_f = true;
                pat = new RegExp("\\b" + wt[0] + "\\b", 'i');
                rn = es[2].search(pat);
                if (rn > c_s) {
                    t_1 = es[2].substr(rn - (c_s - 1));
                    rn = t_1.indexOf('. ');
                    if (rn != -1 && rn < (c_s / 2)) {
                        t_1 = t_1.substr(rn + 1);
                        t_2 = t_1.split(' ');
                        if (t_2.length > ct_l) {
                            es_c = '';
                            for (i = 1; i < ct_l + 1; i++) {
                                es_c += ' ' + t_2[i];
                            }
                            if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
                            es_c += ' ...';
                            ct_f = false;
                        }
                    }
                }
                if (ct_f) {
                    rn = es[2].search(pat);
                    t_1 = es[2].substr(rn - (c_s / 5));
                    rn = t_1.indexOf(' ');
                    if (rn != -1) {
                        t_1 = t_1.substr(rn + 1);
                        t_2 = t_1.split(' ');
                        es_c = '';
                        if (t_2.length > ct_l) {
                            for (i = 1; i < ct_l + 1; i++) {
                                es_c += ' ' + t_2[i];
                            }
                        } else {
                            for (i = 1; i < t_2.length; i++) {
                                es_c += ' ' + t_2[i];
                            }
                        }
                        if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
                        es_c += ' ...';
                    }
                }
            }

            tr[a] = rk + '^' + es[0] + '^' + es[1] + '^' + es_c + '^' + es[2] + '^' + es[3] + '^' + es[4];
            a++;
        }
    }
    tr.sort();
    co = a;
}

if (t_m == 1 && !v_d) {
    dit = dit.replace(/"/gi, '');
    a = 0;
    ct_d = 0;
    pat = new RegExp(dit, 'i');
    for (c = 0; c < s.length; c++) {
        es = s[c].split('^');
        rk = 1000;
        if (es[3] == null) es[3] = '0';
        if (es[4] == null) es[4] = '0';
        if (parseInt(es[4]) > 10) es[4] = '10';
        rn = es[0].search(pat);
        if (rn != -1) {
            rk -= seed * 3;
            rk -= parseInt(es[4]);
            ct_d = 1;
        }
        rn = es[2].search(pat);
        if (rn != -1) {
            rk -= seed;
            rk -= parseInt(es[4]);
        }
        if (rk < 1000) {
            es_c = '';
            ci_e = es[2].split(' ');
            if (ci_e.length < ct_l) {
                es_c = es[2];
            } else {
                for (i = 0; i < ct_l; i++) {
                    es_c += ci_e[i] + ' ';
                }
            }
            es_c = es_c.replace(/^\s*|\s*$/g, '');
            if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
            es_c += ' ...';

            if (ct == 1 && ct_d == 0) {
                ct_f = true;
                rn = es[2].search(pat);
                if (rn > c_s) {
                    t_1 = es[2].substr(rn - (c_s - 1));
                    rn = t_1.indexOf('. ');
                    if (rn != -1 && rn < (c_s / 2)) {
                        t_1 = t_1.substr(rn + 1);
                        t_2 = t_1.split(' ');
                        if (t_2.length > ct_l) {
                            es_c = '';
                            for (i = 1; i < ct_l + 1; i++) {
                                es_c += ' ' + t_2[i];
                            }
                            if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
                            es_c += ' ...';
                            ct_f = false;
                        }
                    }
                }
                if (ct_f) {
                    rn = es[2].search(pat);
                    t_1 = es[2].substr(rn - (c_s / 5));
                    rn = t_1.indexOf(' ');
                    if (rn != -1) {
                        t_1 = t_1.substr(rn + 1);
                        t_2 = t_1.split(' ');
                        es_c = '';
                        if (t_2.length > ct_l) {
                            for (i = 1; i < ct_l + 1; i++) {
                                es_c += ' ' + t_2[i];
                            }
                        } else {
                            for (i = 1; i < t_2.length; i++) {
                                es_c += ' ' + t_2[i];
                            }
                        }
                        if (es_c.charAt(es_c.length - 1) == '.' || es_c.charAt(es_c.length - 1) == ',') es_c = es_c.substr(0, es_c.length - 1);
                        es_c += ' ...';
                    }
                }
            }

            tr[a] = rk + '^' + es[0] + '^' + es[1] + '^' + es_c + '^' + es[2] + '^' + es[3] + '^' + es[4];
            a++;
        }
    }
    tr.sort();
    co = a;
}

if (v_d) co = 0;

function tip_query() {
    if (od != 'undefined' && od != null) document.forms.tipue.d.value = od;
}

function tip_header() { // this writes the line with the search word
    if (co > 0) {
        ne = nr + tn;
        if (ne > co) ne = co;
        document.write(tl_12, ' ', tn + 1, ' ', tl_5, ' ', ne, ' ', tl_6, ' ', co, ' ', tl_7, ' ');
        if (header_links == 1) {
            if (t_m == 0) {
                hd = hd.replace(/\"/gi, '');
                wt_h = hd.split(' ');
                for (i = 0; i < wt_h.length; i++) {
                    if (wt_h[i].toLowerCase() != 'or' && wt_h[i].toLowerCase() != 'and' && wt_h[i].toLowerCase() != 'not' && wt_h[i] != '+' && wt_h[i] != '-') {
                        if (wt_h[i].charAt(0) == '+' || wt_h[i].charAt(0) == '-' || wt_h[i].charAt(0) == '~') {
                            document.write(wt_h[i].charAt(0));
                            wt_h[i] = wt_h[i].slice(1, wt_h[i].length);
                        }
                        document.write('<a href="', r_l, '?d=', wt_h[i], '">', wt_h[i], '</a><p> ');
                    } else document.write(wt_h[i] + ' ');
                }
            } else document.write(hd);
        } else document.write(hd);
    }
}

function tip_out() {
    if (cw_l.length > 0) {
        document.write(tl_9, ' ', cw_l, '<p>');

    }
    if (sp_l.length > 0) {
        sp_e = encodeURIComponent(sp_l);
        document.write(tl_8, ' <a href="', r_l, '?d=', sp_e, '">', sp_l, '</a><p>');
    }
    if (co == 0) {
        if (v_d) {
            document.write(tl_10);
        } else {
            document.write(tl_1);
            if (b_q == 1) document.write('<b>', od, '</b>');
            else document.write(od);
            document.write(tl_2);
        }
        return;
    }
    if (tn + nr > co) nd = co;
    else nd = tn + nr;
    for (a = tn; a < nd; a++) {
        os = tr[a].split('^');
        if (b_q == 1 && t_m == 0) {
            for (i = 0; i < wt.length; i++) {
                pat = new RegExp("\\~", 'i');
                rn = wt[i].search(pat);
                if (rn != -1) {
                    tw = wt[i].split('~');
                    for (c = 0; c < tw.length; c++) {
                        lw = tw[c].length;
                        pat = new RegExp(tw[c], 'i');
                        rn = os[3].search(pat);
                        if (rn != -1) {
                            o1 = os[3].slice(0, rn);
                            o2 = os[3].slice(rn, rn + lw);
                            o3 = os[3].slice(rn + lw);
                            os[3] = o1 + '<b>' + o2 + '</b>' + o3;
                        }
                    }
                } else {
                    lw = wt[i].length;
                    pat = new RegExp(wt[i], 'i');
                    rn = os[3].search(pat);
                    if (rn != -1) {
                        o1 = os[3].slice(0, rn);
                        o2 = os[3].slice(rn, rn + lw);
                        o3 = os[3].slice(rn + lw);
                        os[3] = o1 + '<b>' + o2 + '</b>' + o3;
                    }
                }
            }
        }

        if (b_q == 1 && t_m == 1) {
            lw = dit.length;
            tw = new RegExp(dit, 'i');
            rn = os[3].search(tw);
            if (rn != -1) {
                o1 = os[3].slice(0, rn);
                o2 = os[3].slice(rn, rn + lw);
                o3 = os[3].slice(rn + lw);
                os[3] = o1 + '<b>' + o2 + '</b>' + o3;
            }
        }

        if (include_num == 1) document.write(a + 1, '. ');
        if (os[5] == '0') t_b = '';
        if (os[5] == '1') t_b = 'target="_blank"';
        if (os[5] != '0' && os[5] != '1') t_b = 'target="' + os[5] + '"';
        if (b_t == 0) document.write('<a href="', os[2], '" ', t_b, '>', os[1], '</a>');
        if (b_t == 1) {
            lw = dit.length;
            tw = new RegExp(dit, 'i');
            rn = os[1].search(tw);
            if (rn != -1) {
                o1 = os[1].slice(0, rn);
                o2 = os[1].slice(rn, rn + lw);
                o3 = os[1].slice(rn + lw);
                os[1] = o1 + '<b>' + o2 + '</b>' + o3;
            }
            document.write('<a href="', os[2], '" ', t_b, '>', os[1], '</a>');
        }
        if (b_t == 2) document.write('<a href="', os[2], '" ', t_b, '><b>', os[1], '</b></a>');

        if (os[3].length > 1) document.write('<br>', os[3]);
        if (include_url == 1) document.write('<br><a href="', os[2], '" ', t_b, 'target="_blank">', os[2], '</a>');
        document.write('<p>');
    }
}

function tip_footer() {
    if (co > nr) {
        od = encodeURIComponent(od);
        var np = Math.ceil(co / nr);
        nc = co - (tn + nr);
        if (tn > 0) var na = Math.ceil(tn / nr) + 1;
        else var na = 1;
        if (tn > 1) document.write('<a href="', r_l, '?d=', od, '&n=', tn - nr, '">', tl_3, '</a> &nbsp;');
        if (np < 10) {
            for (var i = 0; i < np; i++) {
                var nb = nr * i;
                if (nb == tn) {
                    if (b_f == 1) document.write('<b>', i + 1, '</b> &nbsp;');
                    else document.write(i + 1, ' &nbsp;');
                } else document.write('<a href="', r_l, '?d=', od, '&n=', nb, '">', i + 1, '</a> &nbsp;');
            }
        }
        if (np > 9) {
            if (na < 8) {
                for (var i = 0; i < 9; i++) {
                    var nb = nr * i;
                    if (nb == tn) {
                        if (b_f == 1) document.write('<b>', i + 1, '</b> &nbsp;');
                        else document.write(i + 1, ' &nbsp;');
                    } else document.write('<a href="', r_l, '?d=', od, '&n=', nb, '">', i + 1, '</a> &nbsp;');
                }
            } else {
                var ng = na - 5;
                if (np > ng + 9) var nf = ng + 9;
                else nf = np;
                for (var i = ng; i < nf; i++) {
                    var nb = nr * i;
                    if (nb == tn) {
                        if (b_f == 1) document.write('<b>', i + 1, '</b> &nbsp;');
                        else document.write(i + 1, ' &nbsp;');
                    } else document.write('<a href="', r_l, '?d=', od, '&n=', nb, '">', i + 1, '</a> &nbsp;');
                }
            }
        }
        if (nc > 0) document.write('<a href="', r_l, '?d=', od, '&n=', tn + nr, '">', tl_4, '</a>');
    }
    }

function tipqueryTask() {
        get_xml();
        tip_header();
        tip_query();
        tip_out();
        tip_footer();
        setFocus();
    }
    document.getElementById('myform').addEventListener('submit', tipqueryTask());{
     // event.preventDefault(); Prevent default behaviour (submitting form)
    var outputElement = document.getElementById('outputHeader');
    outputElement.innerHTML = '<script language="JavaScript" type="text/javascript" >tip_out()></script>';
    var outputElement = document.getElementById('outputQuery');
    outputElement.innerHTML = '<script language="JavaScript" type="text/javascript">tip_query()></script>';
    var outputElement = document.getElementById('outputOut');
    outputElement.innerHTML = '<script language="JavaScript" type="text/javascript">tip_out()</script>';
    var outputElement = document.getElementById('outputFooter');
    outputElement.innerHTML = '<script language="JavaScript" type="text/javascript">tip_footer()></script>';
} false;

Looking into this further, I think it may have something to do with the XML file having to be whitelisted and amendments made to the js file but if so then it's far too complicated for me. I can't write javascript myself, I'm just an amateur and only able to adjust other peoples' scripts to suit my needs.

Please let me know if you need any other info. Many thanks

index.html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0020)http://www.tipue.com -->

<html>
<head>
<title>Address % Telephone Search</title>
</head>
<body>
<form id="myform" method="get" name="tipue" action="results.html">
<table cellpadding=0 cellspacing=0 class="form_table"><tr>
<td class="form_td_left">
<input type="text" name="d" id="searchBox" class="field">
</td>
<td class="form_td_right">
<input type="submit" value="Go" class="button">
<br />
</td></tr></table>
</form>
<!-- End of form section -->
<p>
Enter Tipue or other search terms in the example above.
<p>
This example uses an <a href="http://www.tipue.com/products/tipueJS/started/xml.cgi">XML</a> data file. For more information see <a href="http://www.tipue.com/products/tipueJS/started/">Getting Started</a>.
<br>
</body>
</html>

and you'll also need

results.html
(revised code below)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0020)http://www.tipue.com -->
<html>
<head>
<title>Tipue JS XML Example Search Results</title>
</head>
<body>
<form id="myform" method="get" name="tipue" action="results.html">
<table cellpadding=0 cellspacing=0 class="form_table"><tr>
<td class="form_td_left">
<input type="text" name="d" class="field" id="searchBox">
</td>
<td class="form_td_right">
<input type="submit" value="Go" class="button">
</td></tr></table>
</form>
<!-- End of form section -->
<br>
<div id="outputQuery"></div>
<div id="outputHeader"></div>
<div id="outputOut"></div>
<div id="outputFooter"></div>
<script language="JavaScript" type="text/javascript" src="combinedTipue.js"></script> 
<br>
<hr>
</body>
</html>

If you change the manifest to version: 1 you'll see it works ok but not as version:2. I appreciate your help with this, many thanks

added popup.js deleted

Community
  • 1
  • 1
user1575788
  • 1
  • 1
  • 4
  • 1
    What's the error message, what's the relevant script? Your manifest contains lots of junk, by the way. For instance, `background_page` is not a recognised key in `browser_action`. In permissions, `tipue.js`, `tipue_set.js` and `tipue_data.xml` can be removed. – Rob W Aug 04 '12 at 11:10
  • The error messages are: There were warnings when trying to install this extension: Permission 'tipue.js' is unknown or URL pattern is malformed. Permission 'tipue_set.js' is unknown or URL pattern is malformed. Permission 'tipue_data.xml' is unknown or URL pattern is malformed. I removed them as you suggested and the warnings go away but the search function still doesn't work. The XML code is: Tipue http://www.tipue.com/ Blah,Blah 10 Any ideas? – user1575788 Aug 05 '12 at 05:41
  • 1
    Glancing over your code, I see that a kind of user interface is constructed. But **a background page does not have a visible view!**. Move it to a view, eg an [options page](http://code.google.com/chrome/extensions/options.html) (just for testing). Your script includes Internet Explorer-specific methods, by the way. That's *very* useful in a Chrome extension.. (not). – Rob W Aug 05 '12 at 08:57
  • I moved the background page as you suggested but it doesn't make any difference. Regarding the IE specific methods, as I said I didn't write this - I'm not that clever!, hence the problem I'm having getting it to work with manifest version 2. (As I said, it works perfectly in Version 1) – user1575788 Aug 05 '12 at 12:05
  • It "worked" with manifest version 1? What do you expect from the script? Let `popup.html` be ``, does it work as expected? In any case, you have to load `tipue_set.js` before `tipue.js`. – Rob W Aug 05 '12 at 12:34
  • By "worked" I mean it behaved as intended i.e. I put in a search term and the popup showed the results page with the relevant search results. I added the 2 scripts to index.html which is my default popup page (tipue_set.js is loaded first anyway) as you suggested but still no joy – user1575788 Aug 05 '12 at 19:45
  • I tried to reproduce your problem, then realised that a file is missing. What's the contents of `index.html`? – Rob W Aug 05 '12 at 21:36
  • I've added index.html & also results.html, thanks for trying to help with this – user1575788 Aug 06 '12 at 05:27
  • 2
    Move the function calls to an external script file. This question is a duplicate of [Communication between ContentScript.js and Chrome Extension](http://stackoverflow.com/questions/10416594/communication-between-contentscript-js-and-chrome-extension) and [Module Load Progress Events in NaCl with manifest_version = 2 and no inline javascript](http://stackoverflow.com/questions/11811681/module-load-progress-events-in-nacl-with-manifest-version-2-and-no-inline-java). – Rob W Aug 06 '12 at 07:44
  • I haven't got as far as moving the function calls as I'm still stuck on what to put in the manifest! Could you tell me please what I need to put to allow content security permission from local files. I've tried various combinations of `"content_security_policy": "script-src 'self' C:\Documents and Settings\*; object-src 'self'",` but I keep getting not valid json - invalid escape sequence. This is very frustrating! – user1575788 Aug 07 '12 at 06:18
  • Don't modify the CSP section of the manifest file (there's no point to do that in your case). Just read the linked answers. Basically: Replace `` with `` and move `...` to `somename.js`. For each of your inline script blocks in `index.html`. – Rob W Aug 07 '12 at 07:39
  • I'm stuck again! How do I make eventlistener refer to a form? I'm following this tutorial [link](http://code.google.com/chrome/extensions/trunk/contentSecurityPolicy.html#H3-1) and have changed the 3 inline scripts but the example fires with a button event. How do I code it for a form, please. – user1575788 Aug 08 '12 at 06:01
  • Just change the selector to match the form. Eg. add an id,`
    `, `document.getElementById("myform").addEventListener(...)`.
    – Rob W Aug 08 '12 at 09:39
  • Rob, I've spent a couple more days trawling the internet for an example that matches mine but to no avail. I don't understand Javascript, I'm only able to copy other peoples. Is it possible for you to show me the code I need to use to get this to work, please. Currently, I have `document.getElementById("myform").addEventListener('DOMContentLoaded', function () { document.querySelector("myform").addEventListener('submit', clickHandler); });` I've put every single function in popup.js as per the tutorial & at the end I put `function tipqueryTask()` & `function clickHandler(e)` see below – user1575788 Aug 10 '12 at 04:48
  • `function tipqueryTask() { get_xml(); tip_query(); tip_header(); tip_out(); tip_footer(); }` (These are the functions I've taken out of the tipue.js script) `function clickHandler(e) { setTimeout(tipqueryTask, 1000); }` I think I'm close but just can't get it, it's too complicated. If you can help I'd be very grateful. Many thanks – user1575788 Aug 10 '12 at 04:53
  • You can't merge these functions. Last time I looked in tipue.js, the functions use `document.write` to construct the document. This is extremely bad practice, so I suggest to replace `document.write` calls with DOM manipulation/innerHTML. Some hints regarding implementation: http://jsfiddle.net/6jxbG/ – Rob W Aug 10 '12 at 07:52
  • thanks to your example on jsfiddle the submit button now "works" ( i had some errors according to the console debugger but I think I've fixed them all now). So now, when the button is clicked the results page is displayed in the popup but there's no results! I think I have to add chrome.extension.connect (but I don't know where) so that the pages can communicate but all the examples I've looked at seem to be for 'tabs' not 'popups' . Could you give me some guidance please or point me to an example that uses popup not tabs so that I can copy it please. Many thanks – user1575788 Aug 16 '12 at 06:05
  • See [`chrome.extension.sendMessage`](http://code.google.com/chrome/extensions/extension.html#method-sendMessage) etc. A message sent from a content script is received by all views of the extension, including background page and popup. – Rob W Aug 16 '12 at 08:43
  • Rob can you tell me please what needs to go in the brackets. I've made a content page with `chrome.extension.sendMessage(string extensionId, any message, function responseCallback)` but I don't know what I need to put to make the results.html page appear with the search results from tipue_data.xml. Reading the instructions from the Chrome help page I think I must have to make a background page with `chrome.extension.onMessage.addListener(function(object details) {...}); ` but again what goes in the brackets?? Sorry to be a pain but as I said I'm a complete novice but I'll get there in the end – user1575788 Aug 18 '12 at 06:13
  • By the way, Rob, just wanted to say thanks for all your help. I've tried to find an example to copy from (I've got 11 tabs open at the moment!) but I can't find anything similar to what I'm trying to do. I can appreciate you're probably very busy & don't have the time to waste on this little project so if you want someone else to help me please feel free to link this wherever you think might help. It's very frustrating.This was such a simple tool when it was manifest V1 but now they've changed it to V2 it's so complicated & I'm out of my depth – user1575788 Aug 18 '12 at 06:28
  • I have posted many examples (code snippets and full extensions) on SO. You could browse my answers by using the search feature, for example [`[google-chrome-extension] user:938089 onmessage`](http://stackoverflow.com/search?q=[google-chrome-extension]+user%3A938089+onmessage). For example code on **correctly** using `sendMessage`, see http://stackoverflow.com/a/11811936. Note: In the documentation, every variable is preceded by its expected type. Do *not* include this type in your actual code. So, use `function(details){...` and not `function(object details){..`. – Rob W Aug 18 '12 at 09:16
  • I *have* searched this site for answers, every morning before I go to work I've spent many, many hours trying to find code that will help me but all the examples use console log or alert but that doesn't help cos I need to copy an example similar to what I'm trying to do. I have also found lots of your replies and code snippets on JS Fiddle but I still can't get my head round how to do this. For example "use function(details){... and not function(object details){.." you may as well be speaking a foreign language for all the sense this made to me. Can you please help me step by step.. (cont'd) – user1575788 Aug 21 '12 at 05:53
  • For example chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { // Chrome 20+ }); chrome.extension.sendMessage(message, optional_sendResponse); can you please tell me if I have to put anything in where it says //Chrome 20+ and also what do I put for "message"? I don't particularly want or need a message if it's a normal message e.g "hello" "goodbye". Thank you in advance – user1575788 Aug 21 '12 at 06:04
  • In `//Chrome 20+`, you have to put the expressions which handle the message. Here's a simple example of alerting the message when received: `chrome.extension.onMessage.addListener(function(request) { alert(request); });` Sending a message: `chrome.extension.sendMessage("hello");`. If this doesn't help you, can you phrase concrete questions to your problem? – Rob W Aug 21 '12 at 13:06
  • I had some errors which I found with JSLINT. I haven't been able to add 'sendmessage' etc because I still have errors I can't fix. In popup.js I have `function clickHandler(event) { setTimeout(tipqueryTask, 5000); } // Add event listeners once the DOM has fully loaded by listening for the // DOMContentLoaded event on the document, and adding your listeners to // specific elements when it triggers. document.getElementById("myform").addEventListener('submit', clickHandler(event)); { event.preventDefault(); // Prevent the form from being submitted } false;` contd – user1575788 Aug 24 '12 at 05:16
  • This is giving me `Uncaught TypeError: Cannot call method 'addEventListener' of null` in popup.js and `Uncaught TypeError: Cannot read property 'd' of undefined` in tipue.js I have searched but couldn't find any help but there is a [bug]:http://code.google.com/p/chrome-type-ahead/issues/detail?id=84 Can you help me fix these please? Also, if I put in `document.addEventListener('DOMContentLoaded', function() ` nothing happens but if I leave it out I get the results page saying " Your search - xyz - did not match any documents.Try different keywords etc" so something is being executed? – user1575788 Aug 24 '12 at 05:30
  • Did you get rid off the `document.write` calls? Deferred loading (eg via `DOMContentLoaded`) doesn't work well with it. Also, I really doubt that your extension worked fine with manifest v1 given these errors. Are we still talking about problems raises by the transition from manifest v1 to v2, or are these issues caused by something else? – Rob W Aug 24 '12 at 08:01
  • I can assure you V1 is working perfectly. We use it many times a day as a quick look up for phone numbers at work. I'm retiring soon & that's why I want to make sure that when V1 is finally deprecated the app still works. I haven't got rid of the document.write calls yet as I'm trying to clear the errors I have so far. Yes the problems are caused by the switch to V2 as I've had to move bits of code around to satisfy the stricter controls of V2. At present, without DOMContentLoaded, when I enter a word in the input box & click submit, the extension switches to the results page and says contd – user1575788 Aug 24 '12 at 17:59
  • the extension switches to the results page and says "your search did not match etc" which it gets from Tipue_set.js if the search term is not found so it must be partly working. If you could just help me fix the 'addeventlistener of null' error I think I might be able to get somewhere – user1575788 Aug 24 '12 at 18:03
  • Well, that problem indicates that you're running the code before the form element is created. Put the `` at the end of the document, ie before `

    ` to get rid off that error.

    – Rob W Aug 24 '12 at 20:08

1 Answers1

0

I've sort of got it working with this code which is at the foot of popup.js:

function tipqueryTask() {get_xml(); tip_header(); tip_query(); tip_out(); tip_footer();}
function clickHandler() {
  setTimeout(tipqueryTask, 5000);}
  var alreadyrunflag=0 //flag to indicate whether target function has already been run
if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; clickHandler()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
      clickHandler()}}}

Notice setTimeout is 5 secs. What seems to be happening is when I click on the extension,the index.html opens & I have 5 secs to type in a search query (otherwise it says 'blank search'(which is one of the attributes/variables?? in tipue_set.js))After I hit enter, the results.html page appears but has no results in it then once the 5 secs is up another page appears with the actual results on it. SetTimeout is running the clickhandling from popup.js but I can't figure out how to get it to run from the results page which is supposed to have inline js for all the functions in tipqueryTask. I tried putting them in separate scripts but that didn't work. Any ideas? If not I'll just have to leave it like this. It's not ideal but better than nothing.

user1575788
  • 1
  • 1
  • 4