From 5e3f9695b42f47ff5dbc956cb59ddede9bbfe89c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 14 Dec 2023 09:50:11 -0500 Subject: [PATCH] Support links to update lists which are differential update-friendly If the `manual` parameter is assigned a date in the form of `YYMMDD`, this will tell uBO to update lists from origin sources when the current time is within the range of the specified date, otherwise lists will be updated from CDNs. Updating from CDNs is always strongly recommended since this enables differential updates. For the time being, `manual=1` will always cause to update lists from origin, but this form will be deprecated once next stable release is widespread. The idea is to not leave behind stale and obsolete links which would be detrimental to differential updates should someone click on one of these old links left behind. --- src/js/messaging.js | 2 +- src/js/scriptlets/updater.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index cacf32127adda..9137f26538fa7 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -2178,7 +2178,7 @@ const onMessage = function(request, sender, callback) { url: 'dashboard.html#3p-filters.html', select: true, }); - µb.scheduleAssetUpdater({ now: true, fetchDelay: 100, auto: request.manual !== true }); + µb.scheduleAssetUpdater({ now: true, fetchDelay: 100, auto: request.auto }); break; default: diff --git a/src/js/scriptlets/updater.js b/src/js/scriptlets/updater.js index 0eafc5daa2ffd..006b663a05951 100644 --- a/src/js/scriptlets/updater.js +++ b/src/js/scriptlets/updater.js @@ -51,11 +51,28 @@ function updateStockLists(target) { if ( updateURL.hostname !== 'ublockorigin.github.io') { return; } if ( updateURL.pathname !== '/uAssets/update-lists.html') { return; } const listkeys = updateURL.searchParams.get('listkeys') || ''; - if ( listkeys === '' ) { return true; } + if ( listkeys === '' ) { return; } + let auto = true; + const manual = updateURL.searchParams.get('manual'); + if ( manual === '1' ) { + auto = false; + } else if ( /^\d{6}$/.test(`${manual}`) ) { + const year = parseInt(manual.slice(0,2)) || 0; + const month = parseInt(manual.slice(2,4)) || 0; + const day = parseInt(manual.slice(4,6)) || 0; + if ( year !== 0 && month !== 0 && day !== 0 ) { + const date = new Date(); + date.setUTCFullYear(2000 + year, month - 1, day); + date.setUTCHours(0); + const then = date.getTime() / 1000 / 3600; + const now = Date.now() / 1000 / 3600; + auto = then < (now - 48) || then > (now + 48); + } + } vAPI.messaging.send('scriptlets', { what: 'updateLists', listkeys, - manual: updateURL.searchParams.get('manual') && true || false, + auto, }); return true; } catch (_) {