Skip to content

Instantly share code, notes, and snippets.

@spixi
Last active March 13, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spixi/d399b36ac76217b172ea9a583f198660 to your computer and use it in GitHub Desktop.
Save spixi/d399b36ac76217b172ea9a583f198660 to your computer and use it in GitHub Desktop.
FB Timestamp Displayer
// ==UserScript==
// @name FB Timestamp Displayer
// @namespace Facebook
// @match http://*.facebook.com/*
// @match https://*.facebook.com/*
// @run-at document-start
// @version 0.1
// @author spixi
// @description Shows the timestamp of Facebook posts
// ==/UserScript==
//FB Timestamp Displayer
//Copyright (C) 2020 Marius Spix
//marius.spix@web.de
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 3 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License
//along with this program; if not, write to the Free Software Foundation,
//Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"use strict";
document.addEventListener("DOMContentLoaded", function(){
nodes = document.getElementsByClassName('timestampContent');
for (i = 0; i < nodes.length; ++i) {
node[i].innerText = new Date(parseInt(node[i].parentNode().getAttribute('data-utime'))*1000).toLocaleString();
}
});
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes.length == 1 && mutation.target.classList.contains("livetimestamp")) { //mutation.target.hasAttribute('data-utime')
var node = mutation.addedNodes[0];
node.innerText = new Date(parseInt(mutation.target.getAttribute('data-utime'))*1000).toLocaleString();
}
});
});
observer.observe(document, { childList: true, subtree: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment