feat: rename to shortify

This commit is contained in:
Steven
2023-03-16 08:25:58 +08:00
parent 143bdb7596
commit d08a738a57
43 changed files with 114 additions and 116 deletions

View File

@ -1,4 +1,4 @@
import { getCorgiData } from "./common.js";
import { getShortifyData } from "./common.js";
const urlRegex = /https?:\/\/o\/(.+)/;
@ -6,16 +6,16 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (typeof tab.url === "string") {
const matchResult = urlRegex.exec(tab.url);
if (matchResult) {
const corgiData = await getCorgiData();
const shortifyData = await getShortifyData();
const name = matchResult[1];
const url = `${corgiData.domain}/api/shortcut?openId=${corgiData.openId}&name=${name}&redirect=true`;
const url = `${shortifyData.domain}/api/shortcut?openId=${shortifyData.openId}&name=${name}&redirect=true`;
return chrome.tabs.update({ url });
}
}
});
chrome.omnibox.onInputEntered.addListener(async (text) => {
const corgiData = await getCorgiData();
const url = `${corgiData.domain}/api/shortcut?openId=${corgiData.openId}&name=${text}&redirect=true`;
const shortifyData = await getShortifyData();
const url = `${shortifyData.domain}/api/shortcut?openId=${shortifyData.openId}&name=${text}&redirect=true`;
return chrome.tabs.update({ url });
});

View File

@ -1,10 +1,10 @@
export const getCorgiData = () => {
export const getShortifyData = () => {
return new Promise((resolve, reject) => {
chrome.storage.local.get(["corgi"], (data) => {
if (data?.corgi) {
resolve(data.corgi);
chrome.storage.local.get(["shortify"], (data) => {
if (data?.shortify) {
resolve(data.shortify);
} else {
reject("corgi data not found");
reject("shortify data not found");
}
});
});

View File

@ -1,6 +1,6 @@
{
"name": "Corgi",
"description": "Corgi is an URL manager.",
"name": "Shortify",
"description": "",
"version": "0.0.1",
"manifest_version": 3,
"omnibox": {

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<body>
<h2>Corgi extension</h2>
<h2>Shortify extension</h2>
<div>
<span>Domain</span>
<input id="domain-input" type="text" />

View File

@ -1,4 +1,4 @@
import { getCorgiData } from "./common.js";
import { getShortifyData } from "./common.js";
const saveButton = document.body.querySelector("#save-button");
const domainInput = document.body.querySelector("#domain-input");
@ -6,7 +6,7 @@ const openIdInput = document.body.querySelector("#openid-input");
saveButton.addEventListener("click", () => {
chrome.storage.local.set({
corgi: {
shortify: {
domain: domainInput.value,
openId: openIdInput.value,
},
@ -14,9 +14,9 @@ saveButton.addEventListener("click", () => {
});
(async () => {
const corgiData = await getCorgiData();
if (corgiData) {
domainInput.value = corgiData.domain;
openIdInput.value = corgiData.openId;
const shortifyData = await getShortifyData();
if (shortifyData) {
domainInput.value = shortifyData.domain;
openIdInput.value = shortifyData.openId;
}
})();