Skip to content

Commit 0eed05a

Browse files
committed
feat: Add user settings for NCBI API lookups with opt-out option
1 parent 07cab7b commit 0eed05a

File tree

8 files changed

+87
-20
lines changed

8 files changed

+87
-20
lines changed

content/content_script.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,19 @@
371371
window._mdpiFilterRefFootnoteObserver = observer;
372372
}
373373

374+
// --- User Settings Container ---
375+
if (!window.MDPIFilterSettings) window.MDPIFilterSettings = {};
376+
// Load NCBI API enabled flag (default true)
377+
chrome.storage.sync.get('ncbiApiEnabled', res => {
378+
window.MDPIFilterSettings.ncbiApiEnabled = (res.ncbiApiEnabled !== false);
379+
});
380+
chrome.storage.onChanged.addListener(changes => {
381+
if (changes.ncbiApiEnabled) {
382+
window.MDPIFilterSettings.ncbiApiEnabled = changes.ncbiApiEnabled.newValue;
383+
console.log("[MDPI Filter CS] NCBI API Enabled set to", changes.ncbiApiEnabled.newValue);
384+
}
385+
});
386+
374387
if (chrome.runtime && chrome.runtime.id) {
375388
chrome.storage.sync.get({
376389
mode: 'highlight',
@@ -662,8 +675,8 @@
662675
}
663676
}
664677

665-
// 2. NCBI API Check (if useNcbiApi is true and not already identified as MDPI)
666-
if (!isMdpiResult && config.useNcbiApi) {
678+
// 2. NCBI API Check (respect user setting for NCBI API lookups)
679+
if (!isMdpiResult && window.MDPIFilterSettings?.ncbiApiEnabled !== false) {
667680
// Try to find the primary link of the search result item.
668681
// Common Google search result link structure:
669682
let mainLinkElement = item.querySelector('div.yuRUbf > a[href]');
@@ -941,7 +954,7 @@
941954
isMdpi = itemIsMdpiByDirectIdentification;
942955
let itemIsMdpiByApi = false;
943956

944-
if (!isMdpi && activeConfig.useNcbiApi) {
957+
if (!isMdpi && window.MDPIFilterSettings?.ncbiApiEnabled !== false) {
945958
// console.log(`${logPrefix} Not MDPI by direct ID. Using NCBI API.`);
946959
const pmidsToQuery = new Set();
947960
const pmcidsToQuery = new Set();
@@ -1368,7 +1381,7 @@
13681381
}
13691382

13701383
// Log all current data-mdpi-filter-ref-id values for debugging
1371-
const allRefIds = Array.from(document.querySelectorAll('[data-mdpi-filter-ref-id]')).map(el => el.getAttribute('data-mdpi-filter-ref-id'));
1384+
const allRefIds = Array.from(document.querySelectorAll('[data-mdpi-filter-ref-id]')). map(el => el.getAttribute('data-mdpi-filter-ref-id'));
13721385
console.log('[MDPI Filter CS] All current data-mdpi-filter-ref-id values in DOM:', allRefIds);
13731386

13741387
if (target) {

content/google_content_checker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ class GoogleContentChecker {
134134
console.log(`[MDPI Filter GoogleChecker DEBUG ${itemIdentifier}] No direct MDPI links found. Checking for potential indicators...`);
135135

136136
// --- POTENTIAL MDPI CHECKS (Text or NCBI-confirmed IDs in links/text) ---
137-
if (currentSettings.highlightPotentialMdpiSites) {
137+
const ncbiEnabled = window.MDPIFilterSettings?.ncbiApiEnabled !== false;
138+
if (ncbiEnabled && window.MDPIFilterNcbiApiHandler) {
139+
console.log(`[MDPI Filter GoogleChecker DEBUG ${itemIdentifier}] NCBI API enabled by user, checking links and text...`);
140+
138141
const itemTextContent = item.textContent || '';
139142
let isPotential = false;
140143
let potentialDetailsArray = [];
@@ -153,7 +156,7 @@ class GoogleContentChecker {
153156
}
154157

155158
// Check for NCBI-confirmed PMIDs/PMCIDs in links or text content
156-
if (activeConfig.useNcbiApi && window.MDPIFilterNcbiApiHandler) {
159+
if (ncbiEnabled && window.MDPIFilterNcbiApiHandler) {
157160
console.log(`[MDPI Filter GoogleChecker DEBUG ${itemIdentifier}] NCBI API enabled, checking links and text...`);
158161

159162
// From links

content/ncbi_api_handler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ if (typeof window.MDPIFilterNcbiApiHandler === 'undefined') {
77
const MDPI_DOI_PREFIX = '10.3390'; // For identifying MDPI DOIs
88

99
async function checkNcbiIdsForMdpi(ids, idType, runCache, ncbiApiCache) {
10+
// Respect user opt-out for NCBI API
11+
if (window.MDPIFilterSettings && window.MDPIFilterSettings.ncbiApiEnabled === false) {
12+
console.log("[MDPI Filter NCBI API] Skipping lookup: user opt-out");
13+
return false;
14+
}
1015
// Filter out DOIs with fragments or invalid chars
1116
if (idType === 'doi') {
1217
ids = ids.map(id => id.split('#')[0].split('?')[0].trim())

options.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ <h2>Potential MDPI Site Highlighting (Google Search Only)</h2>
3636
<span>Enable Extension Logging</span>
3737
</label>
3838
</div>
39+
<!-- Advanced Settings -->
40+
<hr class="separator">
41+
<p class="settings-title">Advanced Settings</p>
42+
<div class="setting-item">
43+
<label class="checkbox-label" for="ncbiApiEnabledOptions">
44+
<input type="checkbox" id="ncbiApiEnabledOptions" name="ncbiApiEnabledOptions">
45+
<span>Enable NCBI API lookups</span>
46+
<span class="setting-warning">Disabling reduces accuracy, leading to missed or incorrect highlights.</span>
47+
</label>
48+
</div>
3949
<button id="save">Save</button>
4050
<div id="status"></div>
4151
</div>

options.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ function loadOptions() {
1212
mode: 'highlight',
1313
highlightPotentialMdpiSites: false,
1414
potentialMdpiHighlightColor: '#FFFF99',
15-
loggingEnabled: false
15+
loggingEnabled: false,
16+
ncbiApiEnabled: true
1617
}, (settings) => {
1718
if (chrome.runtime.lastError) {
1819
console.error("Error loading options:", chrome.runtime.lastError);
1920
return;
2021
}
21-
radios.forEach(r => r.checked = (r.value === settings.mode));
22-
if (highlightPotentialMdpiCheckboxOptions) {
23-
highlightPotentialMdpiCheckboxOptions.checked = settings.highlightPotentialMdpiSites;
24-
}
25-
if (potentialMdpiColorInputOptions) {
26-
potentialMdpiColorInputOptions.value = settings.potentialMdpiHighlightColor;
27-
}
28-
if (loggingCheckboxOptions) {
29-
loggingCheckboxOptions.checked = settings.loggingEnabled;
30-
}
22+
// populate UI
23+
Array.from(radios).find(r => r.value === settings.mode).checked = true;
24+
if (highlightPotentialMdpiCheckboxOptions) highlightPotentialMdpiCheckboxOptions.checked = settings.highlightPotentialMdpiSites;
25+
if (potentialMdpiColorInputOptions) potentialMdpiColorInputOptions.value = settings.potentialMdpiHighlightColor;
26+
if (loggingCheckboxOptions) loggingCheckboxOptions.checked = settings.loggingEnabled;
27+
const ncbiCheckbox = document.getElementById('ncbiApiEnabledOptions');
28+
if (ncbiCheckbox) ncbiCheckbox.checked = settings.ncbiApiEnabled;
3129
});
3230
}
3331

@@ -36,12 +34,21 @@ function saveOptions() {
3634
const highlightPotential = highlightPotentialMdpiCheckboxOptions ? highlightPotentialMdpiCheckboxOptions.checked : false;
3735
const potentialColor = potentialMdpiColorInputOptions ? potentialMdpiColorInputOptions.value : '#FFFF99';
3836
const loggingEnabled = loggingCheckboxOptions ? loggingCheckboxOptions.checked : false;
37+
const ncbiApiEnabled = document.getElementById('ncbiApiEnabledOptions')?.checked ?? true;
38+
// Confirm if user is disabling NCBI API lookups
39+
if (!ncbiApiEnabled) {
40+
const proceed = confirm('Disabling NCBI API lookups will reduce detection accuracy and may miss or mislabel MDPI citations. Continue?');
41+
if (!proceed) {
42+
return; // Abort save
43+
}
44+
}
3945

4046
chrome.storage.sync.set({
4147
mode: selectedMode,
4248
highlightPotentialMdpiSites: highlightPotential,
4349
potentialMdpiHighlightColor: potentialColor,
44-
loggingEnabled
50+
loggingEnabled,
51+
ncbiApiEnabled
4552
}, () => {
4653
if (chrome.runtime.lastError) {
4754
status.textContent = 'Error saving options.';

popup.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,11 @@ h2 {
240240
background-color: #fff; /* Ensure background for color swatch */
241241
margin-left: auto; /* Push color picker to the right if in flex container */
242242
}
243+
244+
/* Warning text style */
245+
.setting-warning {
246+
color: red;
247+
font-size: 0.85em;
248+
margin-left: 8px;
249+
}
243250
/* End Styles for new settings */

popup.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ <h1>MDPI Filter</h1>
6969
<input type="checkbox" id="loggingEnabled" name="loggingEnabled">
7070
<span>Enable Extension Logging</span>
7171
</label>
72+
</div>
73+
<div class="setting-item">
74+
<label class="checkbox-label" for="ncbiApiEnabledPopup">
75+
<input type="checkbox" id="ncbiApiEnabledPopup">
76+
<span>Enable NCBI API lookups</span>
77+
<span class="setting-warning">Disabling reduces accuracy, leading to missed or incorrect highlights.</span>
78+
</label>
7279
</div>
7380
<!-- End New Settings -->
7481
<!-- Save button and status moved here -->

popup.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,33 @@ document.addEventListener('DOMContentLoaded', () => {
5656
}
5757
});
5858

59-
// --- Save Mode Setting ---
59+
// --- Load NCBI API setting ---
60+
const ncbiPopupCheckbox = document.getElementById('ncbiApiEnabledPopup');
61+
chrome.storage.sync.get({ ncbiApiEnabled: true }, settings => {
62+
if (ncbiPopupCheckbox) ncbiPopupCheckbox.checked = settings.ncbiApiEnabled;
63+
});
64+
65+
// --- Save all settings including NCBI API ---
6066
saveBtn.addEventListener('click', () => {
6167
const selectedMode = Array.from(radios).find(r => r.checked).value;
6268
const highlightPotential = highlightPotentialMdpiCheckbox ? highlightPotentialMdpiCheckbox.checked : false;
6369
const potentialColor = potentialMdpiColorInput ? potentialMdpiColorInput.value : '#FFFF99';
6470
const loggingEnabled = loggingEnabledCheckbox ? loggingEnabledCheckbox.checked : false;
71+
const ncbiEnabled = ncbiPopupCheckbox?.checked ?? true;
72+
// Confirm if user is disabling NCBI API lookups
73+
if (!ncbiEnabled) {
74+
const proceed = confirm('Disabling NCBI API lookups will reduce detection accuracy and may miss or mislabel MDPI citations. Continue?');
75+
if (!proceed) {
76+
return; // Abort save
77+
}
78+
}
6579

6680
chrome.storage.sync.set({
6781
mode: selectedMode,
6882
highlightPotentialMdpiSites: highlightPotential,
6983
potentialMdpiHighlightColor: potentialColor,
70-
loggingEnabled
84+
loggingEnabled,
85+
ncbiApiEnabled: ncbiEnabled
7186
}, () => {
7287
if (chrome.runtime.lastError) {
7388
status.textContent = 'Error saving settings.';

0 commit comments

Comments
 (0)