Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hrishibawane committed Jun 12, 2021
0 parents commit 7892112
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## URL Alias Chrome Extension

Set aliases for your frequently visited sites and use them just from the address bar

### Examples
- Add alias and corresponding URL from the extension's popup.
- Type in ```"hb" + TAB``` in address bar.
- Type your alias, press ```ENTER```.
20 changes: 20 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Background script
*/

// Empty alias to URL mapping
var aliasToURLMap = {}
var aliasToURLParsed = JSON.stringify(aliasToURLMap);

chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set({ aliasToURLParsed });
console.log("URL map value set");
});

chrome.omnibox.onInputEntered.addListener((alias) => {
console.log("Alias received: ", alias);
chrome.storage.sync.get("aliasToURLParsed", ({ aliasToURLParsed }) => {
var aliasToURLMap = JSON.parse(aliasToURLParsed);
chrome.tabs.create({ url: aliasToURLMap[alias] });
});
});
17 changes: 17 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "URL Alias",
"description": "Extension to use aliases for URLs",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["storage", "tabs"],
"omnibox": {
"keyword": "hb"
},
"action": {
"default_popup": "popup.html"
},
"author": "Hrishikesh Bawane"
}
21 changes: 21 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<label for="aliasInput">Alias</label>
<input id="aliasInput">
<br />
<label for="urlInput">URL</label>
<input id="urlInput">
<br />
<button id="saveAlias">Save</button>
</div>
<div>
<p id="prevAliases"></p>
</div>
<script src="popup.js"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Action script for extension popup
*/

var aliasToUrlMap;

window.onload = setPrevAliases;

document.getElementById("saveAlias").addEventListener("click", saveNewAlias);

function setPrevAliases() {
chrome.storage.sync.get("aliasToURLParsed", ({aliasToURLParsed}) => {
aliasToUrlMap = JSON.parse(aliasToURLParsed);
var displayStr = "";
for (var alias in aliasToUrlMap)
{
displayStr += alias + ": " + aliasToUrlMap[alias];
displayStr += "<br />";
}
document.getElementById("prevAliases").innerHTML = displayStr;
});
}

function saveNewAlias() {
var newAlias = document.getElementById("aliasInput").value;
var newUrl = document.getElementById("urlInput").value;
aliasToUrlMap[newAlias] = newUrl;
var aliasToURLParsed = JSON.stringify(aliasToUrlMap);
chrome.storage.sync.set({ aliasToURLParsed });
setPrevAliases();
}
17 changes: 17 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
button {
height: 30px;
width: 100px;
margin: 10px;
background-color: lightgreen;
}

input {
height: 30px;
width: auto;
margin: 10px;
}

label {
font-weight: bold;
margin: 10px;
}

0 comments on commit 7892112

Please sign in to comment.