|
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 2025-05-28T10:24 |
| 5 | +// @version 2025-06-17T18:50 |
6 | 6 | // @include https://*.openfoodfacts.org/* |
7 | 7 | // @include https://*.openproductsfacts.org/* |
8 | 8 | // @include https://*.openbeautyfacts.org/* |
|
64 | 64 | var proPlatform = false; // TODO: to be included in isPageType() |
65 | 65 | const pageType = isPageType(); // test page type |
66 | 66 | const corsProxyURL = ""; |
67 | | - log("2025-05-28T10:24 - mode: " + pageType); |
| 67 | + log("2025-06-17T18:50 - mode: " + pageType); |
68 | 68 |
|
69 | | - // Disable extension if the page is an API result; https://world.openfoodfacts.org/api/v0/product/3222471092705.json |
| 69 | + // Disable extension if the page is an API result; https://world.openfoodfacts.org/api/v2/product/3222471092705.json |
70 | 70 | if (pageType === "api") { |
71 | 71 | // TODO: allow keyboard shortcut to get back to product view? |
72 | 72 | var _code = window.location.href.match(/\/product\/(.*)\.json$/)[1]; |
|
178 | 178 |
|
179 | 179 | // TODO |
180 | 180 | // * FEATURES |
181 | | - // * identify problematic fields based on quality feedbacks; https://world.openfoodfacts.org/api/v0/product/7502271153193.json |
| 181 | + // * identify problematic fields based on quality feedbacks; https://world.openfoodfacts.org/api/v2/product/7502271153193.json |
182 | 182 | // * see "data_quality_errors_tags" array |
183 | 183 | // * On the fly quality checks in the product edit form (javascript): https://github.com/openfoodfacts/openfoodfacts-server/issues/1905 |
184 | 184 | // * Add automatic detection of nutriments, see: https://robotoff.openfoodfacts.org/api/v1/predict/nutrient?ocr_url=https://static.openfoodfacts.org/images/products/841/037/511/0228/nutrition_pt.12.json |
@@ -589,8 +589,8 @@ textarea.monospace { |
589 | 589 | } |
590 | 590 |
|
591 | 591 | log("code: "+ code); |
592 | | - // build API product link; example: https://world.openfoodfacts.org/api/v0/product/737628064502.json |
593 | | - var apiProductURL = "/api/v0/product/" + code + ".json"; |
| 592 | + // build API product link; example: https://world.openfoodfacts.org/api/v2/product/737628064502.json |
| 593 | + var apiProductURL = "/api/v2/product/" + code + ".json"; |
594 | 594 | log("API: " + apiProductURL); |
595 | 595 | // build edit url |
596 | 596 | var editURL = document.location.protocol + "//" + document.location.host + "/cgi/product.pl?type=edit&code=" + code; |
@@ -2136,7 +2136,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert |
2136 | 2136 | flagRevision(rev); |
2137 | 2137 | } |
2138 | 2138 | else { |
2139 | | - var _url = "/api/v0/product/" + code + ".json"; |
| 2139 | + var _url = "/api/v2/product/" + code + ".json"; |
2140 | 2140 | $.getJSON(_url, function(data) { |
2141 | 2141 | rev = data.product.rev; |
2142 | 2142 | log("rev: "); log(rev); |
@@ -2335,7 +2335,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert |
2335 | 2335 | if (pageType !== "product view") { // script fail if productName below is undefined |
2336 | 2336 | return; |
2337 | 2337 | } |
2338 | | - // The productName below sometimes is undefined; TODO: get it with API? https://world.openfoodfacts.org/api/v0/product/3222475464430.json&fields=product_name |
| 2338 | + // The productName below sometimes is undefined; TODO: get it with API? https://world.openfoodfacts.org/api/v2/product/3222475464430.json&fields=product_name |
2339 | 2339 | productName = $('h1[property="food:name"]').html().match(/(.*?)(( - .*)|$)/)[1]; |
2340 | 2340 | similarProductsSearchURL = encodeURI( |
2341 | 2341 | document.location.protocol + "//" + document.location.host + |
@@ -2370,7 +2370,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert |
2370 | 2370 | * @returns {String} - Type of page: api|saved-product page|edit|list|search form|product view|error page |
2371 | 2371 | */ |
2372 | 2372 | function isPageType() { |
2373 | | - // Detect API page. Example: https://world.openfoodfacts.org/api/v0/product/3599741003380.json |
| 2373 | + // Detect API page. Example: https://world.openfoodfacts.org/api/v2/product/3599741003380.json |
2374 | 2374 | var regex_api = RegExp('api/v0/'); |
2375 | 2375 | if(regex_api.test(document.URL) === true) return "api"; |
2376 | 2376 |
|
|
0 commit comments