diff --git a/OpenFoodFactsPower.user.js b/OpenFoodFactsPower.user.js index 31d3c24..3dbe708 100644 --- a/OpenFoodFactsPower.user.js +++ b/OpenFoodFactsPower.user.js @@ -2,7 +2,7 @@ // @name Open Food Facts power user script // @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. // @namespace openfoodfacts.org -// @version 2024-01-03T11:20 +// @version 2024-01-03T13:20 // @include https://*.openfoodfacts.org/* // @include https://*.openproductsfacts.org/* // @include https://*.openbeautyfacts.org/* @@ -59,7 +59,7 @@ var proPlatform = false; // TODO: to be included in isPageType() const pageType = isPageType(); // test page type const corsProxyURL = ""; - log("2024-01-03T11:20 - mode: " + pageType); + log("2024-01-03T13:20 - mode: " + pageType); // Disable extension if the page is an API result; https://world.openfoodfacts.org/api/v0/product/3222471092705.json if (pageType === "api") { @@ -815,7 +815,7 @@ textarea.monospace { Copydata(); submitToPopup(analyse_form); }); - + $('body').append(''); $("#pwe_hide_text_fields").click(function(){ toggleHideTextFieldsPopUp(); @@ -825,6 +825,28 @@ textarea.monospace { } + if (pageType === "edit" || pageType === "product view") { + var history = document.getElementById("history"); + // add search field after "Changes history" + const historyInput = document.createElement("input"); + history.after(historyInput); + var initalList = true; + // search term when the user fill a value + historyInput.addEventListener('input', function (input) { + const value = input.target.value; + let list = document.querySelector('#history_list').querySelectorAll('li'); + // if search term is less than 2 characters, reset style and return + if (value.length < 2) { + if (initalList === false) list.forEach((x) => { x.style.color = '' }); + initalList = true; + return; + } + initalList = false; + let re = new RegExp(value, 'i'); + // highlight line in blue or grey weither it contains the searched term or not + list.forEach((x) => { x.style.color = (re.test(x.textContent)) ? 'blue' : 'grey' }); + }); + } // Keyboard actions $(document).on('keydown', function(event) { @@ -1532,7 +1554,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert //$("#power-user-help").prev().addClass('ui-state-information'); return popup; } - + // Toggle popup function togglePowerUserInfo(message) { if ($("#power-user-help").dialog( "isOpen" ) === true) { @@ -1542,7 +1564,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert return showPowerUserInfo(message); } } - + // Hide Text Fields function toggleHideTextFieldsPopUp() { if($("#power-user-hide-fields-popup").dialog("isOpen") === true){ @@ -1551,26 +1573,26 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert return showPowerUserHideTextFieldsPopUp(); } } - + function showPowerUserHideTextFieldsPopUp(){ if($("#power-user-hide-fields-popup").length === 0){ $('body').append('
'); $("#power-user-hide-fields-popup").dialog({autoOpen: false}); } - + var popUpContent = getPowerUserHideFieldsContent(); - + $("#power-user-hide-fields-popup").html(popUpContent); getHideFieldsCheckboxesFromStorage(); - + let popup = $("#power-user-hide-fields-popup").dialog({ autoOpen: true, width: 400, dialogClass: 'dialogstyleperso', - }); + }); } - + function getPowerUserHideFieldsContent(){ return ``; } - + //generetes an input and also manages, stores, retrieves the checked state. function createInputWithCheckbox(labelValue, inputId){ let checkbox = ''; @@ -1633,7 +1655,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert getHideFieldCheckboxFromStorage('pus-hide-categories',['label[for="categories"]','label[for="categories"]'],true); getHideFieldCheckboxFromStorage('pus-hide-labels',['label[for="labels"]','label[for="labels"]'],true); getHideFieldCheckboxFromStorage('pus-hide-manufactoring',['label[for="manufacturing_places"]','label[for="manufacturing_places"]'],true); - getHideFieldCheckboxFromStorage('pus-hide-traceability',['label[for="emb_codes"]','label[for="emb_codes"]'],true); + getHideFieldCheckboxFromStorage('pus-hide-traceability',['label[for="emb_codes"]','label[for="emb_codes"]'],true); getHideFieldCheckboxFromStorage('pus-hide-link-to-product',['#link','label[for="link"]']); getHideFieldCheckboxFromStorage('pus-hide-best-before',['#expiration_date','label[for="expiration_date"]']); getHideFieldCheckboxFromStorage('pus-hide-city-state',['label[for="purchase_places"]','label[for="purchase_places"]'],true); @@ -1652,7 +1674,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert if(getLocalStorage(checkboxId) === "checked"){ $('#'+checkboxId).prop("checked", true); } - + $('#'+checkboxId).change(function() { if(this.checked){ localStorage.setItem(checkboxId, "checked"); @@ -1693,7 +1715,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert loadHideTextFieldFromStorage('pus-hide-brands',['label[for="brands"]','label[for="brands"]'],true); loadHideTextFieldFromStorage('pus-hide-categories',['label[for="categories"]','label[for="categories"]'],true); loadHideTextFieldFromStorage('pus-hide-labels',['label[for="labels"]','label[for="labels"]'],true); - loadHideTextFieldFromStorage('pus-hide-manufactoring',['label[for="manufacturing_places"]','label[for="manufacturing_places"]'],true); + loadHideTextFieldFromStorage('pus-hide-manufactoring',['label[for="manufacturing_places"]','label[for="manufacturing_places"]'],true); loadHideTextFieldFromStorage('pus-hide-traceability',['label[for="emb_codes"]','label[for="emb_codes"]'],true); loadHideTextFieldFromStorage('pus-hide-link-to-product',['#link','label[for="link"]']); loadHideTextFieldFromStorage('pus-hide-best-before',['#expiration_date','label[for="expiration_date"]']); @@ -1708,7 +1730,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert loadHideTextFieldFromStorage('pus-hide-nutrition',['#nutrition']); loadHideTextFieldFromStorage('pus-hide-packaging',['#packaging_section']); }); - + } function loadHideTextFieldFromStorage(checkboxId, hideFieldsIds, hasTags = false){ if(getLocalStorage(checkboxId) === "checked"){ @@ -1859,12 +1881,12 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert }); } - + function toggleAlwaysShowBarcodes(){ if(getLocalStorage("pus-always-show-barcode") === "always"){ $('#pus-always-show-barcode').prop("checked", true); } - + $('#pus-always-show-barcode').change(function() { if(this.checked){ localStorage.setItem('pus-always-show-barcode', "always"); @@ -1874,7 +1896,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert toggleListBarcodes(); }); } - + function loadAlwaysShowBarcodesFromStorage(){ $( window ).on( "load", function() { if(getLocalStorage("pus-always-show-barcode") === "always"){ @@ -1939,10 +1961,9 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert } function showListBarcodes() { - + $("ul[id^='products_'].search_results li[data-code]").each(function(index, element) { let code = $(this).attr('data-code'); - if ($("#barcode_draw_" + code).length) { return; } $('').insertBefore( $('a.list_product_a', this) ); @@ -1961,7 +1982,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert break; } - try { + try { JsBarcode("#barcode_draw_" + code, code, { format: barcode_format, flat: true, diff --git a/README.md b/README.md index 73d6e38..f9d71f5 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,11 @@ Once your script manager is installed you can go to https://github.com/openfoodf Just click on the Raw button and your script manager will ask you if you want to install the script. # Changelog +### 2024-01-03T13:20 +* Search as you type to filter changes. Useful for many cases: + * find **add**itions or **change**s + * monitor changes for specific fields + * monitor changes from specific users ### 2024-01-03T11:20 * Products' list: add button to each product to open Hunger Game ### 2023-12-22T10:15