From 8f0f7fb9237343843193ffb4bf5f762e55905592 Mon Sep 17 00:00:00 2001
From: buzz-lightsnack-2007
<73412182+buzz-lightsnack-2007@users.noreply.github.com>
Date: Mon, 25 Mar 2024 12:39:38 +0800
Subject: [PATCH] major moving around of files
---
gui/pages/open/popup.htm | 5 +
gui/pages/open/settings.htm | 5 +
gui/pages/settings.htm | 70 +++++
gui/pages/settings/filters.htm | 0
gui/popup.htm | 3 +-
gui/popup_r.htm | 5 -
.../{popup_r.JS => pages/open/popup.JS} | 4 +-
.../{settings_r.JS => pages/open/settings.JS} | 4 +-
gui/scripts/popup.js | 57 +---
gui/scripts/read.JS | 25 +-
gui/scripts/settings.JS | 245 +++++++++++-------
gui/scripts/windowman.JS | 37 ++-
gui/settings.htm | 70 -----
gui/settings_r.htm | 5 -
manifest.json | 8 +-
15 files changed, 303 insertions(+), 240 deletions(-)
create mode 100644 gui/pages/open/popup.htm
create mode 100644 gui/pages/open/settings.htm
create mode 100644 gui/pages/settings.htm
create mode 100644 gui/pages/settings/filters.htm
delete mode 100644 gui/popup_r.htm
rename gui/scripts/{popup_r.JS => pages/open/popup.JS} (50%)
rename gui/scripts/{settings_r.JS => pages/open/settings.JS} (59%)
delete mode 100644 gui/settings.htm
delete mode 100644 gui/settings_r.htm
diff --git a/gui/pages/open/popup.htm b/gui/pages/open/popup.htm
new file mode 100644
index 0000000..87f4450
--- /dev/null
+++ b/gui/pages/open/popup.htm
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/gui/pages/open/settings.htm b/gui/pages/open/settings.htm
new file mode 100644
index 0000000..ae7db14
--- /dev/null
+++ b/gui/pages/open/settings.htm
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/gui/pages/settings.htm b/gui/pages/settings.htm
new file mode 100644
index 0000000..ee895dc
--- /dev/null
+++ b/gui/pages/settings.htm
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/gui/pages/settings/filters.htm b/gui/pages/settings/filters.htm
new file mode 100644
index 0000000..e69de29
diff --git a/gui/popup.htm b/gui/popup.htm
index f31b5c2..5b33165 100644
--- a/gui/popup.htm
+++ b/gui/popup.htm
@@ -1,4 +1,3 @@
-
-
+
diff --git a/gui/popup_r.htm b/gui/popup_r.htm
deleted file mode 100644
index bd8b4f1..0000000
--- a/gui/popup_r.htm
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/gui/scripts/popup_r.JS b/gui/scripts/pages/open/popup.JS
similarity index 50%
rename from gui/scripts/popup_r.JS
rename to gui/scripts/pages/open/popup.JS
index 1ed1e94..addb39f 100644
--- a/gui/scripts/popup_r.JS
+++ b/gui/scripts/pages/open/popup.JS
@@ -1,7 +1,7 @@
-import {windowman} from './windowman.JS';
+import {windowman} from '../../windowman.JS';
function redirect() {
- new windowman(`gui/popup.htm`);
+ new windowman(`gui/pages/settings.htm`);
window.close();
}
diff --git a/gui/scripts/settings_r.JS b/gui/scripts/pages/open/settings.JS
similarity index 59%
rename from gui/scripts/settings_r.JS
rename to gui/scripts/pages/open/settings.JS
index 5b26d96..7a94a88 100644
--- a/gui/scripts/settings_r.JS
+++ b/gui/scripts/pages/open/settings.JS
@@ -1,9 +1,9 @@
// Open the settings in a pop-up window.
-import {windowman} from './windowman.JS';
+import {windowman} from '../../windowman.JS';
function redirect() {
- new windowman(`gui/settings.htm`);
+ new windowman(`gui/pages/settings.htm`);
window.close();
}
diff --git a/gui/scripts/popup.js b/gui/scripts/popup.js
index 616a9cf..bd24577 100644
--- a/gui/scripts/popup.js
+++ b/gui/scripts/popup.js
@@ -2,52 +2,23 @@
Build the interface for popup
*/
-// Import modules.
+// Import modules.
import texts from './read.JS';
import windowman from './windowman.JS';
+let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
- // Import modules.
- let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
-
- let pref_pane = 0;
-
-
- function start() {
- windowman.prepare();
-
- return(new windowman(`body`, null, null, {'Close': true}));
- }
-
- /* Add the UI design. */
- function design(element) {
- // Set the event of the window.
- function controls() {
- document.getElementById(element[`titlebar`][`controls`][`Close`][`ID`]).onclick = function(){element.terminate(false)};
- }
-
-
-
-
- // TODO work on the content; perhaps, it must read from JSON of valid prefs
-
- controls();
-
- }
-
- /* Populate the strings on the page. */
- function say(element) {
- element.update(element[`titlebar`][`title`], texts.localized(`GUI_title_preferences`));
-
- };
-
- function main() {
- let tab = start();
- design(tab);
- say(tab);
- }
-
- main();
-
+function start() {
+ windowman.prepare();
+}
+/* Populate the strings on the page. */
+function say(element) {
+ // document.title
+}
+function main() {
+ let tab = start();
+ say(tab);
+}
+main();
diff --git a/gui/scripts/read.JS b/gui/scripts/read.JS
index 99aea8b..4f0aa1f 100644
--- a/gui/scripts/read.JS
+++ b/gui/scripts/read.JS
@@ -4,32 +4,37 @@
let messages = {};
let message = "";
-
-
export default class texts {
- static localized (message_name, params = []) {
+ /* This reads the message from its source. This is a fallback for the content scripts, who doesn't appear to read classes.
+
+ @param {string} message the message name
+ @param {boolean} autofill fill in the message with the template name when not found
+ @param {list} params the parameters
+ @return {string} the message
+ */
+
+ static localized (message_name, autofill = false, params = []) {
if (params) {
message = chrome.i18n.getMessage(message_name, params);
} else {
message = chrome.i18n.getMessage(message_name);
}
+ // When the message is not found, return the temporary text.
+ if (!message && autofill) {
+ message = message_name;
+ }
+
return(message);
}
}
-/* This reads the message from its source. This is a fallback for the content scripts, who doesn't appear to read classes.
-@param {string} source the source name, with accepted parameters "localized" and "fallback"
-@param {string} message the message name
-@return {string} the message
-*/
export function read(message_name, params) {
let message;
- message = texts.localized(message_name, params);
- break;
+ message = texts.localized(message_name, params);
return (message);
diff --git a/gui/scripts/settings.JS b/gui/scripts/settings.JS
index 5116f7e..47a62d7 100644
--- a/gui/scripts/settings.JS
+++ b/gui/scripts/settings.JS
@@ -1,104 +1,173 @@
/* Settings.js
- Build the interface for the settings
+ Build the interface for the settings
*/
-// Import modules.
+// Import modules.
import texts from './read.JS';
-import windowman from './windowman.JS';
+import {windowman} from './windowman.JS';
+let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
+// let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
+
+// Import configuration file.
+// const config = chrome.runtime.getURL('gui/layouts/settings.json');
+
+let pref_pane = 0;
- // Import modules.
- let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
-
- let pref_pane = 0;
+function start() {
+ windowman.prepare();
+}
+
+/* Generate the appropriate strings. */
+function say() {
+ windowman.fill();
+}
+
+ /* Add the UI design. */
+ //function design(element) {
+ // Set the event of the window.
+ /*function controls() {
+ document.getElementById(element[`titlebar`][`controls`][`Close`][`ID`]).onclick = function(){element.terminate(false)};
+ }
+
+ function menu() {
+ element.inject(null, 'navbar', element[`content`], `menu`, null, null, {'role': 'tablist'})
+ }
+
+ /* Add the content. */
+ /*function content() {
+ let page_layout = jsonData;
+
+ windowman_builder.tabs(Object.keys(page_layout));
+
+ function tabs(tab_names, parent_element) {
+ (tab_names).forEach((tab_name) => {
+ // Create the elements for each tab content.
+ let inserted_element = element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`], `section`, null, null, {'role': `tabpanel`});
+
+ // Create the menu elements.
+ element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`][`navbar`], `button`, null, null, {'aria-controls': inserted_element});
+
+ });
+ }
+
+ /*
+ Add each item for each preference page, but do not fill in their default preferences.
+
+ @param {dictionary} layout the layout
+ *//*
+ function eachItem(layout) {
+ (layout).forEach((tab) => {
+ // let inserted_element = element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`], `section`, null, null, {'role': `tabpanel`});
+ let current_tab = element[`content`][`navbar`][texts.localized(`term_`.concat(tab_name))];
+
+ (Object.keys(current_tab)).forEach((element_item) => {
+
+ })
+
+ // element.update(element[`content`][`navbar`][texts.localized(`term_`.concat(tab_name))], texts.localized(`term_`.concat(tab_name)));
+ // Create the elements for each tab content.
+ element.inject(texts.localized(`term_`.concat(tab)), texts.localized(`term_`.concat(tab_name)), element[`content`], `section`, null, null, {'role': `tabpanel`});
+
+ // Create the menu elements.
+ element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`][`navbar`], `button`, null, null, {'aria-controls': inserted_element});
+
+ });
+ }
- function start() {
- windowman.prepare();
+ tabs(Object.keys(page_layout));
+ }
- return(new windowman(`body`, null, null, {'Close': true}));
- }
+ function action_buttons() {
+ element.inject(`action_buttons`, `footer`, element[`content`], `footer`, [`field-row`], null, {'style': 'justify-content: flex-end'});
- /* Add the UI design. */
- function design(element) {
- // Set the event of the window.
- function controls() {
- document.getElementById(element[`titlebar`][`controls`][`Close`][`ID`]).onclick = function(){element.terminate(false)};
- }
+ let button_names = ['apply', 'cancel'];
- function menu() {
- element.inject(null, 'navbar', element[`content`], `menu`, null, null, {'role': 'tablist'})
- }
+ (button_names).forEach((button_name) => {
+ // Create the elements for each tab content.
+ element.inject(null, texts.localized(`term_`.concat(button_name)), element[`content`][`footer`], `button`);
+ });
+ }
- function tabs() {
- let tab_names = ['preferences', 'filters', 'about'];
-
- (tab_names).forEach((tab_name) => {
- // Create the elements for each tab content.
- let inserted_element = element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`], `section`, null, null, {'role': `tabpanel`});
+ controls();
+ menu();
+ content();
+ action_buttons();
+ }
- // Create the menu elements.
- element.inject(texts.localized(`term_`.concat(tab_name)), texts.localized(`term_`.concat(tab_name)), element[`content`][`navbar`], `button`, null, null, {'aria-controls': inserted_element});
-
- });
- }
-
- function action_buttons() {
- element.inject(null, `footer`, element[`content`], `footer`, [`field-row`], null, {'style': 'justify-content: flex-end'});
-
- let button_names = ['apply', 'cancel'];
-
- (button_names).forEach((button_name) => {
- // Create the elements for each tab content.
- element.inject(null, texts.localized(`term_`.concat(button_name)), element[`content`][`footer`], `button`);
- });
- }
-
- // TODO work on the content; perhaps, it must read from JSON of valid prefs
-
- controls();
- menu();
- tabs();
- action_buttons();
-
- }
-
- /* Populate the strings on the page. */
- function say(element) {
- document.title = texts.localized(`GUI_title_preferences`);
-
- element.update(element[`titlebar`][`title`], texts.localized(`GUI_title_preferences`));
-
- // Controls
- let tab_names = ['preferences', 'filters', 'about'];
- (tab_names).forEach((tab_name) => {
- element.update(element[`content`][`navbar`][texts.localized(`term_`.concat(tab_name))], texts.localized(`term_`.concat(tab_name)));
- });
-
- function action_buttons() {
- let button_names = ['apply', 'cancel'];
-
- (button_names).forEach((button_name) => {
- // Create the elements for each tab content.
- element.update(element[`content`][`footer`][texts.localized(`term_`.concat(button_name))], texts.localized(`term_`.concat(button_name)));
- });
- };
-
- action_buttons();
- };
-
- function openLast() {
- let last_opened = 'Preferences';
-
- }
-
- function main() {
- let tab = start();
- design(tab);
- say(tab);
- }
-
- main();
+ /* Populate the strings on the page. */
+ /*function say(element) {
+ document.title = texts.localized(`GUI_title_preferences`);
+ element.update(element[`titlebar`][`title`], texts.localized(`GUI_title_preferences`));
+ function content() {
+ fetch(config)
+ .then((response) => response.json())
+ .then((jsonData) => {
+ let page_layout = jsonData;
+ function tabs(tab_names) {
+ (tab_names).forEach((tab_name) => {
+ // Create the elements for each tab content.
+ element.update(element[`content`][`navbar`][texts.localized(`term_`.concat(tab_name))], texts.localized(`term_`.concat(tab_name)));
+ });
+ }
+
+ tabs(Object.keys(page_layout));
+ })
+ .catch((error) => {
+ console.error(error);
+ });
+ }
+
+ // Controls
+ /*
+ let tab_names = ['preferences', 'filters', 'about'];
+ (tab_names).forEach((tab_name) => {
+ element.update(element[`content`][`navbar`][texts.localized(`term_`.concat(tab_name))], texts.localized(`term_`.concat(tab_name)));
+ });
+
+ function action_buttons() {
+ let button_names = ['apply', 'cancel'];
+
+ (button_names).forEach((button_name) => {
+ // Create the elements for each tab content.
+ element.update(element[`content`][`footer`][texts.localized(`term_`.concat(button_name))], texts.localized(`term_`.concat(button_name)));
+ });
+ }
+
+ content();
+ action_buttons();
+
+ }
+
+ */
+
+ /*
+ Arrange the interface.
+ */
+ function arrange() {
+ let last_opened = secretariat.read(`last`);
+ if (!last_opened) {last_opened = 'settings'};
+
+ // click!
+ document.querySelector(`menu button[role="tab"][aria-controls="${last_opened}"]`).click();
+
+ }
+
+ function events() {
+
+ };
+
+ function main() {
+ let tab = start();
+ say();
+
+ document.addEventListener('DOMContentLoaded', function() {
+ arrange();
+ });
+ }
+
+ main();
diff --git a/gui/scripts/windowman.JS b/gui/scripts/windowman.JS
index 0e4370c..f416dab 100644
--- a/gui/scripts/windowman.JS
+++ b/gui/scripts/windowman.JS
@@ -6,17 +6,20 @@ import texts from "./read.JS";
class windowman {
/* Initialize the window frame. */
static prepare() {
- try {
- let UI = {'library': chrome.runtime.getURL('gui/styles/interface.external.css'), 'script': chrome.runtime.getURL('gui/scripts/external/interface.external.js')};
+ try {
+ let UI = {'library': [chrome.runtime.getURL('gui/styles/interface.external.css'), chrome.runtime.getURL('gui/styles/ui.css')], 'script': chrome.runtime.getURL('gui/scripts/external/interface.external.js')};
- $(`head`).append(``);
- $(`head`).append(``);
- } catch(error) {
- console.error(texts.localized(`error_fileNotFound`, [error]));
- }
+ (UI.library).forEach((source) => {
+ $(`head`).append(``);
+ })
- // Prevent scaling, similar to a real window.
- $(`head`).append(``);
+ $(`head`).append(``);
+ } catch(error) {
+ console.error(texts.localized(`error_fileNotFound`, [error]));
+ }
+
+ // Prevent scaling, similar to a real window.
+ $(`head`).append(``);
}
@@ -28,6 +31,22 @@ class windowman {
height: (height) ? height: 600,
});
}
+
+ static fill() {
+
+ function text() {
+ let text_elements = document.querySelectorAll("[data-text]");
+
+ text_elements.forEach((text_element) => {
+ let text_inserted = texts.localized(text_element.getAttribute(`data-text`), (text_element.hasAttribute(`data-text-parameter`)) ? eval(text_element.getAttribute(`data-text-parameter`)) : null );
+ if (!text_inserted) {text_inserted = texts.localized(`term_`.concat(text_element.getAttribute(`data-text`)));}
+
+ text_element.innerText = text_inserted;
+ })
+ }
+
+ text();
+ }
}
export {windowman};
diff --git a/gui/settings.htm b/gui/settings.htm
deleted file mode 100644
index 90a3a3a..0000000
--- a/gui/settings.htm
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/gui/settings_r.htm b/gui/settings_r.htm
deleted file mode 100644
index e4430b6..0000000
--- a/gui/settings_r.htm
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/manifest.json b/manifest.json
index 643cd67..f8fb517 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,14 +1,14 @@
{
"manifest_version": 3,
- "name": "__MSG_manifest_name__",
- "description": "__MSG_manifest_description__",
+ "name": "__MSG_extension_name__",
+ "description": "__MSG_extension_description__",
"version": "0",
"permissions": [ "tabs", "activeTab", "storage", "unlimitedStorage"],
"action": {
"default_icon": "gui/icons/logo_no_tiny.png",
- "default_popup": "gui/popup.htm"
+ "default_popup": "gui/pages/open/popup.htm"
},
"background": {
@@ -33,7 +33,7 @@
"512": "gui/icons/logo_tiny.png"
},
- "options_page": "gui/settings.htm",
+ "options_page": "gui/pages/open/settings.htm",
"default_locale": "en"
}