1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Send back to the popup a sorted deduped list of valid link URLs on this page.
6 // The popup injects this script into all frames in the active tab.
8 var links = [].slice.apply(document.getElementsByTagName('a'));
9 links = links.map(function(element) {
10 // Return an anchor's href attribute, stripping any URL fragment (hash '#').
11 // If the html specifies a relative path, chrome converts it to an absolute
13 var href = element.href;
14 var hashIndex = href.indexOf('#');
16 href = href.substr(0, hashIndex);
23 // Remove duplicates and invalid URLs.
24 var kBadPrefix = 'javascript';
25 for (var i = 0; i < links.length;) {
26 if (((i > 0) && (links[i] == links[i - 1])) ||
28 (kBadPrefix == links[i].toLowerCase().substr(0, kBadPrefix.length))) {
35 chrome.extension.sendRequest(links);