Last active
October 27, 2020 00:55
-
-
Save uqmessias/ea8c1bad9f874ac9e2be3dce75417b80 to your computer and use it in GitHub Desktop.
My wife did want to save some screenshots of our posts on facebook, but she wanted to remove all *like* and *reply* buttons. Besides, she wanted to change the relative date and time to an absotule one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {HTMLSpanElement} timestampContent | |
*/ | |
function getAbsoluteTime(timestampContent, timestampContainer) { | |
const ABSOLUTE_TIME_ATTR = 'data-tooltip-content'; | |
const attr = (timestampContainer && function (att) { return timestampContainer.getAttribute(att); }) || function () { return timestampContent.innerText }; | |
let absoluteTime = attr(ABSOLUTE_TIME_ATTR) || attr('title'); | |
absoluteTime = absoluteTime.indexOf(",") !== -1 | |
? absoluteTime.substr(absoluteTime.indexOf(",") + 2) | |
: absoluteTime; | |
const matcher = /([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})\s([0-9]{2})\:([0-9]{2})/gi.exec( | |
absoluteTime | |
); | |
if (matcher && matcher.length === 6) { | |
const day = matcher[1]; | |
const monthIndex = parseInt(matcher[2]) - 1; | |
const year = matcher[3]; | |
const hour = matcher[4]; | |
const minutes = matcher[5]; | |
absoluteTime`${day} de ${ | |
months[monthIndex] | |
} de ${year} às ${hour}:${minutes}`; | |
} | |
return absoluteTime; | |
} | |
function updateTimeToAbsolute() { | |
var abbrsWithTimestamp = document.querySelectorAll('abbr.livetimestamp'); | |
abbrsWithTimestamp.forEach(abbr => { | |
abbr.classList.remove('livetimestamp'); | |
const span = abbr.querySelector('span') || abbr; | |
const absoluteTime = getAbsoluteTime(span, abbr); | |
console.log(`from "${span.innerText}" to "${absoluteTime}"`); | |
span.innerHTML = absoluteTime; | |
}); | |
} | |
function removeCommentInputs() { | |
const textboxes = document.querySelectorAll('div[contenteditable=true]'); | |
if (textboxes != null) { | |
textboxes.forEach(textbox => { | |
let counter = 0; | |
let toBeRemoved = textbox; | |
while (++counter < 11 && toBeRemoved !== null) { | |
toBeRemoved = toBeRemoved.parentNode; | |
} | |
if (toBeRemoved !== null) { | |
toBeRemoved.parentNode.removeChild(toBeRemoved); | |
} | |
}) | |
} | |
} | |
function removeReactionAndRespondLinks() { | |
const buttons = document.querySelectorAll('ul > li > div[role=button]') | |
const ulTags = new Set(); | |
if (buttons !== null) { | |
buttons.forEach(button => { | |
if (button.innerText.toLowerCase() === 'responder') { | |
const liRespond = button.parentNode; | |
ulTags.add(liRespond.parentNode); | |
liRespond.parentNode.removeChild(liRespond); | |
} | |
}); | |
} | |
ulTags.forEach(ul => { | |
ul.childNodes.forEach(li => { | |
if (li.querySelector('.timestampContent') === null) { | |
li.parentNode.removeChild(li); | |
} else { | |
const separators = li.querySelectorAll('span[aria-hidden=true]'); | |
if (separators !== null) { | |
separators.forEach(separator => { | |
separator.parentNode.removeChild(separator); | |
}); | |
} | |
} | |
}); | |
}); | |
} | |
function removePostActionButtons() { | |
document.querySelectorAll('div > div > span > div[role=button]').forEach(a => { | |
if (a.innerText.toLowerCase() === 'comentar') { | |
const postActions = a.parentNode && a.parentNode.parentNode; | |
if (postActions !== null) { | |
postActions.parentNode.removeChild(postActions); | |
} | |
} | |
}) | |
} | |
updateTimeToAbsolute(); | |
removeCommentInputs(); | |
removeReactionAndRespondLinks(); | |
removePostActionButtons(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment