Skip to content

Commit

Permalink
feat: Pré-remplir avec le presse-papier.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Sep 20, 2022
1 parent 187060a commit fcfb0ea
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 101 deletions.
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
"options_generalHistoryInput_textcontent": {
"message": "Add casted links in browser history"
},
"options_generalClipboardInput_textcontent": {
"message": "Prefill the input field in the popup with the content of the clipboard"
},
"options_menuTitle_textcontent": {
"message": "Context menu"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
"options_generalHistoryInput_textcontent": {
"message": "Añadir enlaces transmitidos al historial del navegador"
},
"options_generalClipboardInput_textcontent": {
"message": "Rellenar el campo de entrada en la ventana emergente con el contenido del portapapeles"
},
"options_menuTitle_textcontent": {
"message": "Menú contextual"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
"options_generalHistoryInput_textcontent": {
"message": "Ajouter les liens diffusés sur Kodi dans l'historique du navigateur"
},
"options_generalClipboardInput_textcontent": {
"message": "Pré-remplir le champ de saisie dans la popup avec le contenu du presse-papier"
},
"options_menuTitle_textcontent": {
"message": "Menu contextuel"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/sk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
"options_generalHistoryInput_textcontent": {
"message": "Pridať odoslané odkazy do histórie prehliadača"
},
"options_generalClipboardInput_textcontent": {
"message": "Predvyplňte vstupné pole vo vyskakovacom okne obsahom schránky"
},
"options_menuTitle_textcontent": {
"message": "Kontextová ponuka"
},
Expand Down
38 changes: 29 additions & 9 deletions src/core/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export const initialize = async function () {
const { name } = await browser.runtime.getBrowserInfo();

await browser.storage.local.set({
"config-version": 4,
"server-mode": "single",
"server-list": [{ address: "", name: "" }],
"server-active": 0,
"general-history": false,
"menu-actions": ["send", "insert", "add"],
"menu-contexts": DEFAULT_MENU_CONTEXTS[name],
"youtube-playlist": "playlist",
"youtube-order": "default",
"config-version": 5,
"server-mode": "single",
"server-list": [{ address: "", name: "" }],
"server-active": 0,
"general-history": false,
"general-clipboard": false,
"menu-actions": ["send", "insert", "add"],
"menu-contexts": DEFAULT_MENU_CONTEXTS[name],
"youtube-playlist": "playlist",
"youtube-order": "default",
});
};

Expand All @@ -39,6 +40,9 @@ export const initialize = async function () {
*/
export const migrate = async function () {
let config = await browser.storage.local.get();

// Regrouper les propriétés des menus et des contextes dans deux
// propriétés ; et permettre la configuration de plusieurs serveurs.
if (1 === config["config-version"]) {
const actions = Object.entries(config)
.filter(([k, v]) => k.startsWith("menus-") && v)
Expand All @@ -62,6 +66,9 @@ export const migrate = async function () {
"youtube-playlist": config["youtube-playlist"],
};
}

// Renommer les propriétés "host" en "address" car elles peuvent maintenant
// contenir une adresse IP ou une adresse complête.
if (2 === config["config-version"]) {
const servers = config["server-list"].map((server) => ({
address: server.host,
Expand All @@ -71,11 +78,19 @@ export const migrate = async function () {
config["config-version"] = 3;
config["server-list"] = servers;
}

// Ajouter une propriété pour définir l'ordre des playlists YouTube.
if (3 === config["config-version"]) {
config["config-version"] = 4;
config["youtube-order"] = "";
}

// Ajouter une propriété pour indiquer s'il faut lire dans le presse-papier.
if (4 === config["config-version"]) {
config["config-version"] = 5;
config["general-clipboard"] = false;
}

// Vider la configuration pour enlever les éventuelles propriétés obsolètes.
// Et aussi pour forcer l'appel à l'écouteur browser.storage.onChanged sous
// Chromium même si la méthode browser.storage.local.set() ne modifie pas la
Expand All @@ -94,6 +109,11 @@ export const remove = async function (permissions) {
if (permissions.includes("history")) {
await browser.storage.local.set({ "general-history": false });
}

if (permissions.includes("clipboardRead")) {
await browser.storage.local.set({ "general-clipboard": false });
}

if (permissions.includes("bookmarks")) {
const config = await browser.storage.local.get(["menu-contexts"]);
const contexts = config["menu-contexts"];
Expand Down
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"minimum_chrome_version": "103",
"optional_permissions": [
"bookmarks",
"clipboardRead",
"history"
],
"options_ui": {
Expand Down
8 changes: 8 additions & 0 deletions src/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ <h3 data-i18n-textcontent="general-title"></h3>
</label>
</div>
</form>
<form id="general-clipboard">
<div>
<label data-i18n-textcontent="general-clipboard-input">
<input name="clipboard" type="checkbox"
data-permissions="clipboardRead"> {}
</label>
</div>
</form>

<h3 data-i18n-textcontent="menu-title"></h3>
<form id="menu-actions">
Expand Down
22 changes: 17 additions & 5 deletions src/popup/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const add = async function () {
}
};

const paste = function (event) {
const paste = async function (event) {
// Annuler l'action (venant d'un raccourci clavier) si le bouton est
// désactivé.
if (document.querySelector("#paste input").disabled) {
Expand All @@ -139,7 +139,19 @@ const paste = function (event) {
for (const section of document.querySelectorAll("section:not(#cast)")) {
section.style.visibility = "hidden";
}
document.querySelector("textarea").focus();

const textarea = document.querySelector("textarea");
// Pré-remplir le champ (avec la valeur du presse-papier) seulement si
// le champ est vide.
if ("" === textarea.value) {
const config = await browser.storage.local.get([
"general-clipboard",
]);
if (config["general-clipboard"]) {
textarea.value = await navigator.clipboard.readText();
}
}
textarea.focus();
} else {
for (const section of document.querySelectorAll("section:not(#cast)")) {
section.style.visibility = "visible";
Expand Down Expand Up @@ -1088,8 +1100,8 @@ const load = async function () {
document.querySelector("#send").addEventListener("click", send);
document.querySelector("#insert").addEventListener("click", insert);
document.querySelector("#add").addEventListener("click", add);
document.querySelector("#paste").addEventListener("change", paste);
for (const input of document.querySelectorAll("select")) {
document.querySelector("#paste input").addEventListener("change", paste);
for (const input of document.querySelectorAll("#server select")) {
input.addEventListener("change", change);
}

Expand Down Expand Up @@ -1130,7 +1142,7 @@ document.querySelector("#openquit").addEventListener("click", openQuit);
for (const input of document.querySelectorAll("#repeat input")) {
input.addEventListener("click", repeat);
}
document.querySelector("#shuffle").addEventListener("change", shuffle);
document.querySelector("#shuffle input").addEventListener("change", shuffle);
document.querySelector("#clear").addEventListener("click", clear);

document.querySelector("#web").addEventListener("click", web);
Expand Down
Loading

0 comments on commit fcfb0ea

Please sign in to comment.