Check if the URL has been accessed before and signaling to the user. With this script you will be able to know if you have already accessed the specific page of some image/video/tag before. If you have never accessed a URL, it will persist it in IndexedDB, if you have already accessed it, a warning message will be added to your screen.
// ==UserScript==
// @name SankakuComplex - URL Verifier with IndexedDB
// @namespace http://tampermonkey.net/
// @version 0.15
// @description Check if the URL has been accessed before and signaling to the user. With this script you will be able to know if you have already accessed the specific page of some image/video/tag before. If you have never accessed a URL, it will persist it in IndexedDB, if you have already accessed it, a warning message will be added to your screen.
// @author mtpontes
// @match *://chan.sankakucomplex.com/posts/*
// @match *://chan.sankakucomplex.com/*/posts/*
// @match *://idol.sankakucomplex.com/posts/*
// @match *://idol.sankakucomplex.com/*/posts/*
// @match *://legacy.sankakucomplex.com/posts/*
// @match *://legacy.sankakucomplex.com/*/posts/*
// @grant none
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABbmlDQ1BpY2MAACiRdZHPKwRhGMc/dolYbeIgOewBOeyWKDlqFZflsFZZXGZmZ3fVzphmZpNclYuDchAXvw7+A67KlVKKlOTgL/DrIo3n3VUr8U7vPJ++7/t9et/vC6FUybC8+gGwbN9NTyRjs9m5WOMTETpoox00w3Mmp8cz/Dveb6hT9Tqhev2/78/RkjM9A+qahIcNx/WFR4VTy76jeEO4wyhqOeF94bgrBxS+ULpe5UfFhSq/KnYz6TEIqZ6xwg/Wf7BRdC3hfuEeq1Q2vs+jbhIx7ZlpqV0yu/FIM0GSGDplFinhk5BqS2Z/+wYqvimWxGPI32EFVxwFiuKNi1qWrqbUvOimfCVWVO6/8/TyQ4PV7pEkNDwEwUsvNG7B52YQfBwEwechhO/hzK75lySnkTfRN2tazx5E1+DkvKbp23C6Dp13juZqFSksM5TPw/MxtGah/Qqa56tZfa9zdAuZVXmiS9jZhT7ZH134ArhcZ+m/WStSAAAACXBIWXMAAAsSAAALEgHS3X78AAAAeElEQVQ4y2NgoCX4Xyb7H4TxqWHCo7keG5toA4CgAQebsAHYbMTlCiYibMfrCiZibcIlx0SE3/GGBRM+Gxi7HjeCMD41TESGPE5XMOGzHRsbnxcIxbsDDAMts4cbjmR7A4kpvQHkMiZCKY1QSmXBZTKedNBA1RwLAFCeNCTVhz2FAAAAAElFTkSuQmCC
// @grant none
// @license MIT
// ==/UserScript==
(function() {
console.log('=== Starting execution of the visited URLs persister ===');
const dbName = 'VisitedDB';
const storeName = 'visitedURLs'
const readMode = 'readonly'
const writeMode = 'readwrite'
function getDatabaseConnection() {
return new Promise((resolve, reject) => {
const request = indexedDB.open(dbName, 1);
// If the database structure needs to be created or updated
request.onupgradeneeded = (event) => {
const db = event.target.result;
if (!db.objectStoreNames.contains(storeName)) {
db.createObjectStore(storeName, { keyPath: 'url' });
}
};
request.onsuccess = (event) => resolve(event.target.result); // Returns the database as the result of the Promise
request.onerror = (event) => reject('Error opening the database');
});
}
function getDbTransaction(db, mode) {
return db.transaction([storeName], mode).objectStore(storeName);
}
async function isVisitedPage(db, pageUrl) {
const store = getDbTransaction(db, readMode);
const getRequest = store.get(pageUrl);
return new Promise((resolve, reject) => {
getRequest.onsuccess = () => resolve(!!getRequest.result); // Operation succeeded
getRequest.onerror = () => reject('Error accessing the database'); // Runs if the operation above fails
});
}
async function addCurrentPage(db, pageUrl) {
const store = getDbTransaction(db, writeMode);
return new Promise((resolve, reject) => {
const request = store.add({ url: pageUrl });
request.onsuccess = () => resolve(); // If successful, resolve without any value
request.onerror = () => reject('Error adding the URL to the database'); // Runs if the operation above fails
});
}
function addWarning() {
const warningDiv = document.createElement('div');
warningDiv.style.position = 'fixed';
warningDiv.style.top = '10px';
warningDiv.style.left = '10px';
warningDiv.style.backgroundColor = 'rgba(255, 0, 0, 0.8)';
warningDiv.style.color = 'white';
warningDiv.style.padding = '10px';
warningDiv.style.zIndex = '9999';
warningDiv.innerText = 'You have already visited this page!';
document.body.appendChild(warningDiv);
console.log('Visited URL warning was added');
}
async function run() {
try {
const currentUrl = window.location.href;
const db = await getDatabaseConnection();
const isVisited = await isVisitedPage(db, currentUrl);
if (isVisited) {
console.log('URL already visited');
addWarning();
return;
}
await addCurrentPage(db, currentUrl);
console.log('URL added to the database');
} catch (error) {
console.error('Error:', error);
}
}
run();
})();