// ==UserScript==
// @name AD57 STACK
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Modifies the page layout
// @author A2
// @match https://num.archives57.com/visualiseur/index.php/rechercheTheme/requeteConstructor/1/*
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.min.js
// ==/UserScript==
(function() {
'use strict';
// Enhanced localStorage logging function
function logLocalStorageEntries(prefix = 'AD57-') {
console.log('--- LocalStorage Entries ---');
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i);
if (key.startsWith(prefix)) {
try {
const value = localStorage.getItem(key);
console.log(`Key: ${key}`);
console.log('Value:', JSON.parse(value));
} catch (error) {
console.error(`Error parsing localStorage item for key ${key}:`, error);
}
}
}
console.log('--- End of LocalStorage Entries ---');
}
function clearLocalStorageWithPrefix(prefix) {
console.log(`Clearing localStorage with prefix: ${prefix}`);
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i);
if (key.startsWith(prefix)) {
console.log(`Removing key: ${key}`);
localStorage.removeItem(key);
}
}
console.log('LocalStorage clearing complete');
}
//console.log('All localStorage cleared');
clearLocalStorageWithPrefix('AD57-');
if (window.location.href.includes('/1/1/A/')) {
window.location.href = 'https://num.archives57.com/visualiseur/index.php/rechercheTheme/requeteConstructor/1/2/A/0/0';
return;
}
if (window.location.href.includes('/1/1/R/')) {
$('#menu').remove();
$('#content').remove();
}
$('html').css({'border': 'none'});
$('ul.dvpt-liste_items li a[onclick^="winopen"]').each(function() {
$(this).removeAttr('onclick').removeAttr('href').html('•');
});
$('body').css({ 'font-family': 'Noto Sans', 'font-size': 'x-large', 'line-height': '1.5'
});
// Remove "Choix de la commune" useless text
$('ul.dvpt-liste_resultat li:contains("Choix de la commune")').each(function() {
const html = $(this).html();
const newHtml = html.replace(/Choix de la commune\s*
/, '');
$(this).html(newHtml);
});
let totalResults = null;
function getTotalResults() {
const match = $('.t.bt td:last-child').text().match(/(\d+)/);
return match ? parseInt(match[1]) : 0;
}
// Function to apply all cleanup and formatting
function applyCleanupAndFormatting() {
// Remove the original #resultat div
document.getElementById('resultat').style.display = 'none';
$('.bouton_84px_type1, .bouton_176px_type1, .bouton_298px_type1').css({
'width': 'auto',
'height': 'auto',
'padding': 'revert'
});
$('#content').removeClass('main_contener');
// Process commune name and description
var commDesc = '';
var commune = $('.dvpt-liste_resultat li').text().trim().replace(/:.*/, '').toLowerCase();
var text = $('.dvpt-liste_resultat li').text().trim();
if (text.includes(':')) {
commDesc = text.split(':')[1].trim();
}
var words = commune.split('-');
for (var i = 0; i < words.length; i++) {
switch (words[i].trim()) {
case 'etangs (les)':
words[i] = 'Les Étangs';
break;
case 'l\'hopital':
words[i] = 'L\'Hôpital';
break;
case 'l orme':
words[i] = 'l’Orme';
break;
case 'les':
words[i] = 'lès';
break;
case 'a':
words[i] = 'à';
break;
case 'la':
case 'le':
case 'aux':
case 'sur':
break;
default:
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
}
}
commune = words.join('-').trim();
// Add header with commune name and result count
$('body').prepend('
Recherche en cours