ScriptKitty

4chan file epoch to date title

Apr 23rd, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         File dates
  3. // @description  Adds a human readable date timestamp to file epoch timestamps
  4. // @namespace    skitty
  5. // @include      *://boards.4chan.org/*
  6. // @run-at       document-start
  7. // @author       Skitty
  8. // @version      1
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.     "use-strict";
  13.     let parse = function (ID, str) {
  14.         let fileInfo = document.querySelector("#fT"+ID.match(/(\d+)/g)[0]+" > .file-info");
  15.         let fileText = parseInt((((str||fileInfo.querySelector("a:nth-child(1)").textContent).match(/(\d{13,})/g))||[""])[0]);
  16.         if(fileText)
  17.             fileInfo.title = new Date(fileText).toLocaleString();
  18.     };
  19.     document.addEventListener("4chanXInitFinished", function() {
  20.         document.querySelectorAll(".file-info").forEach(function(element) {
  21.             parse(element.parentNode.id, element.childNodes[0].text);
  22.         });
  23.     }, false);
  24.     document.addEventListener("ThreadUpdate", function(e) {
  25.         for(let i in e.detail.newPosts)
  26.             parse(e.detail.newPosts[i]);
  27.     }, false);
  28. })();
Advertisement
Add Comment
Please, Sign In to add comment