Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cope with absolute local file paths as sources.
- Loading branch information
Showing
1 changed file
with
19 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) {}); | ||
} | ||
} |