Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension Script

I've created a chrome extension which will find a USPS tracking number on text highlight. My current code is working great but I wanted to make some modification.

Here's the manifest.json

{
  "manifest_version": 2,
  "background" : { "scripts": ["background.js"] },
  "description": "Track on USPS",
  "icons": {
  "default_icon": "usps.png"
      },
  "minimum_chrome_version": "29.0", 
  "name": "USPS",
  "permissions": [ "contextMenus", "tabs", "http://*/*",
  "https://*/*" ],
  "version": "1.0"
}

This is the background.js:

/**
* Returns a handler which will open a new tab when activated.
*/
function searchgoogle(info)
{
  var searchstring = info.selectionText;
  chrome.tabs.create({url: "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=" + searchstring})
}

chrome.contextMenus.create({title: "Search USPS", contexts:["selection"], onclick: searchgoogle});

/**
* Create a context menu which will only show up for images.
*/
chrome.contextMenus.create({
  "title" : "Search tracking number on USPS",
  "type" : "normal",
  "contexts" : ["text"],
  "onclick" : getClickHandler()
});

Now I wanted to modify the current script:

https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=" + searchstring

with the script below. This new code will open a pop up window. I tried modifying the new script but to no avail. Can anyone help me out?

Here's the new script that I wanted to use:

javascript:new function(){window.open('https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=' + window.getSelection().toString(), '_blank', 'toolbar=0,location=0,menubar=0,top=91,height=900,width=650,left=1475');};

Thanks a lot in advance! This community help me a lot with my projects.

like image 951
JAMES Avatar asked May 24 '26 11:05

JAMES


1 Answers

It doesn't look like you're actually calling the function you're creating in the script (and you can't because it isn't named). Try removing the function, and just executing the code:

javascript:window.open('https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=' + window.getSelection().toString(), '_blank', 'toolbar=0,location=0,menubar=0,top=91,height=900,width=650,left=1475');
like image 107
Timothy Kanski Avatar answered May 27 '26 02:05

Timothy Kanski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!