Skip invalid and protected candidates
This commit is contained in:
parent
bd0c1a26c2
commit
93f49c5554
3 changed files with 223 additions and 17 deletions
|
|
@ -85,6 +85,12 @@
|
|||
const redirectTo = {{ redirect_to | tojson }};
|
||||
const apiUrl = {{ url_for('api_valid_hit') | tojson }};
|
||||
const pageUrl = new URL(window.location.href);
|
||||
const cleanPageUrl = new URL(pageUrl);
|
||||
cleanPageUrl.searchParams.delete('title');
|
||||
cleanPageUrl.searchParams.delete('after');
|
||||
cleanPageUrl.searchParams.delete('skip');
|
||||
const storageKey = 'missinglink.skipped.' + linkTo;
|
||||
const skippedTitles = [];
|
||||
|
||||
const elProgress = document.getElementById('search-progress');
|
||||
const elStatus = document.getElementById('search-status');
|
||||
|
|
@ -101,8 +107,39 @@
|
|||
if (elCount) elCount.textContent = elList.children.length;
|
||||
}
|
||||
|
||||
function loadSkippedTitles() {
|
||||
try {
|
||||
const stored = JSON.parse(localStorage.getItem(storageKey) || '[]');
|
||||
if (Array.isArray(stored)) {
|
||||
for (const title of stored) rememberSkipped(title, false);
|
||||
}
|
||||
} catch (e) {
|
||||
try { localStorage.removeItem(storageKey); } catch (e) {}
|
||||
}
|
||||
|
||||
for (const title of {{ skipped_titles | tojson }}) rememberSkipped(title, false);
|
||||
saveSkippedTitles();
|
||||
}
|
||||
|
||||
function saveSkippedTitles() {
|
||||
try {
|
||||
localStorage.setItem(storageKey, JSON.stringify(skippedTitles));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function rememberSkipped(title, save = true) {
|
||||
if (!title || skippedTitles.includes(title)) return;
|
||||
skippedTitles.push(title);
|
||||
if (save) saveSkippedTitles();
|
||||
}
|
||||
|
||||
async function search() {
|
||||
loadSkippedTitles();
|
||||
for (const hitTitle of skippedTitles) removeCandidate(hitTitle);
|
||||
|
||||
for (const hitTitle of hits) {
|
||||
if (skippedTitles.includes(hitTitle)) continue;
|
||||
|
||||
elStatus.textContent = `Checking "${hitTitle}"…`;
|
||||
|
||||
let data;
|
||||
|
|
@ -116,7 +153,11 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!data.valid) { removeCandidate(hitTitle); continue; }
|
||||
if (!data.valid) {
|
||||
rememberSkipped(hitTitle);
|
||||
removeCandidate(hitTitle);
|
||||
continue;
|
||||
}
|
||||
|
||||
elProgress.hidden = true;
|
||||
|
||||
|
|
@ -126,13 +167,15 @@
|
|||
document.getElementById('diff-table').innerHTML = data.diff;
|
||||
document.getElementById('hit-input').value = hitTitle;
|
||||
|
||||
const skipUrl = new URL(pageUrl);
|
||||
skipUrl.searchParams.delete('title');
|
||||
skipUrl.searchParams.set('after', hitTitle);
|
||||
document.getElementById('skip-link').href = skipUrl.toString();
|
||||
const elSkipLink = document.getElementById('skip-link');
|
||||
elSkipLink.href = cleanPageUrl.toString();
|
||||
elSkipLink.onclick = function () {
|
||||
rememberSkipped(hitTitle);
|
||||
};
|
||||
|
||||
const currentUrl = new URL(pageUrl);
|
||||
currentUrl.searchParams.delete('after');
|
||||
currentUrl.searchParams.delete('skip');
|
||||
currentUrl.searchParams.set('title', hitTitle);
|
||||
history.replaceState(null, '', currentUrl.toString());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue