// ==UserScript==
// @name        Download File Under Timestamp Name
// @namespace   pcgia
// @description Adds a button to download a file and gives it a timestamp name, instead of the original name or the hash
// @match       https://8chan.moe/*/res/*
// @match       https://8chan.se/*/res/*
// @version     1
// @grant       none
// @run-at      document-end
// @author      Starknight
// @version     1.0.0
// ==/UserScript==
const uploadCells = Array.from(document.querySelectorAll('figure.uploadCell'));
for (let cell of uploadCells) {
  const hideFileButton = cell.querySelector('span.hideFileButton');
  if (!hideFileButton) {
    console.error('I can\'t find the hide button, ignoring this cell.');
    continue;
  }

  const originalNameLink = cell.querySelector('a.originalNameLink');
  if (!originalNameLink || !originalNameLink.href || 0 === originalNameLink.href.length) {
    console.error('I can\'t grasp the original file name, ignoring this cell.');
    continue;
  }

  const serverHref = originalNameLink.href;
  const hrefSplit = serverHref.split('.');
  if (2 > hrefSplit.length) {
    console.error('The file name is quite unexpected, ignoring this cell.');
    continue;
  }

  const serverExt = '.' + hrefSplit.pop();

  const downloadButton = document.createElement('a');
  downloadButton.href = originalNameLink.href;
  downloadButton.download = Date.now() + serverExt;
  downloadButton.dataset.fileExt = serverExt;
  downloadButton.classList.add('nameLink', 'coloredIcon', 'pcgiaTimestampDownloadButton');
  downloadButton.title = 'Download file';

  hideFileButton.after(downloadButton);
}

const thisCss = `.uploadCell > details .pcgiaTimestampDownloadButton::after {
     content: '\\e04E';
}

.uploadCell > details .pcgiaTimestampDownloadButton {
     display: inline-block;
     margin-left: 0.125em;
}`;
const thisStyle = document.createElement('style');
thisStyle.innerText = thisCss;

document.head.appendChild(thisStyle);
Edit

Pub: 21 Apr 2025 12:01 UTC

Views: 29