Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
Omnibox Integration (#1)
Browse files Browse the repository at this point in the history
* Integration Omnibox

* Suggested changes | Omnibox integration

* Suggested changes | Omnibox integration

* bump version 0.0.3
  • Loading branch information
fxnoob authored and coderworld10 committed Aug 25, 2019
1 parent a3b10a8 commit 7981890
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Short",
"short_name": "Short Ext",
"version": "0.0.2",
"version": "0.0.3",
"description": "Short allows you to visit short links using prefix s/ instead of https://s.time4hacks.com/r/",
"manifest_version": 2,
"background": {
Expand All @@ -15,9 +15,12 @@
"webRequest",
"webRequestBlocking"
],
"omnibox": {
"keyword" : "short"
},
"icons": {
"16": "icons/logo-16.png",
"48": "icons/logo-48.png",
"128": "icons/logo-128.png"
}
}
}
28 changes: 27 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,33 @@ function extractAlias(shortLink: string): string {
return shortLink.substring(aliasStartIdx);
}

function openTab(url: string) {
chrome
.tabs
.create({
url: url
});
}

class ShortExt {
constructor(private apiBaseUrl: string, private webUi: string) {
this.setupOmnibox();
}

fullURL = (alias: string) => {
// Escape user input for special characters , / ? : @ & = + $ #
let escapedAlias = encodeURIComponent(alias);
return `${this.apiBaseUrl}${escapedAlias}`;
}

setupOmnibox = () => {
chrome
.omnibox
.onInputEntered
.addListener((alias: string) => {
let url = this.fullURL(alias);
openTab(url);
});
}

redirect = (details: Details): BlockingResponse => {
Expand Down Expand Up @@ -72,4 +97,5 @@ const webUi = 'https://s.time4hacks.com';
const apiBaseUrl = `${webUi}/r/`;

const ext = new ShortExt(apiBaseUrl, webUi);
ext.launch();

ext.launch();

0 comments on commit 7981890

Please sign in to comment.