-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7a2bdc
Showing
5 changed files
with
210 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Baikal | ||
|
||
A quick navigation between pages with keyboard. Displays a list of all links | ||
within a page in a pop up window. Clicking or hitting Enter on a link navigates to the selected link. | ||
|
||
Use search box to quick find a required link. | ||
|
||
## Installation in Chrome | ||
|
||
* Clone repository | ||
* Install unpacked extension https://developer.chrome.com/extensions/getstarted#unpacked | ||
* Assign keyboard shortcut to display Baikal popup. It's optional, but highly | ||
recommended. Here's an example: https://www.howtogeek.com/127162/how-to-create-custom-keyboard-shortcuts-for-browser-actions-and-extensions-in-google-chrome/ |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"manifest_version": 2, | ||
|
||
"name": "Baikal", | ||
"description": "A quick navigation between pages with keyboard", | ||
"version": "0.0.1", | ||
|
||
"browser_action": { | ||
"default_popup": "popup.html" | ||
}, | ||
"permissions": [ | ||
"activeTab" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!doctype html> | ||
<!-- | ||
This page is shown when the extension button is clicked, because the | ||
"browser_action" field in manifest.json contains the "default_popup" key with | ||
value "popup.html". | ||
--> | ||
<html> | ||
<head> | ||
<title>Getting Started Extension's Popup</title> | ||
<style> | ||
body { | ||
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif; | ||
font-size: 100%; | ||
min-width: 500px; | ||
} | ||
#status { | ||
/* avoid an excessively wide status text */ | ||
white-space: pre; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
max-width: 400px; | ||
} | ||
/**/ | ||
td:focus { | ||
background-color: green; | ||
} | ||
|
||
tr:hover { | ||
background-color: grey; | ||
} | ||
</style> | ||
|
||
<!-- | ||
- JavaScript and HTML must be in separate files: see our Content Security | ||
- Policy documentation[1] for details and explanation. | ||
- | ||
- [1]: https://developer.chrome.com/extensions/contentSecurityPolicy | ||
--> | ||
<script src="popup.js"></script> | ||
</head> | ||
<body> | ||
<input id="filter" type="text" name="" value="" tabindex=1 placeholder="Type to search..."> | ||
<table id=links> | ||
<tr> | ||
<th align=left>URL</th> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
var allLinks = []; | ||
var visibleLinks = []; | ||
|
||
function gotoURL(event) { | ||
// alert('1'); | ||
|
||
const newURL = event.target.innerText; | ||
|
||
chrome.windows.getCurrent(function (currentWindow) { | ||
chrome.tabs.query( | ||
{ active: true, windowId: currentWindow.id }, | ||
function(activeTabs) { | ||
chrome.tabs.update(activeTabs[0].id, {url: newURL}); | ||
window.close(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
// Re-filter allLinks into visibleLinks and reshow visibleLinks. | ||
function filterLinks() { | ||
var filterValue = document.getElementById('filter').value; | ||
var terms = filterValue.split(' '); | ||
visibleLinks = allLinks.filter(function(link) { | ||
for (var termI = 0; termI < terms.length; ++termI) { | ||
var term = terms[termI]; | ||
if (term.length != 0) { | ||
var expected = (term[0] != '-'); | ||
if (!expected) { | ||
term = term.substr(1); | ||
if (term.length == 0) { | ||
continue; | ||
} | ||
} | ||
var found = (-1 !== link.indexOf(term)); | ||
if (found != expected) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
}); | ||
showLinks(); | ||
} | ||
|
||
function showLinks() { | ||
var linksTable = document.getElementById('links'); | ||
while (linksTable.children.length > 1) { | ||
linksTable.removeChild(linksTable.children[linksTable.children.length - 1]) | ||
} | ||
for (var i = 0; i < visibleLinks.length; ++i) { | ||
var row = document.createElement('tr'); | ||
|
||
var col1 = document.createElement('td'); | ||
col1.innerText = visibleLinks[i]; | ||
col1.onclick = gotoURL; | ||
col1.style.whiteSpace = 'nowrap'; | ||
col1.tabIndex = i + 2; | ||
col1.onkeyup = function(event) { | ||
event.preventDefault(); | ||
if (event.keyCode == 13) { | ||
gotoURL(event); | ||
} | ||
} | ||
row.appendChild(col1); | ||
linksTable.appendChild(row); | ||
} | ||
} | ||
|
||
chrome.extension.onRequest.addListener(function(links) { | ||
for (var index in links) { | ||
allLinks.push(links[index]); | ||
} | ||
allLinks.sort(); | ||
visibleLinks = allLinks; | ||
showLinks(); | ||
}); | ||
|
||
|
||
// Set up event handlers and inject send_links.js into all frames in the active | ||
// tab. | ||
window.onload = function() { | ||
document.getElementById('filter').focus(); | ||
document.getElementById('filter').onkeyup = filterLinks; | ||
// document.getElementById('regex').onchange = filterLinks; | ||
// document.getElementById('toggle_all').onchange = toggleAll; | ||
|
||
chrome.windows.getCurrent(function (currentWindow) { | ||
chrome.tabs.query({active: true, windowId: currentWindow.id}, | ||
function(activeTabs) { | ||
chrome.tabs.executeScript( | ||
activeTabs[0].id, {file: 'send_links.js', allFrames: true}); | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Send back to the popup a sorted deduped list of valid link URLs on this page. | ||
// The popup injects this script into all frames in the active tab. | ||
|
||
var links = [].slice.apply(document.getElementsByTagName('a')); | ||
links = links.map(function(element) { | ||
// Return an anchor's href attribute, stripping any URL fragment (hash '#'). | ||
// If the html specifies a relative path, chrome converts it to an absolute | ||
// URL. | ||
var href = element.href; | ||
var hashIndex = href.indexOf('#'); | ||
if (hashIndex >= 0) { | ||
href = href.substr(0, hashIndex); | ||
} | ||
return href; | ||
}); | ||
|
||
links.sort(); | ||
|
||
// Remove duplicates and invalid URLs. | ||
var kBadPrefix = 'javascript'; | ||
for (var i = 0; i < links.length;) { | ||
if (((i > 0) && (links[i] == links[i - 1])) || | ||
(links[i] == '') || | ||
(kBadPrefix == links[i].toLowerCase().substr(0, kBadPrefix.length))) { | ||
links.splice(i, 1); | ||
} else { | ||
++i; | ||
} | ||
} | ||
|
||
chrome.extension.sendRequest(links); |