Skip to content

Commit 9d09a0a

Browse files
API v2
1 parent 3af35c6 commit 9d09a0a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

OpenFoodFactsPower.user.js

Lines changed: 9 additions & 9 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 2025-05-28T10:24
5+
// @version 2025-06-17T18:50
66
// @include https://*.openfoodfacts.org/*
77
// @include https://*.openproductsfacts.org/*
88
// @include https://*.openbeautyfacts.org/*
@@ -64,9 +64,9 @@
6464
var proPlatform = false; // TODO: to be included in isPageType()
6565
const pageType = isPageType(); // test page type
6666
const corsProxyURL = "";
67-
log("2025-05-28T10:24 - mode: " + pageType);
67+
log("2025-06-17T18:50 - mode: " + pageType);
6868

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
7070
if (pageType === "api") {
7171
// TODO: allow keyboard shortcut to get back to product view?
7272
var _code = window.location.href.match(/\/product\/(.*)\.json$/)[1];
@@ -178,7 +178,7 @@
178178

179179
// TODO
180180
// * 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
182182
// * see "data_quality_errors_tags" array
183183
// * On the fly quality checks in the product edit form (javascript): https://github.com/openfoodfacts/openfoodfacts-server/issues/1905
184184
// * 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 {
589589
}
590590

591591
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";
594594
log("API: " + apiProductURL);
595595
// build edit url
596596
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
21362136
flagRevision(rev);
21372137
}
21382138
else {
2139-
var _url = "/api/v0/product/" + code + ".json";
2139+
var _url = "/api/v2/product/" + code + ".json";
21402140
$.getJSON(_url, function(data) {
21412141
rev = data.product.rev;
21422142
log("rev: "); log(rev);
@@ -2335,7 +2335,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert
23352335
if (pageType !== "product view") { // script fail if productName below is undefined
23362336
return;
23372337
}
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
23392339
productName = $('h1[property="food:name"]').html().match(/(.*?)(( - .*)|$)/)[1];
23402340
similarProductsSearchURL = encodeURI(
23412341
document.location.protocol + "//" + document.location.host +
@@ -2370,7 +2370,7 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert
23702370
* @returns {String} - Type of page: api|saved-product page|edit|list|search form|product view|error page
23712371
*/
23722372
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
23742374
var regex_api = RegExp('api/v0/');
23752375
if(regex_api.test(document.URL) === true) return "api";
23762376

0 commit comments

Comments
 (0)