Greasy Fork

Greasy Fork is available in English.

FB: Full Timestamps 2019

Shows full timestamps on Facebook posts

当前为 2019-02-18 提交的版本,查看 最新版本

// ==UserScript==
// @name     FB: Full Timestamps 2019
// @match    https://www.facebook.com/*
// @match    https://*.facebook.com/*
// @match    http://www.facebook.com/*
// @match    http://*.facebook.com/*
// @run-at   document-start
// @grant    GM_addStyle
// @author   wOxxOm & JZersche
// @require  http://greasyfork.icu/scripts/12228/code/setMutationHandler.js
// @  REMOVE SPACES  require  https://momentjs.com/downloads/moment.min.js
// @  REMOVE SPACES  require  https://momentjs.com/downloads/moment-with-locales.min.js
// @version 3.03 Pre-Release
// @namespace http://greasyfork.icu/users/95175
// @description Shows full timestamps on Facebook posts
// ==/UserScript==

var options = {
    weekday: 'long',
    year: 'numeric',
    month: 'numeric',
    day: '2-digit'
};

GM_addStyle(
    '.full-timestamp { opacity: 0.95; color: #f00!important; }' +
    '.full-timestamp:hover { opacity: 1.0; }' +
    '.full-timestamp:before { content: ""; }' +
    '.full-timestamp:after  { content: ""; }' +
    '.timestampContent {display: inline-block; }' +
    '.sponsored {color: #0f0;}'
);

// process the already loaded portion of the page if any
expandDates(document.querySelectorAll('abbr[data-utime]'));

// process the stuff added from now on
setMutationHandler(document, 'abbr[data-utime]', expandDates);
setMutationHandler(document, '.q_1zif-zjsq', RecentTimestamps);
setMutationHandler(document, '.q_1zif-zjsq, ._5r69', RecentURLs);
setMutationHandler(document, '._5pcq', expandPostIDs);

function expandDates(nodes) {
    for (var i = 0, abbr;
        (abbr = nodes[i++]);) {
        if (abbr.querySelector('.full-timestamp')) {
            // already processed
            continue;
        }

        abbr.insertAdjacentHTML(
            'beforeend', '<span class="full-timestamp">' +
            ' on ' + moment(new Date(abbr.dataset.utime * 1000)).format('l \\at LTS')
        );
    }
}

function RecentTimestamps(nodes) {
    for (var i = 0, abbr;
        (abbr = nodes[i++]);) {
        if (abbr.querySelector('.full-timestamp')) {
            // already processed
            continue;
        }
        if (abbr.innerText.includes('min') == true) {
            var minAdjust = abbr.innerText.match(/\d+/);
            abbr.insertAdjacentHTML(
                'beforeend', '<span class="full-timestamp">' +
                ' Javascript Injection —> ' + minAdjust + ' Mɪɴᴜᴛᴇs ᴘᴀssᴇᴅ sɪɴᴄᴇ ' + moment(new Date()).subtract(minAdjust, 'minutes').format(' LTS') + '<br>'
            );
        }
        if (abbr.innerText.includes('hr') == true) {
            var hrAdjust = abbr.innerText.match(/[0-9]{1,2}/);
            var hrAdjustI = parseInt(hrAdjust, 10);
            abbr.insertAdjacentHTML(
                'beforeend', '<span class="full-timestamp">' +
                ' <span style="color:#afa">(' + moment(new Date())
                .subtract(hrAdjustI, 'hours').format('h a') +
                '<span style="color:#afa"> ≃ ᴀᴘᴘʀᴏxɪᴍᴀᴛᴇ)</span><br>'
            );
        }
    }
}

function RecentURLs(nodes) {
    for (var i = 0; i < nodes.length; i++) {
        var element = nodes[i];
        if (element.innerHTML.includes('<br>') === false && element.className != '_5pb8') {
            element.insertAdjacentHTML(
                'beforeend', '<br>' +
                element.parentNode.parentNode.parentNode.parentNode.parentNode
                .parentNode.parentNode.parentNode.parentNode.previousSibling.href
                .replace(/\?fref=nf/, '').replace('&__tn__=', '').replace('7%2Cdm-R-R', '')
                .match(/facebook.com\/[a-z|A-Z|[0-9|\-|_|.]+.[a-zA-Z|[0-9|\-|_|.|]+[a-zA-Z|[0-9|\-|_|.|?=]+/)
            );
        }
    }
}


function expandPostIDs(e) {
    for (var r = 0; r < e.length; r++) {
        var p = e[r];
        !1 === p.innerHTML.includes("<br>") && "_5pcq" === p.className && p.insertAdjacentHTML("beforeend", "<br>" + p.href.replace(/(\?__xts__%.+|\/\?type=\d&__xts__%.+)/gm, "").replace("permalink.php?", "&nbsp;permalink.php?").replace("/groups/", "Group: ").replace("/permalink/", "<br>Post ID: ").slice(24, 100).replace("/", ""))
    }
}