Actualización iOS , pendiente añadir servidor y cambiar diseño de icono además de añadir diseño de logo.
This commit is contained in:
parent
92cc5a4ec4
commit
69c26b4bbb
14 changed files with 296 additions and 158 deletions
|
|
@ -33,7 +33,11 @@ class ViewController: PlatformViewController, WKNavigationDelegate, WKScriptMess
|
||||||
|
|
||||||
self.webView.configuration.userContentController.add(self, name: "controller")
|
self.webView.configuration.userContentController.add(self, name: "controller")
|
||||||
|
|
||||||
self.webView.loadFileURL(Bundle.main.url(forResource: "Main", withExtension: "html")!, allowingReadAccessTo: Bundle.main.resourceURL!)
|
guard let htmlURL = Bundle.main.url(forResource: "Main", withExtension: "html"),
|
||||||
|
let resourceURL = Bundle.main.resourceURL else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.webView.loadFileURL(htmlURL, allowingReadAccessTo: resourceURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||||
|
|
@ -61,7 +65,7 @@ class ViewController: PlatformViewController, WKNavigationDelegate, WKScriptMess
|
||||||
|
|
||||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
if (message.body as! String != "open-preferences") {
|
guard let body = message.body as? String, body == "open-preferences" else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"extension_name": {
|
"extension_name": {
|
||||||
"message": "Shortwaifus",
|
"message": "Short Waifus",
|
||||||
"description": "The display name for the extension."
|
"description": "The display name for the extension."
|
||||||
},
|
},
|
||||||
"extension_description": {
|
"extension_description": {
|
||||||
"message": "This is Shortwaifus. You should tell us what your extension does here.",
|
"message": "URL Shortener using YOURLS.",
|
||||||
"description": "Description of what the extension does."
|
"description": "Description of what the extension does."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1 @@
|
||||||
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
// Background script for ShortWaifus Safari Extension
|
||||||
console.log("Received request: ", request);
|
|
||||||
|
|
||||||
if (request.greeting === "hello")
|
|
||||||
return Promise.resolve({ farewell: "goodbye" });
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.action.onClicked.addListener((tab) => {
|
|
||||||
browser.tabs.sendMessage(tab.id, {
|
|
||||||
action: "shortenURL"
|
|
||||||
}).catch(error => {
|
|
||||||
console.error("Error sending message to content script:", error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1 @@
|
||||||
browser.runtime.sendMessage({ greeting: "hello" }).then((response) => {
|
// Content script for ShortWaifus Safari Extension
|
||||||
console.log("Received response: ", response);
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
||||||
console.log("Received request: ", request);
|
|
||||||
if (request.action === "shortenURL") {
|
|
||||||
const currentURL = window.location.href;
|
|
||||||
browser.runtime.sendNativeMessage("cc.waifus.ShortWaifus.Extension", currentURL)
|
|
||||||
.then(response => {
|
|
||||||
if (response && !response.startsWith("Error:")) {
|
|
||||||
navigator.clipboard.writeText(response)
|
|
||||||
.then(() => {
|
|
||||||
alert(`URL acortada y copiada al portapapeles:\n${response}`);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
alert(`URL acortada: ${response}\n(No se pudo copiar al portapapeles)`);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
alert(`Error al acortar la URL: ${response}`);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
alert("Error al comunicarse con la extensión");
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
|
|
||||||
"name": "Short Waifus",
|
"name": "Short Waifus",
|
||||||
"description": "URL Shortener for waifus.cc",
|
"description": "URL Shortener using YOURLS",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "Assets.xcassets/icon-48.imageset/icon-48.png",
|
"48": "images/icon-48.png",
|
||||||
"96": "Assets.xcassets/icon-96.imageset/icon-96.png",
|
"64": "images/icon-64.png",
|
||||||
"128": "Assets.xcassets/icon-128.imageset/icon-128.png",
|
"96": "images/icon-96.png",
|
||||||
"256": "Assets.xcassets/icon-256.imageset/icon-256.png",
|
"128": "images/icon-128.png",
|
||||||
"512": "Assets.xcassets/icon-512.imageset/icon-512.png"
|
"256": "images/icon-256.png",
|
||||||
|
"512": "images/icon-512.png"
|
||||||
},
|
},
|
||||||
|
|
||||||
"background": {
|
"background": {
|
||||||
|
|
@ -19,20 +20,12 @@
|
||||||
"type": "module"
|
"type": "module"
|
||||||
},
|
},
|
||||||
|
|
||||||
"content_scripts": [{
|
|
||||||
"js": [ "content.js" ],
|
|
||||||
"matches": [ "<all_urls>" ]
|
|
||||||
}],
|
|
||||||
|
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "popup.html",
|
"default_popup": "popup.html",
|
||||||
"default_icon": {
|
"default_icon": {
|
||||||
"16": "Assets.xcassets/toolbar-icon-16.imageset/toolbar-icon-16.png",
|
"48": "images/icon-48.png",
|
||||||
"19": "Assets.xcassets/toolbar-icon-19.imageset/toolbar-icon-19.png",
|
"96": "images/icon-96.png",
|
||||||
"32": "Assets.xcassets/toolbar-icon-32.imageset/toolbar-icon-32.png",
|
"128": "images/icon-128.png"
|
||||||
"38": "Assets.xcassets/toolbar-icon-38.imageset/toolbar-icon-38.png",
|
|
||||||
"48": "Assets.xcassets/toolbar-icon-48.imageset/toolbar-icon-48.png",
|
|
||||||
"72": "Assets.xcassets/toolbar-icon-72.imageset/toolbar-icon-72.png"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
:root {
|
:root {
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
|
--background-color: #ffffff;
|
||||||
|
--text-color: #000000;
|
||||||
|
--result-background: #f2f2f7;
|
||||||
|
--history-background: #f2f2f7;
|
||||||
|
--border-color: #c7c7cc;
|
||||||
|
--url-color: #007AFF;
|
||||||
|
--url-background: #f2f2f7;
|
||||||
|
--input-background: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|
@ -16,7 +24,105 @@ body {
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--text-color);
|
||||||
|
opacity: 0.5;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon:hover {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: var(--result-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background-color: var(--result-background);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-section label {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-color);
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-row input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
background-color: var(--input-background);
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-small {
|
||||||
|
width: auto;
|
||||||
|
padding: 8px 14px;
|
||||||
|
background-color: #007AFF;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-small:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-status {
|
||||||
|
font-size: 11px;
|
||||||
|
min-height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-status.saved {
|
||||||
|
color: #34c759;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-status.error {
|
||||||
|
color: #ff3b30;
|
||||||
|
}
|
||||||
|
|
||||||
|
button#shortenButton {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
background-color: #007AFF;
|
background-color: #007AFF;
|
||||||
|
|
@ -28,7 +134,7 @@ button {
|
||||||
transition: background-color 0.2s;
|
transition: background-color 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button#shortenButton:hover {
|
||||||
background-color: #0056b3;
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,17 +216,6 @@ button:hover {
|
||||||
--border-color: #3a3a3c;
|
--border-color: #3a3a3c;
|
||||||
--url-color: #8e8e93;
|
--url-color: #8e8e93;
|
||||||
--url-background: #2c2c2e;
|
--url-background: #2c2c2e;
|
||||||
}
|
--input-background: #2c2c2e;
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
--background-color: #ffffff;
|
|
||||||
--text-color: #000000;
|
|
||||||
--result-background: #f2f2f7;
|
|
||||||
--history-background: #f2f2f7;
|
|
||||||
--border-color: #c7c7cc;
|
|
||||||
--url-color: #007AFF;
|
|
||||||
--url-background: #f2f2f7;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,23 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="header">
|
||||||
|
<span class="header-title">Short Waifus</span>
|
||||||
|
<button id="settingsToggle" class="btn-icon" title="Configuración">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
||||||
|
<path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492zM5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0z"/>
|
||||||
|
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.421 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.421-1.184-1.185l.159-.291a1.873 1.873 0 0 0-1.116-2.693l-.318-.094c-.835-.246-.835-1.428 0-1.674l.319-.094a1.873 1.873 0 0 0 1.115-2.692l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.116l.094-.318z"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div id="config-section" class="config-section hidden">
|
||||||
|
<label for="signatureInput">API Signature</label>
|
||||||
|
<div class="input-row">
|
||||||
|
<input type="password" id="signatureInput" placeholder="Tu firma de API YOURLS">
|
||||||
|
<button id="saveSignature" class="btn-small">Guardar</button>
|
||||||
|
</div>
|
||||||
|
<div id="configStatus" class="config-status"></div>
|
||||||
|
</div>
|
||||||
<button id="shortenButton">Acortar URL</button>
|
<button id="shortenButton">Acortar URL</button>
|
||||||
<div id="result"></div>
|
<div id="result"></div>
|
||||||
<div class="history-section">
|
<div class="history-section">
|
||||||
|
|
|
||||||
|
|
@ -1,63 +1,125 @@
|
||||||
console.log("Hello World!", browser);
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const shortenButton = document.getElementById('shortenButton');
|
const shortenButton = document.getElementById('shortenButton');
|
||||||
const resultDiv = document.getElementById('result');
|
const resultDiv = document.getElementById('result');
|
||||||
const historyDiv = document.getElementById('history');
|
const historyDiv = document.getElementById('history');
|
||||||
|
const signatureInput = document.getElementById('signatureInput');
|
||||||
|
const saveSignatureBtn = document.getElementById('saveSignature');
|
||||||
|
const configStatus = document.getElementById('configStatus');
|
||||||
|
const configSection = document.getElementById('config-section');
|
||||||
|
const settingsToggle = document.getElementById('settingsToggle');
|
||||||
|
|
||||||
// Cargar historial al iniciar
|
// Cargar firma guardada e historial al iniciar
|
||||||
|
loadSignature();
|
||||||
loadHistory();
|
loadHistory();
|
||||||
|
|
||||||
|
settingsToggle.addEventListener('click', function() {
|
||||||
|
configSection.classList.toggle('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
saveSignatureBtn.addEventListener('click', function() {
|
||||||
|
const signature = signatureInput.value.trim();
|
||||||
|
if (!signature) {
|
||||||
|
configStatus.textContent = 'Ingresa una firma válida';
|
||||||
|
configStatus.className = 'config-status error';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
browser.storage.local.set({ apiSignature: signature })
|
||||||
|
.then(() => {
|
||||||
|
configStatus.textContent = 'Firma guardada';
|
||||||
|
configStatus.className = 'config-status saved';
|
||||||
|
setTimeout(function() {
|
||||||
|
configSection.classList.add('hidden');
|
||||||
|
}, 800);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error al guardar firma:', error);
|
||||||
|
configStatus.textContent = 'Error al guardar';
|
||||||
|
configStatus.className = 'config-status error';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
shortenButton.addEventListener('click', function() {
|
shortenButton.addEventListener('click', function() {
|
||||||
console.log("Botón clickeado");
|
browser.storage.local.get('apiSignature')
|
||||||
browser.tabs.query({active: true, currentWindow: true})
|
.then(data => {
|
||||||
|
const signature = data.apiSignature;
|
||||||
|
if (!signature) {
|
||||||
|
resultDiv.className = '';
|
||||||
|
resultDiv.textContent = 'Configura tu firma de API primero';
|
||||||
|
resultDiv.style.color = 'red';
|
||||||
|
configSection.classList.remove('hidden');
|
||||||
|
throw new Error('No API signature configured');
|
||||||
|
}
|
||||||
|
return browser.tabs.query({ active: true, currentWindow: true })
|
||||||
.then(tabs => {
|
.then(tabs => {
|
||||||
console.log("Tabs encontrados:", tabs);
|
|
||||||
if (!tabs || tabs.length === 0) {
|
if (!tabs || tabs.length === 0) {
|
||||||
throw new Error("No se pudo encontrar la pestaña activa");
|
throw new Error('No se pudo encontrar la pestaña activa');
|
||||||
}
|
}
|
||||||
const currentUrl = tabs[0].url;
|
const currentUrl = tabs[0].url;
|
||||||
console.log("URL actual:", currentUrl);
|
return browser.runtime.sendNativeMessage(
|
||||||
return browser.runtime.sendNativeMessage("cc.waifus.ShortWaifus.Extension", currentUrl);
|
"cc.waifus.Shortwaifus.Extension",
|
||||||
|
{ url: currentUrl, signature: signature }
|
||||||
|
);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log("Respuesta recibida:", response);
|
if (response && !response.startsWith('Error:')) {
|
||||||
if (response && !response.startsWith("Error:")) {
|
|
||||||
navigator.clipboard.writeText(response)
|
navigator.clipboard.writeText(response)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resultDiv.className = 'success';
|
showResult('URL acortada y copiada al portapapeles', response);
|
||||||
resultDiv.innerHTML = `
|
|
||||||
<div class="status">URL acortada y copiada al portapapeles</div>
|
|
||||||
<div class="url">${response}</div>
|
|
||||||
`;
|
|
||||||
saveToHistory(response);
|
saveToHistory(response);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(() => {
|
||||||
console.error("Error al copiar al portapapeles:", err);
|
showResult('URL acortada (no se pudo copiar)', response);
|
||||||
resultDiv.className = 'success';
|
|
||||||
resultDiv.innerHTML = `
|
|
||||||
<div class="status">URL acortada (no se pudo copiar)</div>
|
|
||||||
<div class="url">${response}</div>
|
|
||||||
`;
|
|
||||||
saveToHistory(response);
|
saveToHistory(response);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
resultDiv.className = '';
|
resultDiv.className = '';
|
||||||
resultDiv.textContent = `Error: ${response}`;
|
resultDiv.textContent = 'Error: ' + response;
|
||||||
resultDiv.style.color = 'red';
|
resultDiv.style.color = 'red';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Error en el proceso:", error);
|
if (error.message !== 'No API signature configured') {
|
||||||
resultDiv.className = '';
|
resultDiv.className = '';
|
||||||
resultDiv.textContent = "Error al acortar la URL: " + error.message;
|
resultDiv.textContent = 'Error al acortar la URL: ' + error.message;
|
||||||
resultDiv.style.color = 'red';
|
resultDiv.style.color = 'red';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function showResult(statusText, url) {
|
||||||
|
resultDiv.className = 'success';
|
||||||
|
resultDiv.innerHTML = '';
|
||||||
|
const status = document.createElement('div');
|
||||||
|
status.className = 'status';
|
||||||
|
status.textContent = statusText;
|
||||||
|
const urlDiv = document.createElement('div');
|
||||||
|
urlDiv.className = 'url';
|
||||||
|
urlDiv.textContent = url;
|
||||||
|
resultDiv.appendChild(status);
|
||||||
|
resultDiv.appendChild(urlDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadSignature() {
|
||||||
|
browser.storage.local.get('apiSignature')
|
||||||
|
.then(data => {
|
||||||
|
if (data.apiSignature) {
|
||||||
|
signatureInput.value = data.apiSignature;
|
||||||
|
configSection.classList.add('hidden');
|
||||||
|
} else {
|
||||||
|
configSection.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error al cargar firma:', error);
|
||||||
|
configSection.classList.remove('hidden');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function saveToHistory(shortUrl) {
|
function saveToHistory(shortUrl) {
|
||||||
browser.tabs.query({ active: true, currentWindow: true })
|
browser.tabs.query({ active: true, currentWindow: true })
|
||||||
.then(tabs => {
|
.then(tabs => {
|
||||||
|
if (!tabs || tabs.length === 0) return;
|
||||||
const currentTab = tabs[0];
|
const currentTab = tabs[0];
|
||||||
const historyItem = {
|
const historyItem = {
|
||||||
title: currentTab.title,
|
title: currentTab.title,
|
||||||
|
|
@ -65,22 +127,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
|
||||||
browser.storage.local.get('history')
|
return browser.storage.local.get('history')
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let history = data.history || [];
|
let history = data.history || [];
|
||||||
history.unshift(historyItem);
|
history.unshift(historyItem);
|
||||||
history = history.slice(0, 5);
|
history = history.slice(0, 5);
|
||||||
return browser.storage.local.set({ history: history });
|
return browser.storage.local.set({ history: history });
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => loadHistory());
|
||||||
loadHistory();
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Error al guardar en historial:", error);
|
console.error('Error al guardar en historial:', error);
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error("Error al obtener información de la pestaña:", error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +165,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Error al cargar historial:", error);
|
console.error('Error al cargar historial:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,33 @@ import Foundation
|
||||||
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||||
|
|
||||||
func beginRequest(with context: NSExtensionContext) {
|
func beginRequest(with context: NSExtensionContext) {
|
||||||
let item = context.inputItems[0] as! NSExtensionItem
|
guard let item = context.inputItems.first as? NSExtensionItem,
|
||||||
let message = item.userInfo?[SFExtensionMessageKey]
|
let message = item.userInfo?[SFExtensionMessageKey] as? [String: String],
|
||||||
|
let urlString = message["url"],
|
||||||
|
let signature = message["signature"] else {
|
||||||
|
let response = NSExtensionItem()
|
||||||
|
response.userInfo = [SFExtensionMessageKey: "Error: Invalid request"]
|
||||||
|
context.completeRequest(returningItems: [response], completionHandler: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if let url = message as? String {
|
shortenURL(urlString: urlString, signature: signature) { shortUrl in
|
||||||
shortenURL(urlString: url) { shortUrl in
|
|
||||||
let response = NSExtensionItem()
|
let response = NSExtensionItem()
|
||||||
response.userInfo = [SFExtensionMessageKey: shortUrl]
|
response.userInfo = [SFExtensionMessageKey: shortUrl]
|
||||||
context.completeRequest(returningItems: [response], completionHandler: nil)
|
context.completeRequest(returningItems: [response], completionHandler: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private func shortenURL(urlString: String, completion: @escaping (String) -> Void) {
|
private func shortenURL(urlString: String, signature: String, completion: @escaping (String) -> Void) {
|
||||||
guard let encodedUrl = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
|
guard let encodedUrl = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
|
||||||
let apiUrl = URL(string: "https://short.waifus.cc/yourls-api.php?signature=215c678cd4&action=shorturl&url=\(encodedUrl)&format=json") else {
|
let encodedSignature = signature.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
|
||||||
|
let apiUrl = URL(string: "https://short.waifus.cc/yourls-api.php?signature=\(encodedSignature)&action=shorturl&url=\(encodedUrl)&format=json") else {
|
||||||
NSLog("Invalid URL: %@", urlString)
|
NSLog("Invalid URL: %@", urlString)
|
||||||
completion("Error: Invalid URL")
|
completion("Error: Invalid URL")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let task = URLSession.shared.dataTask(with: apiUrl) { data, response, error in
|
let task = URLSession.shared.dataTask(with: apiUrl) { data, _, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
NSLog("Network error: %@", error.localizedDescription)
|
NSLog("Network error: %@", error.localizedDescription)
|
||||||
completion("Error: Network request failed")
|
completion("Error: Network request failed")
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@
|
||||||
attributes = {
|
attributes = {
|
||||||
BuildIndependentTargetsInParallel = 1;
|
BuildIndependentTargetsInParallel = 1;
|
||||||
LastSwiftUpdateCheck = 1630;
|
LastSwiftUpdateCheck = 1630;
|
||||||
LastUpgradeCheck = 1630;
|
LastUpgradeCheck = 2630;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
2F9376272DB9AF5D006E9AC3 = {
|
2F9376272DB9AF5D006E9AC3 = {
|
||||||
CreatedOnToolsVersion = 16.3;
|
CreatedOnToolsVersion = 16.3;
|
||||||
|
|
@ -605,7 +605,11 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Shortwaifus.entitlements";
|
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Shortwaifus.entitlements";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
|
||||||
|
ENABLE_USER_SELECTED_FILES = readonly;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
|
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
|
||||||
INFOPLIST_KEY_CFBundleDisplayName = "Shortwaifus Extension";
|
INFOPLIST_KEY_CFBundleDisplayName = "Shortwaifus Extension";
|
||||||
|
|
@ -615,7 +619,7 @@
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
"@executable_path/../../../../Frameworks",
|
"@executable_path/../../../../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-framework",
|
"-framework",
|
||||||
|
|
@ -636,7 +640,11 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Shortwaifus.entitlements";
|
CODE_SIGN_ENTITLEMENTS = "macOS (Extension)/Shortwaifus.entitlements";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
|
||||||
|
ENABLE_USER_SELECTED_FILES = readonly;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
|
INFOPLIST_FILE = "macOS (Extension)/Info.plist";
|
||||||
INFOPLIST_KEY_CFBundleDisplayName = "Shortwaifus Extension";
|
INFOPLIST_KEY_CFBundleDisplayName = "Shortwaifus Extension";
|
||||||
|
|
@ -646,7 +654,7 @@
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
"@executable_path/../../../../Frameworks",
|
"@executable_path/../../../../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-framework",
|
"-framework",
|
||||||
|
|
@ -669,7 +677,11 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Shortwaifus.entitlements";
|
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Shortwaifus.entitlements";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
|
||||||
|
ENABLE_USER_SELECTED_FILES = readonly;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_CFBundleDisplayName = Shortwaifus;
|
INFOPLIST_KEY_CFBundleDisplayName = Shortwaifus;
|
||||||
INFOPLIST_KEY_NSMainStoryboardFile = Main;
|
INFOPLIST_KEY_NSMainStoryboardFile = Main;
|
||||||
|
|
@ -678,7 +690,7 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-framework",
|
"-framework",
|
||||||
|
|
@ -703,7 +715,11 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Shortwaifus.entitlements";
|
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Shortwaifus.entitlements";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
|
||||||
|
ENABLE_USER_SELECTED_FILES = readonly;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_CFBundleDisplayName = Shortwaifus;
|
INFOPLIST_KEY_CFBundleDisplayName = Shortwaifus;
|
||||||
INFOPLIST_KEY_NSMainStoryboardFile = Main;
|
INFOPLIST_KEY_NSMainStoryboardFile = Main;
|
||||||
|
|
@ -712,7 +728,7 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-framework",
|
"-framework",
|
||||||
|
|
@ -763,6 +779,7 @@
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
ENABLE_TESTABILITY = YES;
|
ENABLE_TESTABILITY = YES;
|
||||||
|
|
@ -785,6 +802,7 @@
|
||||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
};
|
};
|
||||||
|
|
@ -824,6 +842,7 @@
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
|
@ -839,6 +858,7 @@
|
||||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -7,12 +7,12 @@
|
||||||
<key>Shortwaifus (iOS).xcscheme_^#shared#^_</key>
|
<key>Shortwaifus (iOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Shortwaifus (macOS).xcscheme_^#shared#^_</key>
|
<key>Shortwaifus (macOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict/>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.files.user-selected.read-only</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.network.client</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.files.user-selected.read-only</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.network.client</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.web-extension</key>
|
<key>com.apple.security.web-extension</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue