SankakuComplex - URL Verifier with IndexedDB

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.

  1. // ==UserScript==
  2. // @name SankakuComplex - URL Verifier with IndexedDB
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.15
  5. // @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.
  6. // @author mtpontes
  7. // @match *://chan.sankakucomplex.com/posts/*
  8. // @match *://chan.sankakucomplex.com/*/posts/*
  9. // @match *://idol.sankakucomplex.com/posts/*
  10. // @match *://idol.sankakucomplex.com/*/posts/*
  11. // @match *://legacy.sankakucomplex.com/posts/*
  12. // @match *://legacy.sankakucomplex.com/*/posts/*
  13. // @grant none
  14. // @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
  15.  
  16. // @grant none
  17. // @license MIT
  18. // ==/UserScript==
  19.  
  20. (function() {
  21.  
  22. console.log('=== Starting execution of the visited URLs persister ===');
  23. const dbName = 'VisitedDB';
  24. const storeName = 'visitedURLs'
  25. const readMode = 'readonly'
  26. const writeMode = 'readwrite'
  27.  
  28. function getDatabaseConnection() {
  29. return new Promise((resolve, reject) => {
  30. const request = indexedDB.open(dbName, 1);
  31.  
  32. // If the database structure needs to be created or updated
  33. request.onupgradeneeded = (event) => {
  34. const db = event.target.result;
  35. if (!db.objectStoreNames.contains(storeName)) {
  36. db.createObjectStore(storeName, { keyPath: 'url' });
  37. }
  38. };
  39.  
  40. request.onsuccess = (event) => resolve(event.target.result); // Returns the database as the result of the Promise
  41. request.onerror = (event) => reject('Error opening the database');
  42. });
  43. }
  44.  
  45. function getDbTransaction(db, mode) {
  46. return db.transaction([storeName], mode).objectStore(storeName);
  47. }
  48.  
  49. async function isVisitedPage(db, pageUrl) {
  50. const store = getDbTransaction(db, readMode);
  51. const getRequest = store.get(pageUrl);
  52.  
  53. return new Promise((resolve, reject) => {
  54. getRequest.onsuccess = () => resolve(!!getRequest.result); // Operation succeeded
  55. getRequest.onerror = () => reject('Error accessing the database'); // Runs if the operation above fails
  56. });
  57. }
  58.  
  59. async function addCurrentPage(db, pageUrl) {
  60. const store = getDbTransaction(db, writeMode);
  61.  
  62. return new Promise((resolve, reject) => {
  63. const request = store.add({ url: pageUrl });
  64.  
  65. request.onsuccess = () => resolve(); // If successful, resolve without any value
  66. request.onerror = () => reject('Error adding the URL to the database'); // Runs if the operation above fails
  67. });
  68. }
  69.  
  70. function addWarning() {
  71. const warningDiv = document.createElement('div');
  72. warningDiv.style.position = 'fixed';
  73. warningDiv.style.top = '10px';
  74. warningDiv.style.left = '10px';
  75. warningDiv.style.backgroundColor = 'rgba(255, 0, 0, 0.8)';
  76. warningDiv.style.color = 'white';
  77. warningDiv.style.padding = '10px';
  78. warningDiv.style.zIndex = '9999';
  79. warningDiv.innerText = 'You have already visited this page!';
  80. document.body.appendChild(warningDiv);
  81. console.log('Visited URL warning was added');
  82. }
  83.  
  84. async function run() {
  85. try {
  86. const currentUrl = window.location.href;
  87. const db = await getDatabaseConnection();
  88.  
  89. const isVisited = await isVisitedPage(db, currentUrl);
  90.  
  91. if (isVisited) {
  92. console.log('URL already visited');
  93. addWarning();
  94. return;
  95. }
  96.  
  97. await addCurrentPage(db, currentUrl);
  98. console.log('URL added to the database');
  99.  
  100. } catch (error) {
  101. console.error('Error:', error);
  102. }
  103. }
  104.  
  105. run();
  106. })();