@pilio/gemini-watermark-remover 1.0.30 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/video-app.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pilio/gemini-watermark-remover",
|
|
3
3
|
"description": "Automatically removes watermarks from Gemini AI generated images",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.31",
|
|
5
5
|
"author": "GargantuaX",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"files": [
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"probe:tm:profile": "node scripts/open-tampermonkey-profile.js",
|
|
103
103
|
"probe:tm:setup": "node scripts/tampermonkey-smoke.js setup",
|
|
104
104
|
"probe:real-page:compare": "node scripts/real-page-pixel-compare.js",
|
|
105
|
+
"probe:real-page:copy-download": "node scripts/real-page-copy-download-probe.js",
|
|
105
106
|
"benchmark:samples": "node scripts/sample-benchmark.js",
|
|
106
107
|
"benchmark:userscript": "node scripts/userscript-benchmark.js",
|
|
107
108
|
"benchmark:online-sample:gate": "node scripts/gate-online-gemini-watermark-sample-benchmark.js",
|
|
@@ -5,8 +5,13 @@ import { createRepairTrialFromStages } from './pipelineRepairTrial.js';
|
|
|
5
5
|
|
|
6
6
|
const NEW_MARGIN_96_SIZE = 96;
|
|
7
7
|
const NEW_MARGIN_96_MARGIN = 192;
|
|
8
|
-
const HIGH_RISK_NEW_MARGIN_MIN_SPATIAL = 0.4;
|
|
9
|
-
const HIGH_RISK_NEW_MARGIN_MIN_GRADIENT = 0.08;
|
|
8
|
+
const HIGH_RISK_NEW_MARGIN_MIN_SPATIAL = 0.4;
|
|
9
|
+
const HIGH_RISK_NEW_MARGIN_MIN_GRADIENT = 0.08;
|
|
10
|
+
const SAFE_EXACT_NEW_MARGIN_MIN_SPATIAL = 0.18;
|
|
11
|
+
const SAFE_EXACT_NEW_MARGIN_MIN_GRADIENT = 0.05;
|
|
12
|
+
const SAFE_EXACT_NEW_MARGIN_MIN_IMPROVEMENT = 0.1;
|
|
13
|
+
const SAFE_EXACT_NEW_MARGIN_MAX_PROCESSED_SPATIAL = 0.32;
|
|
14
|
+
const SAFE_EXACT_NEW_MARGIN_MAX_PROCESSED_GRADIENT = 0.05;
|
|
10
15
|
const DEFAULT_ALPHA_NEW_MARGIN_MAX_SPATIAL_RESIDUAL = 0.18;
|
|
11
16
|
const DEFAULT_ALPHA_NEW_MARGIN_MAX_GRADIENT_RESIDUAL = 0.08;
|
|
12
17
|
const DEFAULT_ALPHA_NEW_MARGIN_MIN_IMPROVEMENT = 0.12;
|
|
@@ -40,11 +45,30 @@ export function isNewMarginAlphaVariantTrial(candidate) {
|
|
|
40
45
|
config.alphaVariant === '20260520';
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
export function isDefaultAlphaNewMarginTrial(candidate) {
|
|
44
|
-
const config = getConfig(candidate);
|
|
45
|
-
return isNewMargin96Candidate(candidate) &&
|
|
46
|
-
!config.alphaVariant;
|
|
47
|
-
}
|
|
48
|
+
export function isDefaultAlphaNewMarginTrial(candidate) {
|
|
49
|
+
const config = getConfig(candidate);
|
|
50
|
+
return isNewMargin96Candidate(candidate) &&
|
|
51
|
+
!config.alphaVariant;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isNewMarginVariantFamilyCandidate(candidate) {
|
|
55
|
+
const config = getConfig(candidate);
|
|
56
|
+
const provenance = getProvenance(candidate);
|
|
57
|
+
return config.marginRight === NEW_MARGIN_96_MARGIN &&
|
|
58
|
+
config.marginBottom === NEW_MARGIN_96_MARGIN &&
|
|
59
|
+
(config.alphaVariant === '20260520' || provenance.alphaVariant === '20260520');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function hasSafeExactNewMarginVariantRecovery(candidate) {
|
|
63
|
+
if (!isNewMarginAlphaVariantTrial(candidate)) return false;
|
|
64
|
+
if (candidate?.damage?.safe !== true) return false;
|
|
65
|
+
|
|
66
|
+
return numberOr(candidate?.originalSpatialScore) >= SAFE_EXACT_NEW_MARGIN_MIN_SPATIAL &&
|
|
67
|
+
numberOr(candidate?.originalGradientScore) >= SAFE_EXACT_NEW_MARGIN_MIN_GRADIENT &&
|
|
68
|
+
numberOr(candidate?.improvement, -Infinity) >= SAFE_EXACT_NEW_MARGIN_MIN_IMPROVEMENT &&
|
|
69
|
+
Math.abs(numberOr(candidate?.processedSpatialScore, Infinity)) <= SAFE_EXACT_NEW_MARGIN_MAX_PROCESSED_SPATIAL &&
|
|
70
|
+
Math.max(0, numberOr(candidate?.processedGradientScore, Infinity)) <= SAFE_EXACT_NEW_MARGIN_MAX_PROCESSED_GRADIENT;
|
|
71
|
+
}
|
|
48
72
|
|
|
49
73
|
export function hasClearedResidual(candidate) {
|
|
50
74
|
return candidate?.residual?.cleared === true ||
|
|
@@ -61,13 +85,14 @@ export function hasSafeDefaultAlphaNewMarginResidual(candidate) {
|
|
|
61
85
|
numberOr(candidate?.improvement, -Infinity) >= DEFAULT_ALPHA_NEW_MARGIN_MIN_IMPROVEMENT;
|
|
62
86
|
}
|
|
63
87
|
|
|
64
|
-
export function hasHighRiskNewMarginPositiveEvidence(candidate) {
|
|
65
|
-
if (getProvenance(candidate).darkPolarity === true) return true;
|
|
66
|
-
if (!
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
numberOr(candidate?.originalSpatialScore) >= HIGH_RISK_NEW_MARGIN_MIN_SPATIAL;
|
|
70
|
-
|
|
88
|
+
export function hasHighRiskNewMarginPositiveEvidence(candidate) {
|
|
89
|
+
if (getProvenance(candidate).darkPolarity === true) return true;
|
|
90
|
+
if (!isNewMarginVariantFamilyCandidate(candidate) && !isDefaultAlphaNewMarginTrial(candidate)) return true;
|
|
91
|
+
|
|
92
|
+
const hasStrongEvidence = numberOr(candidate?.originalGradientScore) >= HIGH_RISK_NEW_MARGIN_MIN_GRADIENT ||
|
|
93
|
+
numberOr(candidate?.originalSpatialScore) >= HIGH_RISK_NEW_MARGIN_MIN_SPATIAL;
|
|
94
|
+
return hasStrongEvidence || hasSafeExactNewMarginVariantRecovery(candidate);
|
|
95
|
+
}
|
|
71
96
|
|
|
72
97
|
export function shouldFailClosedForVisibleResidualUnsafeDamage({
|
|
73
98
|
selectedTrial = null,
|
|
@@ -124,10 +149,11 @@ export function createCandidateEvaluation({
|
|
|
124
149
|
provenance,
|
|
125
150
|
originalSpatialScore: originalScores?.spatialScore,
|
|
126
151
|
originalGradientScore: originalScores?.gradientScore,
|
|
127
|
-
processedSpatialScore: processedScores?.spatialScore,
|
|
128
|
-
processedGradientScore: processedScores?.gradientScore,
|
|
129
|
-
improvement
|
|
130
|
-
|
|
152
|
+
processedSpatialScore: processedScores?.spatialScore,
|
|
153
|
+
processedGradientScore: processedScores?.gradientScore,
|
|
154
|
+
improvement,
|
|
155
|
+
damage
|
|
156
|
+
};
|
|
131
157
|
const originalSpatial = numberOr(originalScores?.spatialScore);
|
|
132
158
|
const originalGradient = numberOr(originalScores?.gradientScore);
|
|
133
159
|
const processedSpatial = numberOr(processedScores?.spatialScore);
|
|
@@ -496,6 +496,23 @@ function resolveAlphaMapForSize(size, { alpha48, alpha96, getAlphaMap } = {}) {
|
|
|
496
496
|
return alpha96 ? interpolateAlphaMap(alpha96, 96, size) : null;
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
export function resolveSizeJitterAlphaMap(seed, size, {
|
|
500
|
+
alpha48,
|
|
501
|
+
alpha96,
|
|
502
|
+
getAlphaMap,
|
|
503
|
+
resolveAlphaMap = null
|
|
504
|
+
} = {}) {
|
|
505
|
+
const seedSize = Number(seed?.position?.width);
|
|
506
|
+
if (seed?.alphaMap && Number.isFinite(seedSize) && seedSize > 0) {
|
|
507
|
+
if (size === seedSize) return seed.alphaMap;
|
|
508
|
+
return interpolateAlphaMap(seed.alphaMap, seedSize, size);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return typeof resolveAlphaMap === 'function'
|
|
512
|
+
? resolveAlphaMap(size)
|
|
513
|
+
: resolveAlphaMapForSize(size, { alpha48, alpha96, getAlphaMap });
|
|
514
|
+
}
|
|
515
|
+
|
|
499
516
|
function resolveAlphaMapForConfig(config, {
|
|
500
517
|
alpha48,
|
|
501
518
|
alpha96,
|
|
@@ -1320,11 +1337,35 @@ function compareSameAnchorCandidateRanking(currentBest, candidate) {
|
|
|
1320
1337
|
return compareRankingKey(candidate.rankingKey, currentBest.rankingKey);
|
|
1321
1338
|
}
|
|
1322
1339
|
|
|
1340
|
+
function shouldPreserveExactNewMarginVariant(exactCandidate, competingCandidate) {
|
|
1341
|
+
const exactConfig = exactCandidate?.config ?? {};
|
|
1342
|
+
const competingConfig = competingCandidate?.config ?? {};
|
|
1343
|
+
const exactVariant = exactConfig.alphaVariant ?? exactCandidate?.provenance?.alphaVariant;
|
|
1344
|
+
const competingVariant = competingConfig.alphaVariant ?? competingCandidate?.provenance?.alphaVariant;
|
|
1345
|
+
|
|
1346
|
+
if (exactCandidate?.accepted !== true || exactCandidate?.damage?.safe !== true) return false;
|
|
1347
|
+
if (exactConfig.logoSize !== 96 || exactConfig.marginRight !== 192 || exactConfig.marginBottom !== 192) {
|
|
1348
|
+
return false;
|
|
1349
|
+
}
|
|
1350
|
+
if (exactVariant !== '20260520') return false;
|
|
1351
|
+
if (competingCandidate?.provenance?.sizeJitter !== true) return false;
|
|
1352
|
+
if (competingConfig.marginRight !== 192 || competingConfig.marginBottom !== 192) return false;
|
|
1353
|
+
if (competingVariant !== exactVariant) return false;
|
|
1354
|
+
|
|
1355
|
+
return !hasMuchStrongerOriginalSignal(competingCandidate, exactCandidate);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1323
1358
|
export function pickBetterCandidate(currentBest, candidate, minCostDelta = 0.005) {
|
|
1324
1359
|
if (!candidate?.accepted) return currentBest;
|
|
1325
1360
|
if (!currentBest) return candidate;
|
|
1326
1361
|
const evaluationDecision = arbitrateCandidateByEvaluation(currentBest, candidate);
|
|
1327
1362
|
if (evaluationDecision) return evaluationDecision;
|
|
1363
|
+
if (shouldPreserveExactNewMarginVariant(currentBest, candidate)) {
|
|
1364
|
+
return currentBest;
|
|
1365
|
+
}
|
|
1366
|
+
if (shouldPreserveExactNewMarginVariant(candidate, currentBest)) {
|
|
1367
|
+
return candidate;
|
|
1368
|
+
}
|
|
1328
1369
|
if (shouldPreserveCatalogOriginalSignal(currentBest, candidate)) {
|
|
1329
1370
|
return currentBest;
|
|
1330
1371
|
}
|
|
@@ -1975,13 +2016,12 @@ function searchStandardSizeJitterCandidate({
|
|
|
1975
2016
|
if (candidatePosition.x + candidatePosition.width > originalImageData.width) continue;
|
|
1976
2017
|
if (candidatePosition.y + candidatePosition.height > originalImageData.height) continue;
|
|
1977
2018
|
|
|
1978
|
-
const candidateAlphaMap =
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
});
|
|
2019
|
+
const candidateAlphaMap = resolveSizeJitterAlphaMap(seed, size, {
|
|
2020
|
+
alpha48,
|
|
2021
|
+
alpha96,
|
|
2022
|
+
getAlphaMap,
|
|
2023
|
+
resolveAlphaMap
|
|
2024
|
+
});
|
|
1985
2025
|
if (!candidateAlphaMap) continue;
|
|
1986
2026
|
|
|
1987
2027
|
const candidate = evaluateRestorationCandidate({
|
|
@@ -1989,11 +2029,10 @@ function searchStandardSizeJitterCandidate({
|
|
|
1989
2029
|
alphaMap: candidateAlphaMap,
|
|
1990
2030
|
position: candidatePosition,
|
|
1991
2031
|
source: `${seed.source}+size`,
|
|
1992
|
-
config: {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
},
|
|
2032
|
+
config: {
|
|
2033
|
+
...seed.config,
|
|
2034
|
+
logoSize: size
|
|
2035
|
+
},
|
|
1997
2036
|
baselineNearBlackRatio: calculateNearBlackRatio(originalImageData, candidatePosition),
|
|
1998
2037
|
adaptiveConfidence,
|
|
1999
2038
|
provenance: mergeCandidateProvenance(seed.provenance, { sizeJitter: true }),
|
|
@@ -2644,38 +2644,50 @@ function refineLocatedAggressiveRemoval({
|
|
|
2644
2644
|
return best;
|
|
2645
2645
|
}
|
|
2646
2646
|
|
|
2647
|
-
function shouldSkipLocatedAggressiveForCleanCanonical96({
|
|
2647
|
+
function shouldSkipLocatedAggressiveForCleanCanonical96({
|
|
2648
2648
|
config,
|
|
2649
2649
|
alphaGain,
|
|
2650
2650
|
originalSpatialScore,
|
|
2651
2651
|
originalGradientScore,
|
|
2652
|
-
currentSpatialScore,
|
|
2653
|
-
currentGradientScore
|
|
2654
|
-
}) {
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
)
|
|
2660
|
-
return false;
|
|
2661
|
-
}
|
|
2662
|
-
|
|
2663
|
-
const resolvedAlphaGain = Number(alphaGain);
|
|
2664
|
-
const originalSpatial = Number(originalSpatialScore);
|
|
2665
|
-
const originalGradient = Number(originalGradientScore);
|
|
2666
|
-
const currentSpatial = Number(currentSpatialScore);
|
|
2667
|
-
const currentGradient = Number(currentGradientScore);
|
|
2652
|
+
currentSpatialScore,
|
|
2653
|
+
currentGradientScore
|
|
2654
|
+
}) {
|
|
2655
|
+
const resolvedAlphaGain = Number(alphaGain);
|
|
2656
|
+
const originalSpatial = Number(originalSpatialScore);
|
|
2657
|
+
const originalGradient = Number(originalGradientScore);
|
|
2658
|
+
const currentSpatial = Number(currentSpatialScore);
|
|
2659
|
+
const currentGradient = Number(currentGradientScore);
|
|
2668
2660
|
if (
|
|
2669
2661
|
!Number.isFinite(resolvedAlphaGain) ||
|
|
2670
2662
|
!Number.isFinite(originalSpatial) ||
|
|
2671
2663
|
!Number.isFinite(originalGradient) ||
|
|
2672
2664
|
!Number.isFinite(currentSpatial) ||
|
|
2673
2665
|
!Number.isFinite(currentGradient)
|
|
2674
|
-
) {
|
|
2675
|
-
return false;
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
const
|
|
2666
|
+
) {
|
|
2667
|
+
return false;
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
const cleanExactNewMarginVariant =
|
|
2671
|
+
config?.logoSize === 96 &&
|
|
2672
|
+
config.marginRight === 192 &&
|
|
2673
|
+
config.marginBottom === 192 &&
|
|
2674
|
+
config.alphaVariant === '20260520' &&
|
|
2675
|
+
resolvedAlphaGain <= 1.3 &&
|
|
2676
|
+
originalSpatial >= 0.18 &&
|
|
2677
|
+
originalSpatial < 0.4 &&
|
|
2678
|
+
originalGradient >= 0.05 &&
|
|
2679
|
+
originalGradient < 0.08;
|
|
2680
|
+
if (cleanExactNewMarginVariant) return true;
|
|
2681
|
+
|
|
2682
|
+
if (
|
|
2683
|
+
config?.logoSize !== 96 ||
|
|
2684
|
+
config.marginRight !== 64 ||
|
|
2685
|
+
config.marginBottom !== 64
|
|
2686
|
+
) {
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
const cleanStandardAlpha =
|
|
2679
2691
|
resolvedAlphaGain <= 1 &&
|
|
2680
2692
|
currentSpatial >= 0 &&
|
|
2681
2693
|
currentSpatial <= 0.35 &&
|
|
@@ -1089,8 +1089,10 @@ export async function processPageImageSource({
|
|
|
1089
1089
|
fetchBlobFromBackgroundImpl = fetchBlobFromBackground
|
|
1090
1090
|
}) {
|
|
1091
1091
|
const treatAsPreviewSource = shouldTreatPageImageSourceAsPreview(imageElement, sourceUrl);
|
|
1092
|
-
|
|
1093
|
-
|
|
1092
|
+
const canFallBackToPreviewProcessing = !isBlobPageImageSource(sourceUrl)
|
|
1093
|
+
&& isGeminiDisplayPreviewAssetUrl(sourceUrl);
|
|
1094
|
+
if (treatAsPreviewSource || canFallBackToPreviewProcessing) {
|
|
1095
|
+
if (canFallBackToPreviewProcessing) {
|
|
1094
1096
|
try {
|
|
1095
1097
|
return await processOriginalPageImageSource({
|
|
1096
1098
|
sourceUrl,
|
|
@@ -1105,8 +1107,8 @@ export async function processPageImageSource({
|
|
|
1105
1107
|
rejectPreviewAspectMismatch: true
|
|
1106
1108
|
});
|
|
1107
1109
|
} catch {
|
|
1108
|
-
// Fall back to the preview-specific path when
|
|
1109
|
-
// is unavailable, invalid, or blocked
|
|
1110
|
+
// Fall back to the preview-specific path when original-quality
|
|
1111
|
+
// acquisition is unavailable, invalid, or blocked.
|
|
1110
1112
|
}
|
|
1111
1113
|
}
|
|
1112
1114
|
|
package/src/userscript/index.js
CHANGED
|
@@ -207,11 +207,16 @@ export async function initGeminiWatermarkRemoverUserscript() {
|
|
|
207
207
|
};
|
|
208
208
|
const handleProcessedBlobResolved = (payload = {}) => {
|
|
209
209
|
const resolvedActionContext = resolveCompatibleActionContextFromPayload(payload);
|
|
210
|
+
const isClipboardResult = resolvedActionContext?.action === 'clipboard';
|
|
210
211
|
storeProcessedBlobResolved(payload, {
|
|
211
|
-
slot: 'full',
|
|
212
|
-
processedFrom:
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
slot: isClipboardResult ? 'preview' : 'full',
|
|
213
|
+
processedFrom: isClipboardResult ? 'original-clipboard' : 'original-download'
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const handleClipboardFallbackBlobResolved = (payload = {}) => {
|
|
217
|
+
storeProcessedBlobResolved(payload, {
|
|
218
|
+
slot: 'preview',
|
|
219
|
+
processedFrom: 'clipboard-fallback'
|
|
215
220
|
});
|
|
216
221
|
};
|
|
217
222
|
const downloadIntentGate = createGeminiDownloadIntentGate({
|
|
@@ -270,7 +275,7 @@ export async function initGeminiWatermarkRemoverUserscript() {
|
|
|
270
275
|
const disposeClipboardHook = installGeminiClipboardImageHook(targetWindow, {
|
|
271
276
|
getActionContext: () => downloadIntentGate.getRecentActionContext(),
|
|
272
277
|
imageSessionStore: imageSessionStore,
|
|
273
|
-
onProcessedBlobResolved:
|
|
278
|
+
onProcessedBlobResolved: handleClipboardFallbackBlobResolved,
|
|
274
279
|
onActionCriticalFailure: handleActionCriticalFailure,
|
|
275
280
|
processClipboardImageBlob: (blob, { actionContext } = {}) => (
|
|
276
281
|
processClipboardImageBlobAtBestPath(blob, { actionContext })
|