Skip to content

Commit

Permalink
Support links to update lists which are differential update-friendly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Dec 14, 2023
1 parent bd7ce41 commit 5e3f969
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions src/js/scriptlets/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (_) {
Expand Down

0 comments on commit 5e3f969

Please sign in to comment.