|
2 | 2 | // @name Open Food Facts power user script |
3 | 3 | // @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. |
4 | 4 | // @namespace openfoodfacts.org |
5 | | -// @version 2024-02-02T20:39 |
| 5 | +// @version 2024-02-16T13:40 |
6 | 6 | // @include https://*.openfoodfacts.org/* |
7 | 7 | // @include https://*.openproductsfacts.org/* |
8 | 8 | // @include https://*.openbeautyfacts.org/* |
@@ -827,25 +827,27 @@ textarea.monospace { |
827 | 827 |
|
828 | 828 | if (pageType === "edit" || pageType === "product view") { |
829 | 829 | 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 | + } |
849 | 851 | } |
850 | 852 |
|
851 | 853 | // Keyboard actions |
|
0 commit comments