aboutsummaryrefslogtreecommitdiff
path: root/p/scripts
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2022-02-28 20:22:43 +0100
committerGravatar GitHub <noreply@github.com> 2022-02-28 20:22:43 +0100
commit1fe66ad020ca8f0560bb9c6e311852ed77228f78 (patch)
treedf78da3f33a9f13a9d6ba3f2744c369bd6e313a6 /p/scripts
parentfa23ae76ea46b329fb65329081df95e864b03b23 (diff)
Implement Web scraping "HTML + XPath" (#4220)
* More PHP type hints for Fever Follow-up of https://github.com/FreshRSS/FreshRSS/pull/4201 Related to https://github.com/FreshRSS/FreshRSS/issues/4200 * Detail * Draft * Progress * More draft * Fix thumbnail PHP type hint https://github.com/FreshRSS/FreshRSS/issues/4215 * More types * A bit more * Refactor FreshRSS_Entry::fromArray * Progress * Starts to work * Categories * Fonctional * Layout update * Fix relative URLs * Cache system * Forgotten files * Remove a debug line * Automatic form validation of XPath expressions * data-leave-validation * Fix reload action * Simpler examples * Fix column type for PostgreSQL * Enforce HTTP encoding * Readme * Fix get full content * target="_blank" * gitignore * htmlspecialchars_utf8 * Implement HTML <base> And fix/revert `xml:base` support in SimplePie https://github.com/simplepie/simplepie/commit/e49c578817aa504d8d05cd7f33857aeda9d41908 * SimplePie upstream PR merged https://github.com/simplepie/simplepie/pull/723
Diffstat (limited to 'p/scripts')
-rw-r--r--p/scripts/extra.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/p/scripts/extra.js b/p/scripts/extra.js
index 00a460917..505b05110 100644
--- a/p/scripts/extra.js
+++ b/p/scripts/extra.js
@@ -213,6 +213,49 @@ function init_configuration_alert() {
};
}
+/**
+ * Allow a <select class="select-show"> to hide/show elements defined by <option data-show="elem-id"></option>
+ */
+function init_select_show() {
+ const listener = (select) => {
+ const options = select.querySelectorAll('option[data-show]');
+ for (const option of options) {
+ const elem = document.getElementById(option.dataset.show);
+ if (elem) {
+ elem.style.display = option.selected ? 'block' : 'none';
+ }
+ }
+ };
+
+ const selects = document.querySelectorAll('select.select-show');
+ for (const select of selects) {
+ select.addEventListener('change', (e) => listener(e.target));
+ listener(select);
+ }
+}
+
+/**
+ * Automatically validate XPath textarea fields
+ */
+function init_valid_xpath() {
+ const listener = (textarea) => {
+ const evaluator = new XPathEvaluator();
+ try {
+ if (textarea.value === '' || evaluator.createExpression(textarea.value) != null) {
+ textarea.setCustomValidity('');
+ }
+ } catch (ex) {
+ textarea.setCustomValidity(ex);
+ }
+ };
+
+ const textareas = document.querySelectorAll('textarea.valid-xpath');
+ for (const textarea of textareas) {
+ textarea.addEventListener('change', (e) => listener(e.target));
+ listener(textarea);
+ }
+}
+
function init_extra() {
if (!window.context) {
if (window.console) {
@@ -227,6 +270,8 @@ function init_extra() {
init_slider_observers();
init_configuration_alert();
fix_popup_preview_selector();
+ init_select_show();
+ init_valid_xpath();
}
if (document.readyState && document.readyState !== 'loading') {