From 62f038cb4bef29513e02c5e6037cce0df560b001 Mon Sep 17 00:00:00 2001 From: Giteadmin Date: Sun, 10 Sep 2023 07:49:18 +0200 Subject: [PATCH] Added Options now it is possible to configure the default url --- MantisHelperPlugin/background.js | 8 +++++--- MantisHelperPlugin/manifest.json | 5 +++-- MantisHelperPlugin/options.html | 14 ++++++++++++++ MantisHelperPlugin/options.js | 13 +++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 MantisHelperPlugin/options.html create mode 100644 MantisHelperPlugin/options.js diff --git a/MantisHelperPlugin/background.js b/MantisHelperPlugin/background.js index 6dea0da..1f0e8d7 100644 --- a/MantisHelperPlugin/background.js +++ b/MantisHelperPlugin/background.js @@ -12,8 +12,10 @@ chrome.contextMenus.onClicked.addListener((info) => { if (selectedText.startsWith('#')) { selectedText = selectedText.substring(1); } - const fixedUrl = 'https://ot.syncore.at/view.php?id='; - const completeUrl = `${fixedUrl}${selectedText}`; - chrome.tabs.create({ url: completeUrl }); + chrome.storage.sync.get(['customUrl'], (result) => { + const fixedUrl = result.customUrl || 'https://example.com/view.php?id='; + const completeUrl = `${fixedUrl}${selectedText}`; + chrome.tabs.create({ url: completeUrl }); + }); } }); diff --git a/MantisHelperPlugin/manifest.json b/MantisHelperPlugin/manifest.json index 2740094..5f29ef1 100644 --- a/MantisHelperPlugin/manifest.json +++ b/MantisHelperPlugin/manifest.json @@ -2,9 +2,10 @@ "manifest_version": 3, "name": "Open in Mantis", "version": "1.0", - "permissions": ["contextMenus"], + "permissions": ["contextMenus", "storage"], "background": { "service_worker": "background.js" }, - "description": "Open selected number in Mantis" + "description": "Open selected number in Mantis", + "options_page": "options.html" } diff --git a/MantisHelperPlugin/options.html b/MantisHelperPlugin/options.html new file mode 100644 index 0000000..b1c44ac --- /dev/null +++ b/MantisHelperPlugin/options.html @@ -0,0 +1,14 @@ + + + + Options + + +
+ + + +
+ + + diff --git a/MantisHelperPlugin/options.js b/MantisHelperPlugin/options.js new file mode 100644 index 0000000..00d5bb7 --- /dev/null +++ b/MantisHelperPlugin/options.js @@ -0,0 +1,13 @@ +document.addEventListener('DOMContentLoaded', () => { + chrome.storage.sync.get(['customUrl'], (result) => { + document.getElementById('customUrl').value = result.customUrl || 'https://example.com/view.php?id='; + }); +}); + +document.getElementById('optionsForm').addEventListener('submit', (e) => { + e.preventDefault(); + const customUrl = document.getElementById('customUrl').value; + chrome.storage.sync.set({ customUrl }, () => { + alert('Options saved.'); + }); +});