mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-08 20:19:06 +03:00
init
This commit is contained in:
77
popup/popup.css
Normal file
77
popup/popup.css
Normal file
@@ -0,0 +1,77 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
width: 360px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: #f9f9f9;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.4em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
textarea,
|
||||
select {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 8px;
|
||||
padding: 6px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
textarea {
|
||||
height: 60px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
button {
|
||||
margin: 4px 2px;
|
||||
padding: 6px 10px;
|
||||
font-size: 0.9em;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
#wordList > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 6px;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
#wordList input[type="text"] {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
#wordList input[type="color"] {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
51
popup/popup.html
Normal file
51
popup/popup.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><span data-i18n="extension_name"></span></title>
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 data-i18n="extension_name">Goose Highlighter</h1>
|
||||
|
||||
<div class="section">
|
||||
<label for="listSelect" data-i18n="select_list">Select List:</label>
|
||||
<select id="listSelect"></select>
|
||||
<button id="newListBtn" data-i18n="new_list">+ New List</button>
|
||||
<button id="deleteListBtn" data-i18n="delete_list">Delete List</button>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<label><span data-i18n="list_name">List Name:</span> <input type="text" id="listName"></label>
|
||||
<label><span data-i18n="background">Background:</span> <input type="color" id="listBg"></label>
|
||||
<label><span data-i18n="foreground">Foreground:</span> <input type="color" id="listFg"></label>
|
||||
<label><input type="checkbox" id="listActive"> <span data-i18n="enable_highlight">Enable Highlight</span></label>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<textarea id="bulkPaste" data-i18n="paste_hint" placeholder="Paste words here..."></textarea>
|
||||
<button id="addWordsBtn" data-i18n="apply_paste">Add Words</button>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<button id="selectAllBtn" data-i18n="select_all">Select All</button>
|
||||
<button id="deleteSelectedBtn" data-i18n="delete_selected">Delete Selected</button>
|
||||
<button id="disableSelectedBtn" data-i18n="disable_selected">Disable Selected</button>
|
||||
<button id="enableSelectedBtn" data-i18n="enable_selected">Enable Selected</button>
|
||||
</div>
|
||||
|
||||
<div id="wordList"></div>
|
||||
|
||||
<div class="section">
|
||||
<button id="importBtn" data-i18n="import_list">Import JSON</button>
|
||||
<input type="file" id="importInput" accept="application/json" hidden>
|
||||
<button id="exportBtn" data-i18n="export_list">Export JSON</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../storage.js"></script>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
197
popup/popup.js
Normal file
197
popup/popup.js
Normal file
@@ -0,0 +1,197 @@
|
||||
const listSelect = document.getElementById("listSelect");
|
||||
const listName = document.getElementById("listName");
|
||||
const listBg = document.getElementById("listBg");
|
||||
const listFg = document.getElementById("listFg");
|
||||
const listActive = document.getElementById("listActive");
|
||||
const bulkPaste = document.getElementById("bulkPaste");
|
||||
const wordList = document.getElementById("wordList");
|
||||
const importInput = document.getElementById("importInput");
|
||||
|
||||
let lists = [];
|
||||
let currentListIndex = 0;
|
||||
|
||||
async function save() {
|
||||
await chrome.storage.local.set({ lists });
|
||||
renderLists();
|
||||
renderWords();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const res = await chrome.storage.local.get("lists");
|
||||
lists = res.lists || [];
|
||||
if (!lists.length) {
|
||||
lists.push({
|
||||
id: Date.now(),
|
||||
name: chrome.i18n.getMessage("default_list_name"),
|
||||
background: "#ffff00",
|
||||
foreground: "#000000",
|
||||
active: true,
|
||||
words: []
|
||||
});
|
||||
}
|
||||
renderLists();
|
||||
renderWords();
|
||||
}
|
||||
|
||||
function renderLists() {
|
||||
listSelect.innerHTML = lists.map((list, index) => `<option value="${index}">${list.name}</option>`).join("");
|
||||
listSelect.value = currentListIndex;
|
||||
updateListForm();
|
||||
}
|
||||
|
||||
function updateListForm() {
|
||||
const list = lists[currentListIndex];
|
||||
listName.value = list.name;
|
||||
listBg.value = list.background;
|
||||
listFg.value = list.foreground;
|
||||
listActive.checked = list.active;
|
||||
}
|
||||
|
||||
function renderWords() {
|
||||
const list = lists[currentListIndex];
|
||||
wordList.innerHTML = list.words.map((w, i) => `
|
||||
<div>
|
||||
<input type="checkbox" data-index="${i}">
|
||||
<input value="${w.wordStr}" data-word-edit="${i}">
|
||||
<input type="color" value="${w.background || list.background}" data-bg-edit="${i}">
|
||||
<input type="color" value="${w.foreground || list.foreground}" data-fg-edit="${i}">
|
||||
<label><input type="checkbox" ${w.active ? "checked" : ""} data-active-edit="${i}"> ${chrome.i18n.getMessage("word_active_label")}</label>
|
||||
</div>
|
||||
`).join("");
|
||||
}
|
||||
|
||||
listSelect.onchange = () => {
|
||||
currentListIndex = +listSelect.value;
|
||||
renderWords();
|
||||
updateListForm();
|
||||
};
|
||||
|
||||
document.getElementById("newListBtn").onclick = () => {
|
||||
lists.push({
|
||||
id: Date.now(),
|
||||
name: chrome.i18n.getMessage("new_list_name"),
|
||||
background: "#ffff00",
|
||||
foreground: "#000000",
|
||||
active: true,
|
||||
words: []
|
||||
});
|
||||
currentListIndex = lists.length - 1;
|
||||
save();
|
||||
};
|
||||
|
||||
document.getElementById("deleteListBtn").onclick = () => {
|
||||
if (confirm(chrome.i18n.getMessage("confirm_delete_list"))) {
|
||||
lists.splice(currentListIndex, 1);
|
||||
currentListIndex = Math.max(0, currentListIndex - 1);
|
||||
save();
|
||||
}
|
||||
};
|
||||
|
||||
listName.oninput = () => { lists[currentListIndex].name = listName.value; save(); };
|
||||
listBg.oninput = () => { lists[currentListIndex].background = listBg.value; save(); };
|
||||
listFg.oninput = () => { lists[currentListIndex].foreground = listFg.value; save(); };
|
||||
listActive.onchange = () => { lists[currentListIndex].active = listActive.checked; save(); };
|
||||
|
||||
document.getElementById("addWordsBtn").onclick = () => {
|
||||
const words = bulkPaste.value.split(/\n+/).map(w => w.trim()).filter(Boolean);
|
||||
const list = lists[currentListIndex];
|
||||
for (const w of words) list.words.push({ wordStr: w, background: "", foreground: "", active: true });
|
||||
bulkPaste.value = "";
|
||||
save();
|
||||
};
|
||||
|
||||
document.getElementById("selectAllBtn").onclick = () => {
|
||||
wordList.querySelectorAll("input[type=checkbox]").forEach(cb => cb.checked = true);
|
||||
};
|
||||
|
||||
document.getElementById("deleteSelectedBtn").onclick = () => {
|
||||
if (confirm(chrome.i18n.getMessage("confirm_delete_words"))) {
|
||||
const list = lists[currentListIndex];
|
||||
const toDelete = [...wordList.querySelectorAll("input[type=checkbox]:checked")].map(cb => +cb.dataset.index);
|
||||
lists[currentListIndex].words = list.words.filter((_, i) => !toDelete.includes(i));
|
||||
save();
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById("disableSelectedBtn").onclick = () => {
|
||||
const list = lists[currentListIndex];
|
||||
wordList.querySelectorAll("input[type=checkbox]:checked").forEach(cb => list.words[+cb.dataset.index].active = false);
|
||||
save();
|
||||
};
|
||||
|
||||
document.getElementById("enableSelectedBtn").onclick = () => {
|
||||
const list = lists[currentListIndex];
|
||||
wordList.querySelectorAll("input[type=checkbox]:checked").forEach(cb => list.words[+cb.dataset.index].active = true);
|
||||
save();
|
||||
};
|
||||
|
||||
wordList.addEventListener("input", e => {
|
||||
const index = e.target.dataset.wordEdit ?? e.target.dataset.bgEdit ?? e.target.dataset.fgEdit;
|
||||
if (e.target.dataset.wordEdit != null) lists[currentListIndex].words[index].wordStr = e.target.value;
|
||||
if (e.target.dataset.bgEdit != null) lists[currentListIndex].words[index].background = e.target.value;
|
||||
if (e.target.dataset.fgEdit != null) lists[currentListIndex].words[index].foreground = e.target.value;
|
||||
save();
|
||||
});
|
||||
|
||||
wordList.addEventListener("change", e => {
|
||||
if (e.target.dataset.activeEdit != null) {
|
||||
lists[currentListIndex].words[e.target.dataset.activeEdit].active = e.target.checked;
|
||||
save();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const exportBtn = document.getElementById("exportBtn");
|
||||
exportBtn.onclick = () => {
|
||||
const blob = new Blob([JSON.stringify(lists, null, 2)], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "highlight-lists.json";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const importBtn = document.getElementById("importBtn");
|
||||
importBtn.onclick = () => importInput.click();
|
||||
|
||||
importInput.onchange = e => {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = e => {
|
||||
try {
|
||||
const data = JSON.parse(e.target.result);
|
||||
if (Array.isArray(data)) {
|
||||
lists = data;
|
||||
currentListIndex = 0;
|
||||
save();
|
||||
}
|
||||
} catch (err) {
|
||||
alert(chrome.i18n.getMessage("invalid_json_error"));
|
||||
}
|
||||
};
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
// Localize the page
|
||||
function localizePage() {
|
||||
// Localize all elements with a data-i18n attribute
|
||||
const elements = document.querySelectorAll('[data-i18n]');
|
||||
elements.forEach(element => {
|
||||
const message = element.dataset.i18n;
|
||||
const localizedText = chrome.i18n.getMessage(message);
|
||||
if (localizedText) {
|
||||
if (element.tagName === 'INPUT' && element.hasAttribute('placeholder')) {
|
||||
element.placeholder = localizedText;
|
||||
} else {
|
||||
element.textContent = localizedText;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Call this function when the page loads
|
||||
document.addEventListener('DOMContentLoaded', localizePage);
|
||||
|
||||
load();
|
||||
Reference in New Issue
Block a user