Skip to content

Commit

Permalink
Cope with absolute local file paths as sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
robmiller committed Jun 8, 2012
1 parent 9b37d34 commit 6468801
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions finder.js
@@ -1,9 +1,25 @@
var button = chrome.contextMenus.create({"title": "Find timthumb original", "contexts": ["image"], "onclick": finder, "targetUrlPatterns":["*://*/*timthumb.php*"]});

function finder(info, tab) {
var myRe = /src=([^&]+)/g;
var urlArray = myRe.exec(info.srcUrl);
var urlArray = info.srcUrl.match(/src=([^&]+)/);

var src = decodeURIComponent(urlArray[1]);
var target = '';

// If the TimThumb src points to a absolute local file path, then try and convert it to a URL.
if ( src.match(/^\//) ) {
var parts = src.match(/\/([^\/]+(\.[a-z]{3}|\.co\.uk))\/(httpdocs|public_html|htdocs)\/(.*)$/);
if ( parts && parts.length >= 2 ) {
hostname = parts[1];
path = parts[4];
target = 'http://' + hostname + '/' + path;
}
} else {
target = src;
}

// Create new tab
chrome.tabs.create({'url': decodeURIComponent(urlArray[1])}, function(tab) {});
if ( target != '' ) {
chrome.tabs.create({'url': target}, function(tab) {});
}
}

0 comments on commit 6468801

Please sign in to comment.