// ==UserScript==// @name Download File Under Timestamp Name on 8chanmoe// @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 2.0.0// ==/UserScript==constaddDownloadButton=function(cell){consthideFileButton=cell.querySelector('span.hideFileButton');if(!hideFileButton){console.error('I can\'t find the hide button, ignoring this cell.');returnfalse;}constoriginalNameLink=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.');returnfalse;}constserverHref=originalNameLink.href;consthrefSplit=serverHref.split('.');if(2>hrefSplit.length){console.error('The file name is quite unexpected, ignoring this cell.');returnfalse;}constserverExt='.'+hrefSplit.pop();consttimeName=(window.performance.timing.navigationStart+window.performance.now())/0.001;constdownloadButton=document.createElement('a');downloadButton.href=originalNameLink.href;downloadButton.download=`${timeName}`+serverExt;downloadButton.dataset.fileExt=serverExt;downloadButton.classList.add('nameLink','coloredIcon','pcgiaTimestampDownloadButton');downloadButton.title='Download file';hideFileButton.after(downloadButton);returntrue;};constuploadCells=Array.from(document.querySelectorAll('figure.uploadCell'));for(letcellofuploadCells){addDownloadButton(cell);}constthisCss=`.uploadCell > details .pcgiaTimestampDownloadButton::after { content: '\\e04E';}.uploadCell > details .pcgiaTimestampDownloadButton { display: inline-block; margin-left: 0.125em;}`;constthisStyle=document.createElement('style');thisStyle.innerText=thisCss;document.head.appendChild(thisStyle);constthreadList=document.getElementById('threadList');if(!threadList){console.error('Cannot determine thread list, will not auto-update.');return;}constallPosts=threadList.querySelector('.divPosts');if(!allPosts){console.error('Cannot determine where posts go, will not auto-update');return;}constmutationObserver=newMutationObserver((changes,self)=>{for(changeofchanges){for(nodeofchange.addedNodes){constcell=node.querySelector('figure.uploadCell');addDownloadButton(cell);}}});mutationObserver.observe(allPosts,{attributes:false,childList:true,subtree:false});
Warning
LINK
You are about to visit a link which has been flagged with the above content warnings. Do you wish to continue?