Skip to content

Commit 2783a69

Browse files
committed
Fix #90
1 parent 41c39a5 commit 2783a69

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

OpenFoodFactsPower.user.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @name Open Food Facts power user script
33
// @description Helps power users in their day to day work. Key "?" shows help. This extension is a kind of sandbox to experiment features that could be added to Open Food Facts website.
44
// @namespace openfoodfacts.org
5-
// @version 2024-02-02T20:39
5+
// @version 2024-02-16T13:40
66
// @include https://*.openfoodfacts.org/*
77
// @include https://*.openproductsfacts.org/*
88
// @include https://*.openbeautyfacts.org/*
@@ -827,25 +827,27 @@ textarea.monospace {
827827

828828
if (pageType === "edit" || pageType === "product view") {
829829
var history = document.getElementById("history");
830-
// add search field after "Changes history"
831-
const historyInput = document.createElement("input");
832-
history.after(historyInput);
833-
var initalList = true;
834-
// search term when the user fill a value
835-
historyInput.addEventListener('input', function (input) {
836-
const value = input.target.value;
837-
let list = document.querySelector('#history_list').querySelectorAll('li');
838-
// if search term is less than 2 characters, reset style and return
839-
if (value.length < 2) {
840-
if (initalList === false) list.forEach((x) => { x.style.color = '' });
841-
initalList = true;
842-
return;
843-
}
844-
initalList = false;
845-
let re = new RegExp(value, 'i');
846-
// highlight line in blue or grey weither it contains the searched term or not
847-
list.forEach((x) => { x.style.color = (re.test(x.textContent)) ? 'blue' : 'grey' });
848-
});
830+
if (history !== null) {
831+
// add search field after "Changes history"
832+
const historyInput = document.createElement("input");
833+
history.after(historyInput);
834+
var initalList = true;
835+
// search term when the user fill a value
836+
historyInput.addEventListener('input', function (input) {
837+
const value = input.target.value;
838+
let list = document.querySelector('#history_list').querySelectorAll('li');
839+
// if search term is less than 2 characters, reset style and return
840+
if (value.length < 2) {
841+
if (initalList === false) list.forEach((x) => { x.style.color = '' });
842+
initalList = true;
843+
return;
844+
}
845+
initalList = false;
846+
let re = new RegExp(value, 'i');
847+
// highlight line in blue or grey weither it contains the searched term or not
848+
list.forEach((x) => { x.style.color = (re.test(x.textContent)) ? 'blue' : 'grey' });
849+
});
850+
}
849851
}
850852

851853
// Keyboard actions

0 commit comments

Comments
 (0)