Skip to content

Instantly share code, notes, and snippets.

@lexoyo
Created December 2, 2016 13:34
Show Gist options
  • Save lexoyo/21ac3ac79e424df5e131bf9c19cad3d5 to your computer and use it in GitHub Desktop.
Save lexoyo/21ac3ac79e424df5e131bf9c19cad3d5 to your computer and use it in GitHub Desktop.
Cleanup Facebook History user script
// ==UserScript==
// @name private-facebook
// @namespace lexoyo.user.scripts
// @description cleanup facebook as you go
// @version 1.0.0
// @grant none
// @include https://www.facebook.com*
// @run-at document-end
// ==/UserScript==
console.info('User Script Activated: lexoyo.user.scripts private-facebook');
function addCss(cssString) {
var head = document.getElementsByTagName('head')[0];
var newCss = document.createElement('style');
newCss.type = "text/css";
newCss.innerHTML = cssString;
head.appendChild(newCss);
}
function addButton(id, label, onClick) {
if(document.body.querySelector('#' + id)) return;
var container = document.body.querySelector('._2t-e');
var btn = document.createElement('button');
btn.innerHTML = label;
btn.addEventListener('click', onClick);
btn.classList.add('btn');
container.appendChild(btn);
return btn;
}
function isCleanup() {
return location.search.indexOf('cleanup');
}
function cleanup () {
var btn = document.querySelector('[data-testid=recent_searches_clear]');
console.log('cleanup now!!', btn);
if(!btn) {
setTimeout(function() {
cleanup();
}, 1000);
return;
}
btn.click();
confirmCleanup();
}
function confirmCleanup() {
var btn = document.querySelector('.layerConfirm');
console.log('confirm now!!', btn);
if(!btn) {
setTimeout(function() {
confirmCleanup();
}, 1000);
return;
}
btn.click();
setTimeout(function() {
history.back();
}, 1000);
}
addCss(`
.btn {
margin: 8px;
}
`);
/////////////////////////
if(isCleanup() >= 0) {
cleanup();
}
var test = addButton("test", "Cleanup", function() {
document.location = "https://www.facebook.com/me/allactivity?log_filter=search&cleanup";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment