From fa091890efeb988d010703c06ab29e272cafe59c Mon Sep 17 00:00:00 2001 From: Daniel Howe Date: Mon, 16 Dec 2024 01:45:59 -0500 Subject: [PATCH 1/7] minor refactors and cleanup --- src/js/adn/vault.js | 128 +++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 86 deletions(-) diff --git a/src/js/adn/vault.js b/src/js/adn/vault.js index 9f80f91262291..269e5904d9555 100644 --- a/src/js/adn/vault.js +++ b/src/js/adn/vault.js @@ -88,7 +88,6 @@ onBroadcast(request => { break; case 'adDetected': - console.log('*** New-ad-detected ***', request.ad); waitingAds.push(request.ad); lastAdDetectedTime = new Date(); const brush = document.getElementsByClassName('chart-bg')[0]; @@ -96,7 +95,6 @@ onBroadcast(request => { sliderPos = gSliderLeft ? parseFloat(/\((.*?),/g.exec(gSliderLeft)[1]) : null; // only when the slider covers 'now' or when there is no slider (empty vault or one ad) - // console.log(w, sliderPos) if (w - sliderPos <= 1 || sliderPos == 0) setTimeout(autoUpdateVault, 3000); // updateVault() would normally be triggered by the 'adDetected' message (above), @@ -112,10 +110,12 @@ onBroadcast(request => { adjustHeight(); createSlider(); break; + case 'hideNotifications': uDom('#notifications').addClass("hide"); adjustHeight(); break; + case 'showNotifications': uDom('#notifications').removeClass("hide"); adjustHeight(); @@ -158,28 +158,26 @@ const renderAds = function (json) { renderNotifications(data.notifications, 'vault'); adjustHeight(); }) - }) + }); + // disable warnings #1910 // Notifications need to be hidden right away for the correct height to be calculated vAPI.messaging.send( - 'adnauseam', { - what: 'getWarningDisabled' - } - ).then(isDisabled => { - if (isDisabled) { - uDom("#notifications").addClass('hide'); - } else { - uDom("#notifications").removeClass('hide'); - } - adjustHeight(); - }) + 'adnauseam', { what: 'getWarningDisabled' }) + .then(isDisabled => { + if (isDisabled) { + uDom("#notifications").addClass('hide'); + } else { + uDom("#notifications").removeClass('hide'); + } + adjustHeight(); + }) vAPI.messaging.send( 'adnauseam', { what: 'getBlurCollectedAds' - } - ).then(blurCollectedAds => { - console.log("blurCollectedAds", blurCollectedAds) + }).then(blurCollectedAds => { + //console.log("blurCollectedAds", blurCollectedAds); if (blurCollectedAds) { uDom("#stage").addClass('blur'); } else { @@ -1196,7 +1194,8 @@ function storeViewState(focusScale) { }, 1000) // restore zoom scale to userZoomScale - dynamicZoom(viewState.zoomScale - viewState.focusScale, { marginLeft: viewState.left, marginTop: viewState.top }); + dynamicZoom(viewState.zoomScale - viewState.focusScale, + { marginLeft: viewState.left, marginTop: viewState.top }); } } @@ -1257,16 +1256,14 @@ function lightboxMode($selected) { if ($selected && !$selected.hasClass('inspected')) { if ($container.hasClass("posTransition")) { - return + return; } const inspectedGid = parseInt($selected.attr('data-gid')); - selectedAdSet = findAdSetByGid(inspectedGid); // throws // lazy-create the meta data for the adset (#61) if (!$selected.children('div.meta').length) { - appendBulletsTo($selected, selectedAdSet); } @@ -1276,14 +1273,12 @@ function lightboxMode($selected) { $selected.find('span.counter-index').show(); // show index-counter bulletIndex($selected, selectedAdSet); - animateInspector($selected); } const next = selectedAdSet.nextPending(); // tell the addon if (next) { - messager.send('adnauseam', { what: 'itemInspected', id: next.id @@ -1291,7 +1286,6 @@ function lightboxMode($selected) { } centerZoom($selected); - $container.addClass('lightbox'); } else if ($container.hasClass('lightbox')) { @@ -1336,16 +1330,12 @@ function animateInspector($inspected) { } function findAdById(id) { - if (gAdSets == undefined || gAdSets == null) return + if (gAdSets === undefined || gAdSets === null) return for (let i = 0, j = gAdSets.length; i < j; i++) { - const childIdx = gAdSets[i].childIdxForId(id); - if (childIdx > -1) { - return { - ad: gAdSets[i].child(childIdx), group: gAdSets[i], index: childIdx @@ -1372,9 +1362,9 @@ function findItemDivByGid(gid) { function findAdSetByGid(gid) { for (let i = 0, j = gAdSets.length; i < j; i++) { - - if (gAdSets[i].gid === gid) + if (gAdSets[i].gid === gid) { return gAdSets[i]; + } } throw Error('No group for gid: ' + gid); @@ -1385,14 +1375,15 @@ function zoomIn(immediate) { // calculate the suitable zoomIdx by userZoomScale const previousState = zoomIdx; for (let i = 0; zoomIdx === previousState && i < Zooms.length; i++) { - - if (userZoomScale === Zooms[i]) + if (userZoomScale === Zooms[i]) { zoomIdx = i; - else if (userZoomScale < Zooms[i] && userZoomScale > Zooms[i + 1]) + } + else if (userZoomScale < Zooms[i] && userZoomScale > Zooms[i + 1]) { zoomIdx = i + 1; + } } - (zoomIdx > 0) && setZoom(--zoomIdx, immediate); + if (zoomIdx > 0) setZoom(--zoomIdx, immediate); } function zoomOut(immediate) { @@ -1400,14 +1391,15 @@ function zoomOut(immediate) { // calculate the suitable zoomIdx by userZoomScale const previousState = zoomIdx; for (let i = 0; zoomIdx === previousState && i < Zooms.length - 1; i++) { - - if (userZoomScale === Zooms[i]) + if (userZoomScale === Zooms[i]) { zoomIdx = i; - else if (userZoomScale < Zooms[i] && userZoomScale > Zooms[i + 1]) + } + else if (userZoomScale < Zooms[i] && userZoomScale > Zooms[i + 1]) { zoomIdx = i; + } } - (zoomIdx < Zooms.length - 1) && setZoom(++zoomIdx, immediate); + if (zoomIdx < Zooms.length - 1) setZoom(++zoomIdx, immediate); } function setScale(scale, targetPos) { @@ -1468,8 +1460,6 @@ function dynamicZoom(scaleInterval, targetPos) { function setZoom(idx, immediate, targetPos) { - //log('setZoom('+idx+','+(immediate===true)+')'); - // Disable transitions immediate && $container.addClass('notransition'); @@ -1488,32 +1478,23 @@ function setZoom(idx, immediate, targetPos) { function onscreen($this, winW, winH, scale, percentVisible) { - const off = $this.offset(), w = $this.width() * scale, h = $this.height() * scale, minX = (-w * (1 - percentVisible)), maxX = (winW - (w * percentVisible)), minY = (-h * (1 - percentVisible)), maxY = (winH - (h * percentVisible)); - - // console.log('onscreen() :: trying: '+Zooms[zoomIdx]+"%",$this.attr('data-gid'),off.left, minX, maxX); - - return (!(off.left < minX || off.left > maxX || off.top < minY || off.top > maxY)); + const off = $this.offset(); + const w = $this.width() * scale; + const h = $this.height() * scale; + const minX = (-w * (1 - percentVisible)); + const minY = (-h * (1 - percentVisible)); + const maxX = (winW - (w * percentVisible)); + const maxY = (winH - (h * percentVisible)); + return !(off.left < minX || off.left > maxX || off.top < minY || off.top > maxY); } function openInNewTab(url) { - window.open(url, '_blank').focus(); } -function asAdArray(adsets) { // remove - - const ads = []; - for (let i = 0, j = adsets.length; i < j; i++) { - for (let k = 0, m = adsets[i].children.length; k < m; k++) - ads.push(adsets[i].children[k]); - } - return ads; -} - function addInterfaceHandlers(ads) { $('#x-close-button').click(function (e) { - e.preventDefault(); messager.send('adnauseam', { what: 'closeExtPage', @@ -1528,14 +1509,11 @@ function addInterfaceHandlers(ads) { }); $('#logo').click(function (e) { - e.preventDefault(); openInNewTab('http://adnauseam.io'); }); $(document).click(function (e) { - - if (e.which === 1) // Left-button only if ($(e.target).parents('.meta-item').length > 0) { return @@ -1544,19 +1522,15 @@ function addInterfaceHandlers(ads) { }); $(document).keyup(function (e) { - (e.keyCode === 27) && lightboxMode(false); // esc (e.keyCode === 73) && toggleInterface(); // 'i' (e.keyCode === 68) && logAdSetInfo(); // 'd' (e.keyCode === 80) && repack(); // 'p' (e.keyCode === 85) && updateVault(waitingAds, true); // 'u' - //console.log(e); }); /////////// DRAG-STAGE /////////// - let offsetX = 0; - let offsetY = 0; - + let offsetX = 0, offsetY = 0; container_div.addEventListener('mousedown', mouseDown, false); container_div.addEventListener('touchstart', touchStart, false); window.addEventListener('touchend', touchEnd, false); @@ -1616,7 +1590,6 @@ function addInterfaceHandlers(ads) { container_div.style.marginLeft = (ml += x_change) + 'px'; container_div.style.marginTop = (mt += y_change) + 'px'; - // container_div.style.transformOrigin = Math.abs(ml+=x_change) + 'px ' + Math.abs(mt+=y_change) + 'px'; offsetX = e.pageX; offsetY = e.pageY; @@ -1731,42 +1704,30 @@ function addInterfaceHandlers(ads) { // Here is where we group individual ads into AdSets, based on their hash, // created from the domain it was found on, and its content-data // If we get too many cross-domain duplicate images, we may need to revisit -// -- called just once per layout +// Note: called just once per layout function createAdSets(ads) { //console.log('Vault-Slider.createAdSets: ' + ads.length + '/' + gAds.length + ' ads'); - - let key; - - let ad; + let key, ad; const hash = {}; const adsets = []; // set hidden val for each ad for (let i = 0; i < ads.length; i++) { - ad = ads[i]; - key = getHash(ad); - if (!key) continue; - if (!hash[key]) { - // new: add a hash entry hash[key] = new AdSet(ad); adsets.push(hash[key]); - } else { - // dup: add as child hash[key].add(ad); } } // sort adset children by foundTs - for (let i = 0; i < adsets.length; i++) { - adsets[i].children.sort(byField('-foundTs')); } @@ -1785,11 +1746,8 @@ function repack() { showVaultAlert(visible ? false : 'no ads found'); const loader = imagesLoaded($container, function () { - if (visible > 1) { - const p = new Packery('#container', { - centered: { y: 10000 }, // centered at half min-height @@ -1800,9 +1758,7 @@ function repack() { computeZoom($items); } else if (visible === 1) { - $items.css({ // center single - top: (10000 - $items.height() / 2) + 'px', left: (10000 - $items.width() / 2) + 'px' }); From e102757f0cbdb13810246c1499531bb09d223fba Mon Sep 17 00:00:00 2001 From: Daniel Howe Date: Tue, 17 Dec 2024 23:20:24 -0500 Subject: [PATCH 2/7] work on capture-mode --- manifest.json | 3 +- platform/common/vapi-common.js | 3 +- src/_locales/en/adnauseam.json | 22 +++-- src/js/adn/adn-utils.js | 6 +- src/js/adn/core.js | 3 +- src/js/adn/options.js | 19 ++-- src/js/adn/vault.js | 155 +++++++++++++++++++-------------- src/js/background.js | 65 +++++++------- src/vault.html | 1 + 9 files changed, 152 insertions(+), 125 deletions(-) diff --git a/manifest.json b/manifest.json index e5eb44f25e062..a8e545ba3627a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,6 @@ { - "version": "3.23.2", + "version": "3.23.3", + "version_name": "portraits", "key": "ilkggpgmkemaniponkfgnkonpajankkm", "author": "Daniel C. Howe", "background": { diff --git a/platform/common/vapi-common.js b/platform/common/vapi-common.js index ad9a0591dca1c..eec5c2eef162f 100644 --- a/platform/common/vapi-common.js +++ b/platform/common/vapi-common.js @@ -166,7 +166,8 @@ vAPI.webextFlavor = { soup.add('ipaddress'); // Whether this is a dev build. - if ( /^\d+\.\d+\.\d+\D/.test(browser.runtime.getManifest().version) ) { + if (browser.runtime.getManifest().version_name === 'portraits') { + console.log('AdNauseam: portrait build'); soup.add('devbuild'); } diff --git a/src/_locales/en/adnauseam.json b/src/_locales/en/adnauseam.json index 90046cf0e8b47..8e753bde478a2 100755 --- a/src/_locales/en/adnauseam.json +++ b/src/_locales/en/adnauseam.json @@ -31,7 +31,7 @@ "message": "Block Malware", "description": "English: Firstrun.html -> Block Malware" }, - "adnAboutResetDataConfirm" : { + "adnAboutResetDataConfirm": { "message": "All your settings will be removed, ads in your vault will be deleted, and AdNauseam will restart.\n\nReset AdNauseam to factory settings?", "description": "Message asking user to confirm reset" }, @@ -71,7 +71,7 @@ "message": "Activate the EasyList filter", "description": "English: Notifications -> Activate the EasyList filter" }, - "adnNotificationActivateAdNauseamList": { + "adnNotificationActivateAdNauseamList": { "message": "Activate the AdNauseam filter", "description": "English: Notifications -> Activate the AdNauseam filter" }, @@ -91,7 +91,7 @@ "message": "The 'Content Blocking' settings in your browser may interfere with AdNauseam!", "description": "English: Notifications -> The 'Content Blocking' settings in your browser may interfere with AdNauseam!" }, - "adnNotificationPrivacyMode":{ + "adnNotificationPrivacyMode": { "message": "You have allowed adnauseam to have access to your online activities while private browsing.", "description": "English: Notifications -> You have allowed adnauseam to have access to your online activities while private browsing." }, @@ -113,7 +113,7 @@ }, "adnNotificationShowAdsDebug": { "message": "The Advanced Setting \"Show Ads Debug\" is turned on", - "description": "English: Notifications -> The Advanced Setting \"Show Ads Debug\" is turned on" + "description": "English: Notifications -> The Advanced Setting \"Show Ads Debug\" is turned on" }, "adnNewerVersionAvailableNotification": { "message": "A newer version of AdNauseam is available", @@ -220,7 +220,7 @@ "description": "appears in ADN settings" }, "adnPurgeConfirm": { - "message": "This action will permanently remove all ads with load image error. Make sure your internet is connected, otherwise all your ads will be deleted.", + "message": "This action will permanently remove all ads for which the image cannot be loaded. It is a good idea to backup your vault before purging, and also to make sure you have an active internet connection.", "description": "appears in ADN settings" }, "adnAdClickingStatusPending": { @@ -363,6 +363,10 @@ "message": "Purge Dead Ads", "description": "appears on vault page" }, + "adnCaptureVault": { + "message": "Capture", + "description": "appears on vault page" + }, "adnVaultFound": { "message": "{{total}} ads collected", "description": "appears on vault page" @@ -475,9 +479,9 @@ "message": "Languages", "description": "English: Languages" }, - "3pPageUpdate":{ - "message":"Update", - "description":"English: update" + "3pPageUpdate": { + "message": "Update", + "description": "English: update" }, "adnUpdateButton": { "message": "Update", @@ -535,4 +539,4 @@ "message": "Ads not collected", "description": "Ads are present on page but none are collected" } -} +} \ No newline at end of file diff --git a/src/js/adn/adn-utils.js b/src/js/adn/adn-utils.js index 242618014e0d5..7c9d2e2c334e3 100644 --- a/src/js/adn/adn-utils.js +++ b/src/js/adn/adn-utils.js @@ -109,14 +109,14 @@ export const rand = function (min, max) { }; export const setCost = function (numVisited) { - var constPerClick = 0 + var costPerClick = 0 vAPI.messaging.send('dashboard', {what:'getCostPerClick'}).then(response => { - constPerClick = response + costPerClick = response const $west = uDom('#worth-estimate'), $cost = uDom('.cost'); if (numVisited > 0) { $cost.removeClass('hidden'); - $west.text('= $' + (numVisited * constPerClick).toFixed(2)); + $west.text('= $' + (numVisited * costPerClick).toFixed(2)); } else { $cost.addClass('hidden'); } diff --git a/src/js/adn/core.js b/src/js/adn/core.js index 97fa58b82f14b..15556957932ff 100644 --- a/src/js/adn/core.js +++ b/src/js/adn/core.js @@ -1574,7 +1574,8 @@ const adnauseam = (function () { hidingDisabled: !us.hidingAds || showDnt, clickingDisabled: !us.clickingAds, textAdsDisabled: !us.parseTextAds, - logEvents: us.eventLogging + vaultCaptureMode: us.vaultCaptureMode, // for-capture + logEvents: us.eventLogging, }; }; diff --git a/src/js/adn/options.js b/src/js/adn/options.js index 1bc6379240a4d..ccb6412b10bdb 100644 --- a/src/js/adn/options.js +++ b/src/js/adn/options.js @@ -138,12 +138,11 @@ const changeUserSettings = function (name, value) { updateGroupState(); }); // reflect some changes immediately - switch ( name ) { + switch (name) { case 'colorBlindFriendly': - console.log("colorBlindFriendly", value) - setTheme(value ? 'colorBlind' : 'dark', true); - break; - } + setTheme(value ? 'colorBlind' : 'dark', true); + break; + } }; /******************************************************************************/ @@ -185,10 +184,10 @@ const onDisableWarningChanged = function (ev) { // send to messaging so that the change is broadcasted to all tabs vAPI.messaging.send( 'adnauseam', { - what: 'setWarningDisabled', - value, value - } - ) + what: 'setWarningDisabled', + value, value + } + ) } // Workaround for: @@ -208,7 +207,7 @@ const updateGroupState = function () { uDom('.clickingAds-child').prop('disabled', !uDom('#clickingAds').prop('checked')); uDom('.clickingAds-child').parent().parent().parent().toggleClass('disabled', !uDom('#clickingAds').prop('checked')); - + /* blocking malware doesnt have any subgroup uDom('.blockingMalware-child').prop('disabled', !uDom('#blockingMalware').prop('checked')); diff --git a/src/js/adn/vault.js b/src/js/adn/vault.js index 269e5904d9555..51918af476d37 100644 --- a/src/js/adn/vault.js +++ b/src/js/adn/vault.js @@ -21,10 +21,11 @@ 'use strict'; -import { i18n$ } from "../i18n.js"; import uDom from './uDom.js'; + +import { i18n$ } from "../i18n.js"; +import { onBroadcast } from '../broadcast.js'; import { renderNotifications } from './notifications.js'; -import { broadcast, onBroadcast } from '../broadcast.js'; import { byField, @@ -45,8 +46,7 @@ import { const States = ['pending', 'visited', 'failed', 'dnt-allowed', 'image-error'], Zooms = [400, 200, 150, 100, 75, 50, 25, 12.5, 7.5, 5], EnableContextMenu = 1, - MaxStartNum = 300, - MaxPerSet = 9; + MaxStartNum = 300; const margin = { top: 50, @@ -65,11 +65,10 @@ let userZoomScale = Zooms[Zooms.indexOf(100)]; // determined by zoom in / out buttons let zoomIdx = 0; -let zoomStyle, animatorId, resizeId, selectedAdSet; +let animatorId, resizeId, selectedAdSet; let showInterface = true; let draggingVault = false; let vaultLoading = false; -let isInspectingAd = false; const container_div = document.getElementById('container'); const $container = $('#container') @@ -139,7 +138,8 @@ function $height(ele) { const renderAds = function (json) { - // console.log('renderAds: ', json); + console.log('renderAds: ', json); + gAds = json.data; // store addInterfaceHandlers(); settings = json.prefs; @@ -154,8 +154,9 @@ const renderAds = function (json) { 'adnauseam', { what: 'getNotifications' }).then(data => { - if (data.notifications && data.notifications.length) + if (data.notifications && data.notifications.length) { renderNotifications(data.notifications, 'vault'); + } adjustHeight(); }) }); @@ -183,7 +184,7 @@ const renderAds = function (json) { } else { uDom("#stage").removeClass('blur'); } - }) + }); }; const autoUpdateVault = function () { @@ -314,6 +315,10 @@ function parseAd(ad, data) { } function analyze(adsets) { + displayStatistics(extractData(adsets)); +} + +function extractData(adsets) { let data = { totalImg: 0, totalText: 0, @@ -338,7 +343,7 @@ function analyze(adsets) { data.adNetworks = sortDict(data.adNetworks); data.total = data.totalImg + data.totalText; //console.log(data); - displayStatistics(data); + return data; } function displayStatistics(data) { @@ -933,65 +938,61 @@ function computeStats(adsets) { const numVisits = numVisited(gAds); $('.since').text(i18n$("adnVaultSince").replace('{{datetime}}', sinceTime(adsets))); - $('.clicked').text(i18n$("adnMenuAdsClicked").replace('{{number}}', numVisits)); - $('.total').text(i18n$("adnVaultFound").replace('{{total}}', numTotal())); $('#detected').text(numFound(adsets)); - if (numTotal() != numFound(adsets)) + if (numTotal() != numFound(adsets)) { $('.showing').show(); - else + } + else { $('.showing').hide(); + } setCost(numVisits); } -function numVisible() { - return $('.item').length; -} - function numVisited(adsets) { - //TODO: update after visit let numv = 0; - - for (let i = 0, j = adsets && adsets.length; i < j; i++) + for (let i = 0, j = adsets && adsets.length; i < j; i++) { numv += (adsets[i].visitedTs > 0); - + } return numv; } function numFound(adsets) { - let numv = 0; - - for (let i = 0, j = adsets && adsets.length; i < j; i++) + for (let i = 0, j = adsets && adsets.length; i < j; i++) { numv += (adsets[i].count()); - + } return numv; } function numTotal() { - return gAds.length; } function sinceTime(adsets) { - - let idx = 0, oldest = +new Date(); - + let oldest = +new Date(); for (let i = 0, j = adsets && adsets.length; i < j; i++) { - const foundTs = adsets[i].child(0).foundTs; if (foundTs < oldest) { - oldest = foundTs; - idx = i; } } - return formatDate(oldest); } +function untilTime(adsets) { + let youngest = 0; + for (let i = 0, j = adsets && adsets.length; i < j; i++) { + const foundTs = adsets[i].child(0).foundTs; + if (foundTs > youngest) { + youngest = foundTs; + } + } + return formatDate(youngest); +} + function formatTargetDate(ad) { const dntNote = i18n$('adnAllowedByDNT') + " ? ", frequencyNote = i18n$('adnAdClickingStatusSkippedFrequency'), userNote = i18n$('adnAdClickingStatusSkippedUser'); @@ -1200,19 +1201,15 @@ function storeViewState(focusScale) { } function logAdSetInfo() { - if (selectedAdSet) { - console.log("Logging JSON for AdSet #" + selectedAdSet.gid); - messager.send('adnauseam', { what: 'logAdSet', gid: selectedAdSet.gid, ids: selectedAdSet.childIds() }).then(data => { location.href = "data:text/plain," + encodeURI(data); - }) - + }); } } @@ -1221,17 +1218,12 @@ const ifs = ['#logo', '#ratio', '#stats', '#svgcon', '#x-close-button', '.zoom', function toggleInterface() { showInterface = !showInterface; - if (!showInterface) { - $("body").css('background-image', 'none') - .css({ - 'background-color': '#fff' - }); - - ifs.forEach(function (s) { - $(s).hide(); - }); + $("body") + .css('background-image', 'none') + .css({ 'background-color': '#fff' }); + ifs.forEach(s => $(s).hide()); // remove all duplicate classes (TODO: just hide them) $(".item").removeClass(function (i, css) { @@ -1239,15 +1231,10 @@ function toggleInterface() { }).addClass('dup-count-1'); } else { - - $("body").css('background-image', 'url(../img/gray_grid.png)') - .css({ - 'background-color': '#000' - }); - - ifs.forEach(function (s) { - $(s).show(); - }); + $("body") + .css('background-image', 'url(../img/gray_grid.png)') + .css({ 'background-color': '#000' }); + ifs.forEach(s => $(s).show()); } } @@ -1969,7 +1956,6 @@ function createSlider(mode) { runFilter([gMin, gMax]) break; case "update": - // console.log(gMin, new Date()) const ext = [gMin, new Date()]; doLayout(runFilter(ext), true) break; @@ -1982,7 +1968,6 @@ function createSlider(mode) { // this is called on brushend() and createSlider() function runFilter(ext) { - // console.log('vault.js::runFilter: '+ext[0]+","+ext[1]); centerContainer(); gMin = ext[0], gMax = ext[1]; @@ -1992,11 +1977,6 @@ function createSlider(mode) { // make sure the sliders are always visible if (gMax - gMin <= 0) d3.select('.resize').style("display", "block"); - // if (gAdSets != null && gAds.length !== 1 && gMax - gMin < 0) { - // //console.log('vault-slider::ignore-micro: ' + ext[0] + "," + ext[1]); - // return; // gAdSets || (gAdSets = createAdSets(gAds)); // fix for gh #100 - // } - if (gAds.length >= MaxStartNum) { uDom("a[class=showing-help]").text("?") uDom("a[class=showing-help]").addClass("help-mark") @@ -2081,6 +2061,50 @@ function createSlider(mode) { } } +function onCapture() { // save screenshot + + toggleInterface(showInterface = true); + browser.tabs.captureVisibleTab(imgUrl => { + const saveImageToFile = (image, filename) => { + const canvas = document.createElement('canvas'); + canvas.width = image.width; + canvas.height = image.height; + const ctx = canvas.getContext('2d'); + ctx.drawImage(image, 0, 0); + + // Convert canvas to data URL + const dataURL = canvas.toDataURL(); + + // Create a link element and trigger a download + const anchor = document.createElement('a'); + anchor.href = dataURL; + anchor.download = filename; + anchor.click(); + }; + console.log(gAds, gAdSets, gMin, gMax); + + let meta = extractData(gAds); + meta.sinceTime = sinceTime(gAdSets); + meta.untilTime = untilTime(gAdSets); + meta.minDate = formatDate(gMin); + meta.maxDate = formatDate(gMax); + meta.clicked = numVisited(gAds); + meta.total = numTotal(); + meta.detected = numFound(gAdSets); + meta.cost = '$' + (meta.clicked * 1.03).toFixed(2); + console.log(meta); + + const screenshot = new Image(); + screenshot.src = imgUrl; + screenshot.onload = () => { + saveImageToFile(screenshot, 'screenshot.png'); + setTimeout(() => { + toggleInterface(showInterface = false); + }, 5000); + }; + }); +}; + function onPurgeDeadAds() { let deadAds = getDeadAds() if (deadAds.length > 0) { @@ -2089,6 +2113,7 @@ function onPurgeDeadAds() { console.log("no dead ads to purge") } } + function getDeadAds() { let adsGids = [] document.querySelectorAll(".image-error").forEach(el => { @@ -2271,7 +2296,6 @@ AdSet.prototype.groupState = function () { } const failed = this.failedCount(); - return failed ? 'failed' : 'pending'; }; @@ -2286,3 +2310,4 @@ $('#import').on('click', startImportFilePicker); $('#importFilePicker').on('change', handleImportAds); $('#reset').on('click', clearAds); $('#purge').on('click', onPurgeDeadAds); +$('#capture').on('click', onCapture); diff --git a/src/js/background.js b/src/js/background.js index 136d8f8fcbe7c..419c42cf00f38 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -36,8 +36,8 @@ import { adnlogSet } from './console.js'; // Not all platforms may have properly declared vAPI.webextFlavor. -if ( vAPI.webextFlavor === undefined ) { - vAPI.webextFlavor = { major: 0, soup: new Set([ 'ublock' ]) }; +if (vAPI.webextFlavor === undefined) { + vAPI.webextFlavor = { major: 0, soup: new Set(['ublock']) }; } /******************************************************************************/ @@ -94,17 +94,11 @@ const hiddenSettingsDefault = { internalLinkDomains: internalLinkDomainsDefault.join(','), // Adn }; -if ( vAPI.webextFlavor.soup.has('devbuild') ) { - hiddenSettingsDefault.consoleLogLevel = 'info'; - hiddenSettingsDefault.cacheStorageAPI = 'unset'; - adnlogSet(true); -} - const userSettingsDefault = { ////////////////// ADN ////////////////// - admap: {}, + admap: {}, dntDomains: [], parseTextAds: true, eventLogging: false, @@ -136,6 +130,7 @@ const userSettingsDefault = { cnameUncloakEnabled: true, collapseBlocked: true, colorBlindFriendly: false, + vaultCaptureMode: false, contextMenuEnabled: true, uiAccentCustom: false, uiAccentCustom0: '#aca0f7', @@ -157,14 +152,17 @@ const userSettingsDefault = { webrtcIPAddressHidden: false, }; +if (vAPI.webextFlavor.soup.has('devbuild')) { + userSettingsDefault.vaultCaptureMode = true; // for capture + hiddenSettingsDefault.consoleLogLevel = 'info'; + hiddenSettingsDefault.cacheStorageAPI = 'unset'; + adnlogSet(true); +} + /* Adn https://github.com/dhowe/AdNauseam/issues/2040 */ const allowAnyBlockOnDomains = ['youtube.com', 'funnyordie.com']; // no dnt in here - -const strictBlockDefault = allowAnyBlockOnDomains.map( - d => d + ' * * strictBlock' -) - +const strictBlockDefault = allowAnyBlockOnDomains.map(d => d + ' * * strictBlock'); const dynamicFilteringDefault = [ 'behind-the-scene * * noop', 'behind-the-scene * image noop', @@ -177,13 +175,10 @@ const dynamicFilteringDefault = [ /* end of Adn */ -const hostnameSwitchesDefault = [ - 'no-large-media: behind-the-scene false', -]; - +const hostnameSwitchesDefault = [ 'no-large-media: behind-the-scene false' ]; // https://github.com/LiCybora/NanoDefenderFirefox/issues/196 -if ( vAPI.webextFlavor.soup.has('firefox') ) { +if (vAPI.webextFlavor.soup.has('firefox')) { hostnameSwitchesDefault.push('no-csp-reports: * true'); } @@ -234,7 +229,7 @@ const µBlock = { // jshint ignore:line blockedRequestCount: 0, allowedRequestCount: 0 }, - + requestStats: { blockedCount: 0, allowedCount: 0, @@ -277,7 +272,7 @@ const µBlock = { // jshint ignore:line // settings. The content of 'assets.json' will also tell which filter // lists to enable by default when uBO is first installed. assetsBootstrapLocation: undefined, - + /* ADN - no need for us to use dev assets for dev build, but it is something we can implement later. assetsJsonPath: vAPI.webextFlavor.soup.has('devbuild') @@ -310,7 +305,7 @@ const µBlock = { // jshint ignore:line storageQuota: vAPI.storage.QUOTA_BYTES, storageUsed: 0, - noopFunc: function(){}, + noopFunc: function () { }, apiErrorCount: 0, @@ -360,8 +355,8 @@ const µBlock = { // jshint ignore:line } maybeFromDocumentURL(documentUrl) { - if ( documentUrl === undefined ) { return; } - if ( documentUrl.startsWith(this.tabOrigin) ) { return; } + if (documentUrl === undefined) { return; } + if (documentUrl.startsWith(this.tabOrigin)) { return; } this.tabOrigin = originFromURI(µBlock.normalizeTabURL(0, documentUrl)); this.tabHostname = hostnameFromURI(this.tabOrigin); this.tabDomain = domainFromHostname(this.tabHostname); @@ -374,7 +369,7 @@ const µBlock = { // jshint ignore:line const tabId = details.tabId; this.type = details.type; const isMainFrame = this.itype === this.MAIN_FRAME; - if ( isMainFrame && tabId > 0 ) { + if (isMainFrame && tabId > 0) { µBlock.tabContextManager.push(tabId, details.url); } this.fromTabId(tabId); // Must be called AFTER tab context management @@ -385,16 +380,16 @@ const µBlock = { // jshint ignore:line this.aliasURL = details.aliasURL || undefined; this.redirectURL = undefined; this.filter = undefined; - if ( this.itype !== this.SUB_FRAME ) { + if (this.itype !== this.SUB_FRAME) { this.docId = details.frameId; this.frameId = -1; } else { this.docId = details.parentFrameId; this.frameId = details.frameId; } - if ( this.tabId > 0 ) { - if ( this.docId === 0 ) { - if ( isMainFrame === false ) { + if (this.tabId > 0) { + if (this.docId === 0) { + if (isMainFrame === false) { this.maybeFromDocumentURL(details.documentUrl); } this.docOrigin = this.tabOrigin; @@ -402,20 +397,20 @@ const µBlock = { // jshint ignore:line this.docDomain = this.tabDomain; return this; } - if ( details.documentUrl !== undefined ) { + if (details.documentUrl !== undefined) { this.setDocOriginFromURL(details.documentUrl); return this; } const pageStore = µBlock.pageStoreFromTabId(this.tabId); const docStore = pageStore && pageStore.getFrameStore(this.docId); - if ( docStore ) { + if (docStore) { this.setDocOriginFromURL(docStore.rawURL); } else { this.setDocOrigin(this.tabOrigin); } return this; } - if ( details.documentUrl !== undefined ) { + if (details.documentUrl !== undefined) { const origin = originFromURI( µBlock.normalizeTabURL(0, details.documentUrl) ); @@ -430,7 +425,7 @@ const µBlock = { // jshint ignore:line } getTabOrigin() { - if ( this.tabOrigin === undefined ) { + if (this.tabOrigin === undefined) { const tabContext = µBlock.tabContextManager.mustLookup(this.tabId); this.tabOrigin = tabContext.origin; this.tabHostname = tabContext.rootHostname; @@ -457,11 +452,11 @@ const µBlock = { // jshint ignore:line filter: undefined, }; // Many filters may have been applied to the current context - if ( Array.isArray(this.filter) === false ) { + if (Array.isArray(this.filter) === false) { details.filter = this.filter; return logger.writeOne(details); } - for ( const filter of this.filter ) { + for (const filter of this.filter) { details.filter = filter; logger.writeOne(details); } diff --git a/src/vault.html b/src/vault.html index 2f00bdab3bcd3..36f2a6096a336 100644 --- a/src/vault.html +++ b/src/vault.html @@ -73,6 +73,7 @@

+ From 561d1c370b71ccbdaee9aebb6ef5e7447431cf28 Mon Sep 17 00:00:00 2001 From: dhowe Date: Thu, 19 Dec 2024 19:50:53 -0500 Subject: [PATCH 3/7] implement file-name-tagging and meta-data in image --- src/js/adn/vault.js | 130 ++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/src/js/adn/vault.js b/src/js/adn/vault.js index 51918af476d37..4b79a18a97ae5 100644 --- a/src/js/adn/vault.js +++ b/src/js/adn/vault.js @@ -124,22 +124,8 @@ onBroadcast(request => { /********************************************************************/ -function $width(ele) { - - ele = ele ? (ele.length ? ele.nodes[0] : ele) : 0; - return ele ? ele.offsetWidth || ele.clientWidth : -1; -} - -function $height(ele) { - - ele = ele ? (ele.length ? ele.nodes[0] : ele) : 0; - return ele ? ele.offsetHeight || ele.clientHeight : -1; -} - const renderAds = function (json) { - console.log('renderAds: ', json); - gAds = json.data; // store addInterfaceHandlers(); settings = json.prefs; @@ -268,7 +254,7 @@ function setCurrent(ad) { function doLayout(adsets, update) { adsets = adsets || []; - // console.log('Vault.doLayout: ' + adsets.length + " ad-sets, total=" + numFound(adsets)); + //console.log('Vault.doLayout: ' + adsets.length + " ad-sets, total=" + numFound(adsets)); vaultLoading = true; if (!update) $('.item').remove(); @@ -333,6 +319,7 @@ function extractData(adsets) { data = parseAd(ad, data); } else { //adsets + console.log(i + ') multiple'); for (const key in adsets[i].children) { const ad = adsets[i].children[key]; data = parseAd(ad, data); @@ -342,6 +329,7 @@ function extractData(adsets) { data.sites = sortDict(data.sites); data.adNetworks = sortDict(data.adNetworks); data.total = data.totalImg + data.totalText; + //console.log(data); return data; } @@ -1000,7 +988,9 @@ function formatTargetDate(ad) { } function formatDate(ts) { - if (!ts) return settings.clickingDisabled ? i18n$('adnAdClickingStatusSkippedDisabled') : i18n$('adnNotYetVisited'); + if (!ts) return settings.clickingDisabled ? + i18n$('adnAdClickingStatusSkippedDisabled') + : i18n$('adnNotYetVisited'); function getLocale() { return navigator.languages[0] || navigator.language; @@ -1012,8 +1002,7 @@ function formatDate(ts) { hour: 'numeric', minute: 'numeric' }; - const result = typeof Intl === "object" ? new Intl.DateTimeFormat(getLocale(), options).format(date) : date; - return result; + return typeof Intl === "object" ? new Intl.DateTimeFormat(getLocale(), options).format(date) : date; } function enableLightbox() { @@ -1802,10 +1791,11 @@ function createSlider(mode) { // finding the first and last ad const minDate = d3.min(gAds, function (d) { return d.foundTs; - }), - maxDate = d3.max(gAds, function (d) { - return d.foundTs; - }); + }); + + const maxDate = d3.max(gAds, function (d) { + return d.foundTs; + }); // mapping the scales const xScale = d3.time.scale() @@ -1938,7 +1928,7 @@ function createSlider(mode) { } // cases: - // 1) [default]]reload vault: doLayout, update slider - runFilter() + // 1) [default] reload vault: doLayout, update slider - runFilter() // 2) "update": updateLayout, same slider // 3) "delete": skipLayout, same slider // 4) "resize": repack, remap slider @@ -2028,15 +2018,11 @@ function createSlider(mode) { function dateFilter(min, max) { - //log('dateFilter: min='+min+', max='+max); - const filtered = []; // NOTE: always need to start from full-set (all) here for (let i = 0, j = gAds.length; i < j; i++) { - if (!(gAds[i].foundTs < min || gAds[i].foundTs > max)) { - filtered.push(gAds[i]); } } @@ -2064,45 +2050,57 @@ function createSlider(mode) { function onCapture() { // save screenshot toggleInterface(showInterface = true); - browser.tabs.captureVisibleTab(imgUrl => { - const saveImageToFile = (image, filename) => { - const canvas = document.createElement('canvas'); - canvas.width = image.width; - canvas.height = image.height; - const ctx = canvas.getContext('2d'); - ctx.drawImage(image, 0, 0); - - // Convert canvas to data URL - const dataURL = canvas.toDataURL(); - - // Create a link element and trigger a download - const anchor = document.createElement('a'); - anchor.href = dataURL; - anchor.download = filename; - anchor.click(); - }; - console.log(gAds, gAdSets, gMin, gMax); - - let meta = extractData(gAds); - meta.sinceTime = sinceTime(gAdSets); - meta.untilTime = untilTime(gAdSets); - meta.minDate = formatDate(gMin); - meta.maxDate = formatDate(gMax); - meta.clicked = numVisited(gAds); - meta.total = numTotal(); - meta.detected = numFound(gAdSets); - meta.cost = '$' + (meta.clicked * 1.03).toFixed(2); - console.log(meta); - - const screenshot = new Image(); - screenshot.src = imgUrl; - screenshot.onload = () => { - saveImageToFile(screenshot, 'screenshot.png'); - setTimeout(() => { - toggleInterface(showInterface = false); - }, 5000); - }; - }); + setTimeout(() => { + browser.tabs.captureVisibleTab(imgUrl => { + const saveImageToFile = (image, meta) => { + const canvas = document.createElement('canvas'); + canvas.width = image.width; + canvas.height = image.height; + const ctx = canvas.getContext('2d'); + ctx.drawImage(image, 0, 0); + + // create a meta data string and fname for the image + let metaText = `Clicked ${meta.clicked} of ${meta.count} ads, from ${meta.minDate} to ${meta.maxDate}, costing ${meta.cost}.`; + let metaName = `${meta.clicked}-${meta.count}-${meta.gMin}-${meta.gMax}-${meta.cost.substring(1)}.png`; + console.log('Saving image: ' + metaName); + + // write meta data to upper left corner + ctx.fillStyle = 'black'; + ctx.fillText(metaText, 20, 20); + + // Convert canvas to data URL + const dataURL = canvas.toDataURL(); + + // Create a link element and trigger a download + const anchor = document.createElement('a'); + anchor.href = dataURL; + anchor.download = metaName; + anchor.click(); + }; + + // create a subset of visited ads where foundTs is within the range gMin to gMax + let subset = gAds.filter(ad => ad.foundTs >= gMin && ad.foundTs <= gMax); + + let meta = extractData(subset); + meta.count = subset.length; + meta.clicked = numVisited(subset); + meta.cost = (meta.clicked * 1.03).toFixed(2); + meta.gMin = Date.parse(gMin); + meta.gMax = Date.parse(gMax); + meta.minDate = gMin; + meta.maxDate = gMax; + + const screenshot = new Image(); + screenshot.src = imgUrl; + screenshot.onload = () => { + saveImageToFile(screenshot, meta); + setTimeout(() => { + toggleInterface(showInterface = false); + }, 5000); + }; + + }); + }, 1000); }; function onPurgeDeadAds() { From 45e3a37b7f4d4f43ba87a828fa31d531dddecbfa Mon Sep 17 00:00:00 2001 From: dhowe Date: Thu, 19 Dec 2024 20:27:50 -0500 Subject: [PATCH 4/7] minor refactors --- manifest.json | 2 +- platform/common/vapi-common.js | 3 +- src/_locales/en/adnauseam.json | 2 +- src/css/vault.css | 2 +- src/js/adn/adn-utils.js | 2 +- src/js/adn/core.js | 4 +- src/js/adn/firstrun.js | 2 +- src/js/adn/log.js | 2 +- src/js/adn/menu.js | 2 +- src/js/adn/notifications.js | 2 +- src/js/adn/options.js | 2 +- src/js/adn/parser.js | 2 +- src/js/adn/tests.js | 2 +- src/js/adn/textads.js | 2 +- src/js/adn/vault.js | 76 +++------- src/js/background.js | 4 +- src/vault.html | 248 +++++++++++++++++---------------- 17 files changed, 166 insertions(+), 193 deletions(-) diff --git a/manifest.json b/manifest.json index a8e545ba3627a..11af62d96589f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "version": "3.23.3", - "version_name": "portraits", + "version_name": "3.23.3-dev", "key": "ilkggpgmkemaniponkfgnkonpajankkm", "author": "Daniel C. Howe", "background": { diff --git a/platform/common/vapi-common.js b/platform/common/vapi-common.js index eec5c2eef162f..35ccf2b476f70 100644 --- a/platform/common/vapi-common.js +++ b/platform/common/vapi-common.js @@ -166,8 +166,7 @@ vAPI.webextFlavor = { soup.add('ipaddress'); // Whether this is a dev build. - if (browser.runtime.getManifest().version_name === 'portraits') { - console.log('AdNauseam: portrait build'); + if (browser.runtime.getManifest().version_name.endsWith('dev')) { soup.add('devbuild'); } diff --git a/src/_locales/en/adnauseam.json b/src/_locales/en/adnauseam.json index 8e753bde478a2..a4df5537e7549 100755 --- a/src/_locales/en/adnauseam.json +++ b/src/_locales/en/adnauseam.json @@ -365,7 +365,7 @@ }, "adnCaptureVault": { "message": "Capture", - "description": "appears on vault page" + "description": "appears on vault page in dev mode" }, "adnVaultFound": { "message": "{{total}} ads collected", diff --git a/src/css/vault.css b/src/css/vault.css index 5039d1d0140a8..3b4c3df8fc5d2 100755 --- a/src/css/vault.css +++ b/src/css/vault.css @@ -4,7 +4,7 @@ html { body { height: 100%; - background: #000 url(../img/gray_grid.png); + color: #4C4D4C; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; margin: 0; diff --git a/src/js/adn/adn-utils.js b/src/js/adn/adn-utils.js index 7c9d2e2c334e3..0f77579c74661 100644 --- a/src/js/adn/adn-utils.js +++ b/src/js/adn/adn-utils.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/core.js b/src/js/adn/core.js index 15556957932ff..15aadea555154 100644 --- a/src/js/adn/core.js +++ b/src/js/adn/core.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1574,8 +1574,8 @@ const adnauseam = (function () { hidingDisabled: !us.hidingAds || showDnt, clickingDisabled: !us.clickingAds, textAdsDisabled: !us.parseTextAds, - vaultCaptureMode: us.vaultCaptureMode, // for-capture logEvents: us.eventLogging, + devMode: us.devMode, }; }; diff --git a/src/js/adn/firstrun.js b/src/js/adn/firstrun.js index 468e37ee12c57..d37dc07037c41 100644 --- a/src/js/adn/firstrun.js +++ b/src/js/adn/firstrun.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/log.js b/src/js/adn/log.js index df4d1cdcf97e5..9159d24bc4801 100644 --- a/src/js/adn/log.js +++ b/src/js/adn/log.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/menu.js b/src/js/adn/menu.js index 8ab69d9cf8af1..342cb4aee226e 100644 --- a/src/js/adn/menu.js +++ b/src/js/adn/menu.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/notifications.js b/src/js/adn/notifications.js index 52ac04b9b9936..966426f1a4ba0 100644 --- a/src/js/adn/notifications.js +++ b/src/js/adn/notifications.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/options.js b/src/js/adn/options.js index ccb6412b10bdb..3be5df0eda71e 100644 --- a/src/js/adn/options.js +++ b/src/js/adn/options.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/parser.js b/src/js/adn/parser.js index a47fbbb4d2ce8..81a936248bfea 100644 --- a/src/js/adn/parser.js +++ b/src/js/adn/parser.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/tests.js b/src/js/adn/tests.js index 63dbff9710d02..d5ebe8101e7aa 100644 --- a/src/js/adn/tests.js +++ b/src/js/adn/tests.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/textads.js b/src/js/adn/textads.js index 0f5ab58380148..19b749b171471 100644 --- a/src/js/adn/textads.js +++ b/src/js/adn/textads.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/js/adn/vault.js b/src/js/adn/vault.js index 4b79a18a97ae5..1d6e12b16be1d 100644 --- a/src/js/adn/vault.js +++ b/src/js/adn/vault.js @@ -1,7 +1,7 @@ /******************************************************************************* AdNauseam - Fight back against advertising surveillance. - Copyright (C) 2014-2021 Daniel C. Howe + Copyright (C) 2014-2024 Daniel C. Howe This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,6 +43,8 @@ import { clearAds } from './adn-utils.js'; +// note: this code is a mess and needs to be refactored + const States = ['pending', 'visited', 'failed', 'dnt-allowed', 'image-error'], Zooms = [400, 200, 150, 100, 75, 50, 25, 12.5, 7.5, 5], EnableContextMenu = 1, @@ -126,6 +128,8 @@ onBroadcast(request => { const renderAds = function (json) { + //console.log("renderAds", json); + gAds = json.data; // store addInterfaceHandlers(); settings = json.prefs; @@ -171,6 +175,11 @@ const renderAds = function (json) { uDom("#stage").removeClass('blur'); } }); + + if (settings.devMode) { + console.log("devMode: enabling capture button"); + $('#capture').removeClass('item-hidden'); + } }; const autoUpdateVault = function () { @@ -2060,8 +2069,8 @@ function onCapture() { // save screenshot ctx.drawImage(image, 0, 0); // create a meta data string and fname for the image - let metaText = `Clicked ${meta.clicked} of ${meta.count} ads, from ${meta.minDate} to ${meta.maxDate}, costing ${meta.cost}.`; - let metaName = `${meta.clicked}-${meta.count}-${meta.gMin}-${meta.gMax}-${meta.cost.substring(1)}.png`; + let metaText = `Clicked ${meta.clicked} of ${meta.count} ads, from ${meta.minDate} to ${meta.maxDate}, costing $${meta.cost}.`; + let metaName = `${meta.clicked}-${meta.count}-${meta.gMin}-${meta.gMax}-${meta.cost}.png`; console.log('Saving image: ' + metaName); // write meta data to upper left corner @@ -2113,12 +2122,10 @@ function onPurgeDeadAds() { } function getDeadAds() { - let adsGids = [] - document.querySelectorAll(".image-error").forEach(el => { - adsGids.push(parseInt(el.getAttribute('data-gid'))) - }) - let deadAds = gAdSets.filter(adset => adsGids.includes(adset.gid)) - return deadAds + let adsGids = []; + document.querySelectorAll(".image-error") + .forEach(el => adsGids.push(parseInt(el.getAttribute('data-gid')))); + return gAdSets.filter(adset => adsGids.includes(adset.gid)) } /********************************************************************/ @@ -2127,7 +2134,6 @@ const TEXT_MINW = 150, TEXT_MAXW = 450; function AdSet(ad) { - this.gid = Math.abs(createGid(ad)); this.children = []; this.index = 0; @@ -2135,113 +2141,73 @@ function AdSet(ad) { } AdSet.prototype.id = function (i) { - return this.child(i).id; }; AdSet.prototype.childIds = function () { - const ids = []; - for (let i = 0, j = this.children.length; i < j; i++) { - this.children[i] && ids.push(this.children[i].id); } - return ids; }; AdSet.prototype.childIdxForId = function (id) { - for (let i = 0, j = this.children.length; i < j; i++) { - - if (this.children[i].id === id) - return i; + if (this.children[i].id === id) return i; } - return -1; }; AdSet.prototype.child = function (i) { - return this.children[(typeof i === 'undefined') ? this.index : i]; }; AdSet.prototype.state = function (i) { - const ad = this.child(i) || i; - if (!ad) console.warn('invalid index!'); - - if (ad.dntAllowed) { - return 'dnt-allowed'; - } + if (ad.dntAllowed) return 'dnt-allowed'; // ad should not be 'failed' until 3 failed visits (gh #64) if (ad.visitedTs === 0 || (ad.attempts < 3 && ad.visitedTs < 0)) { return 'pending'; } - return ad.visitedTs < 0 ? 'failed' : 'visited'; }; AdSet.prototype.type = function () { - return this.children[0].contentType; // same-for-all }; AdSet.prototype.failedCount = function () { - const containerObj = this; - - return this.children.filter(function (d) { - - return containerObj.state(d) === 'failed'; - - }).length;// === containerObj.children.length; + return this.children.filter((d) => containerObj.state(d) === 'failed').length; }; AdSet.prototype.dntCount = function () { - const containerObj = this; - - return this.children.filter(function (d) { - - return containerObj.state(d) === 'dnt-allowed'; - - }).length;// === containerObj.children.length; + return this.children.filter((d) => containerObj.state(d) === 'dnt-allowed').length; }; AdSet.prototype.visitedCount = function () { - - return this.children.filter(function (d) { - - return d.visitedTs > 0; - - }).length; + return this.children.filter((d) => d.visitedTs > 0).length; }; AdSet.prototype.nextPending = function () { - const ads = this.children.slice(); ads.sort(byField('-foundTs')); - for (let i = 0, j = ads.length; i < j; i++) { - if (ads[i].visitedTs === 0) // pending return ads[i]; } - return null; }; AdSet.prototype.count = function () { - return this.children.length; }; AdSet.prototype.add = function (ad) { - ad && this.children.push(ad); }; diff --git a/src/js/background.js b/src/js/background.js index 419c42cf00f38..5a6a0c1e3d373 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -99,6 +99,7 @@ const userSettingsDefault = { ////////////////// ADN ////////////////// admap: {}, + devMode: false, dntDomains: [], parseTextAds: true, eventLogging: false, @@ -130,7 +131,6 @@ const userSettingsDefault = { cnameUncloakEnabled: true, collapseBlocked: true, colorBlindFriendly: false, - vaultCaptureMode: false, contextMenuEnabled: true, uiAccentCustom: false, uiAccentCustom0: '#aca0f7', @@ -153,7 +153,7 @@ const userSettingsDefault = { }; if (vAPI.webextFlavor.soup.has('devbuild')) { - userSettingsDefault.vaultCaptureMode = true; // for capture + userSettingsDefault.devMode = true; // for capture hiddenSettingsDefault.consoleLogLevel = 'info'; hiddenSettingsDefault.cacheStorageAPI = 'unset'; adnlogSet(true); diff --git a/src/vault.html b/src/vault.html index 36f2a6096a336..f0f48ce5a48ee 100644 --- a/src/vault.html +++ b/src/vault.html @@ -2,150 +2,158 @@ - - - - - - - - + + + + + + + + -
- -
+
+ +
-
+
-
- -
- + - -
-
100%
- - - - -
-
-
- - -
- -
- -
-

-
    -
-
-
-

-
    -
-
-
-

-
    -
-
-
- -
-
-  ,   -   / -   - (0 ),   -     ? -
-
- - - - - - -
-
+
+ + + +
+
100%
-
- alert -

Alert goes here

-
+ -
-
+ +
+
+
+ +
-
+
+ +
+

+
    +
+
+
+

+
    +
+
+
+

+
    +
+
+
+
+
+  ,   +   / +   + (0 ),   +     ? +
+
+ + + + + + +
+
+ alert +

Alert goes here

+
-