Skip to content

Commit

Permalink
build: 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrikeasia committed Dec 5, 2024
1 parent 0b244c5 commit 2ca9ee0
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 65 deletions.
Binary file removed eew-source.trem
Binary file not shown.
132 changes: 74 additions & 58 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
const path = require('path');
const TREM = require(path.resolve('src/js/index/constant'));

class Plugin {
#ctx;

constructor(ctx) {
this.#ctx = ctx;
this.eewSource = JSON.parse(localStorage.getItem('eew-source-plugin')) || [];
this.eewSource =
JSON.parse(localStorage.getItem("eew-source-plugin")) || [];
this.supportSource = [
{ value: 'trem', text: 'TREM (僅套用在重播)' },
{ value: 'cwa', text: '中央氣象署 (CWA)' },
{ value: 'nied', text: '防災科研 (NIED)' },
{ value: 'kma', text: '韓國氣象廳 (KMA)' },
{ value: 'scdzj', text: '四川省地震局 (SCDZJ)' },
{ value: 'fjdzj', text: '福建省地震局 (FJDZJ)' },
{ value: "trem", text: "TREM (僅套用在重播)" },
{ value: "cwa", text: "中央氣象署 (CWA)" },
{ value: "nied", text: "防災科研 (NIED)" },
{ value: "kma", text: "韓國氣象廳 (KMA)" },
{ value: "scdzj", text: "四川省地震局 (SCDZJ)" },
{ value: "fjdzj", text: "福建省地震局 (FJDZJ)" },
];
}

changeAuthor(){
if(this.eewSource && this.eewSource.length > 0) {
const eewSource = JSON.parse(localStorage.getItem('eew-source-plugin')) || [];
changeAuthor(TREM) {
if (this.eewSource && this.eewSource.length > 0) {
const eewSource =
JSON.parse(localStorage.getItem("eew-source-plugin")) || [];
TREM.constant.EEW_AUTHOR = eewSource;
window.this_constant = TREM.constant.EEW_AUTHOR;
logger.info('Earthquake early warning source change success!', this_constant);
logger.info(
"Earthquake early warning source change success!",
this_constant
);
}
}

init() {
this.changeAuthor();
window.addEventListener('storage', (event) => {
if (event.key === 'eew-source-plugin' && event.newValue) {
this.changeAuthor();
init(TREM) {
this.changeAuthor(TREM);
window.addEventListener("storage", (event) => {
if (event.key === "eew-source-plugin" && event.newValue) {
this.changeAuthor(TREM);
}
});

const settingButtons = document.querySelector('.setting-buttons');
const settingContent = document.querySelector('.setting-content');
if(settingContent) {
const button = document.createElement('div');
button.className = 'button eew-source';
button.setAttribute('for', 'eew-source-page');
const settingButtons = document.querySelector(".setting-buttons");
const settingContent = document.querySelector(".setting-content");
if (settingContent) {
const button = document.createElement("div");
button.className = "button eew-source";
button.setAttribute("for", "eew-source-page");
settingButtons.appendChild(button);
button.textContent = 'EEW Source';

const options = this.supportSource.map((source) => `
button.textContent = "EEW Source";

const options = this.supportSource
.map(
(source) => `
<div>
<span>${source.text}</span>
<label class="switch">
<input id="${source.value}.eew-source-plugin" type="checkbox">
<div class="slider round"></div>
</label>
</div>
`).join('');

const element = document.createElement('div');
element.classList.add('setting-options-page', 'eew-source-page');
`
)
.join("");

const element = document.createElement("div");
element.classList.add("setting-options-page", "eew-source-page");
element.innerHTML = `
<div class="setting-page-header-title">EEW Source</div>
<div class="setting-item-wrapper">
Expand All @@ -67,15 +73,15 @@ class Plugin {
</div>
</div>`;
settingContent.appendChild(element);
};
}
}

addCheckBoxEvent() {
document.addEventListener('click', async (e) => {
if (e.target.classList.contains('slider')) {
addCheckBoxEvent(TREM) {
document.addEventListener("click", async (e) => {
if (e.target.classList.contains("slider")) {
const inputElement = e.target.previousElementSibling;
if (inputElement && inputElement.id.endsWith('.eew-source-plugin')) {
const key = inputElement.id.split('.')[0];
if (inputElement && inputElement.id.endsWith(".eew-source-plugin")) {
const key = inputElement.id.split(".")[0];
if (!TREM.constant.EEW_AUTHOR) {
TREM.constant.EEW_AUTHOR = [];
}
Expand All @@ -86,42 +92,50 @@ class Plugin {
} else {
const index = TREM.constant.EEW_AUTHOR.indexOf(key);
if (index !== -1) {
TREM.constant.EEW_AUTHOR.splice(index, 1);
TREM.constant.EEW_AUTHOR.splice(index, 1);
}
}
localStorage.setItem('eew-source-plugin', JSON.stringify(TREM.constant.EEW_AUTHOR));
localStorage.setItem(
"eew-source-plugin",
JSON.stringify(TREM.constant.EEW_AUTHOR)
);
}
}
});
}

addClickEvent() {
const settingOptionsPage = document.querySelectorAll('.setting-options-page');
const settingButtons = document.querySelectorAll('.setting-buttons .button');
const page = document.querySelector('.eew-source-page');
const button = document.querySelector('.eew-source');
const settingOptionsPage = document.querySelectorAll(
".setting-options-page"
);
const settingButtons = document.querySelectorAll(
".setting-buttons .button"
);
const page = document.querySelector(".eew-source-page");
const button = document.querySelector(".eew-source");

if(button) {
button.addEventListener('click', () => {
if (button) {
button.addEventListener("click", () => {
settingOptionsPage.forEach((item) => {
item.classList.remove('active');
item.classList.remove("active");
});
page.classList.add('active');
page.classList.add("active");

settingButtons.forEach((item) => {
item.classList.remove('on');
item.classList.remove("on");
});
button.classList.add('on');
button.classList.add("on");
});
}
}

initializeEEWAuthor() {
const storedData = JSON.parse(localStorage.getItem('eew-source-plugin')) || [];
initializeEEWAuthor(TREM) {
const storedData =
JSON.parse(localStorage.getItem("eew-source-plugin")) || [];
if (!TREM.constant.EEW_AUTHOR) {
TREM.constant.EEW_AUTHOR = [];
}
TREM.constant.EEW_AUTHOR = [...storedData];
TREM.constant.EEW_AUTHOR = [...storedData];
for (const key of storedData) {
const checkbox = document.getElementById(`${key}.eew-source-plugin`);
if (checkbox) {
Expand All @@ -131,12 +145,14 @@ class Plugin {
}

async onLoad() {
this.init();
const { TREM, logger } = this.#ctx;

this.init(TREM);
this.addClickEvent();
this.addCheckBoxEvent();
this.initializeEEWAuthor();
this.addCheckBoxEvent(TREM);
this.initializeEEWAuthor(TREM);
logger.info("Loading EEW Source plugin...");
}
}

module.exports = Plugin;
module.exports = Plugin;
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "eew-source",
"version": "0.0.2",
"version": "0.0.3",
"description": {
"zh_tw": "TREM-Lite EEW Source Plugin",
"zh-Hant": "TREM-Lite 地震速報來源擴充套件"
},
"loader": ["setting", "index"],
"author": ["cstrikeasia"],
"dependencies": {
"trem": ">=3.1.0-rc.2"
"trem": ">=3.1.0-rc.3"
},
"resources": ["AGPL-3.0"],
"link": "https://github.com/ExpTechTW/TREM-EEW-Source-Plugin"
Expand Down
10 changes: 5 additions & 5 deletions signature.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"timestamp": 1733339206066,
"version": "0.0.2",
"timestamp": 1733392197363,
"version": "0.0.3",
"fileHashes": {
"index.js": "6ecd28c330e7b8a03930a7c8dccf7ed3557c1ffee1432eaf051132557deb974b",
"info.json": "c587163c771877906e1fb83cad9875e5e99f41ccebb8c5366ac25374f51b490a"
"index.js": "863b16fd3e0562df9da02a0155a5edcd06643b7614bd73317e5452de2e2bb894",
"info.json": "10f68a42b82e7e49ab8fbca4ff946497055398316049bf3afcce4f3356ef3829"
},
"signature": "MlYgOF8nMFLip2S0w1dB5k8a7bMZRslgM7MYzwvO2rs7ADoxxiwva/pQHwxuetPqMu1G4KswK1gOTS2lvr33e5KemQubQQXjdvjX/R9yIDPneAChy4FbEnzRm3OqWL1M0wj7dNCQNjCPonfM+K2C6dUWjvlvqUfLK2LkkLrSxtUByGEuaWoEGOqApYRQyT2MaA05eJ0+16AIInffr8J4rBlJ5gUdrcZxv50uhsqcOpXmxOSSe2eH85WWXnpITh+NMrx0aaiRBUpS+lcPV32igaXeQeCFu/ZWK8OSvTEb6ECcPHhCPwbF0XtQRBwt7d753aW7CkiBAhhlaYdk6xooTQ=="
"signature": "LhAMAfdmIQUD2urV+TcaYaDE2w6TesrVihtUSQsvKbywDjR/BbuztFu8nWFw21mUO+hlLNpaK77HjtR7IdnVOrU6IkIXOMIBD0sVQ6QXM6kAqFQYa+a8hgsMuUeaMFIoNxDfriImrdrdqzUBk+Sb6FoRzJER38qg3FIGw+U58USn4WNGgXCxxnrD5jHYqJ4fQqDuHUvgTsGTurLiSk3CWAFueEQODeOCG0LdGkrov2lHqr3yzKpKuZbEPd5MNp7PgYBVvAcIQI/SHngttpRA3xRyZ4HQYuQMdFuo9/+MXmodc7BrbkWocBYqgo8HXj2XiAZ31gONM5nJm4UNkqje8Q=="
}

0 comments on commit 2ca9ee0

Please sign in to comment.