Skip to content

Instantly share code, notes, and snippets.

@JarrettR
Last active September 8, 2024 23:06
Show Gist options
  • Select an option

  • Save JarrettR/a4b1ecb12aa8e1982d0f41b6b9886bf3 to your computer and use it in GitHub Desktop.

Select an option

Save JarrettR/a4b1ecb12aa8e1982d0f41b6b9886bf3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name FBMP Hider
// @namespace http://tampermonkey.net/
// @version 2024-09-08
// @description Add a button to hide FB MP listings
// @author Jarrett Rainier
// @match https://www.facebook.com/marketplace/*
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
function addHidden(id) {
console.log("Adding " + id + " to the hidden list");
var timestamp = Date.now();
GM_setValue(id.toString(),timestamp);
}
function getHidden(id) {
//console.log("Checking " + id + " on the hidden list");
var store = GM_getValue(id.toString(), null);
if (store != null) {
var timestamp = Date.now();
//Reset the clock on keeping the listing hidden
GM_setValue(id.toString(),timestamp);
}
return store
}
function getMPId(url) {
var ids = url.split('/');
//console.log(url.split('/')[3]);
return ids[3];
}
function hideMPClass(jNode, id) {
if (id != null) {
console.log("Hiding " + id);
jNode.parent().parent().parent().parent().parent().parent().parent().parent().hide()
} else {
//console.log("Didn't hide " + id);
//console.log(jNode);
}
}
function insertMPHideButton(jNode, id) {
var insertA = document.createElement('input');
//insertA.href = '#';
insertA.setAttribute('type',"button");
insertA.setAttribute('value',"hide");
insertA.setAttribute('id',"hide" + id);
insertA.innerHTML = "Hide";
insertA.addEventListener("click", function(event) { event.stopPropagation(); addHidden(id); hideMPClass(jNode, id); }, true);
jNode.parent().append(insertA);
var href = jNode.attr('href');
var newHTML = jNode.children().eq(0).html().replace("div", "a href='" + href + "' ");
var n = newHTML.lastIndexOf("div");
newHTML = newHTML.slice(0, n) + newHTML.slice(n).replace("div", "a");
jNode.attr('href', '');
newHTML = jNode.parent().html().replace("a", "div");
n = newHTML.lastIndexOf("a");
newHTML = newHTML.slice(0, n) + newHTML.slice(n).replace("a", "div");
}
function checkMPclass (jNode) {
//xlil10hfl
//console.log (jNode);
var id = getMPId(jNode.attr("href"));
if (getHidden(id) != null) {
hideMPClass(jNode, id);
} else {
insertMPHideButton(jNode, id);
}
}
(function() {
console.log ("Do you see this?");
//waitForKeyElements (".xjp7ctv > div > span > div > div > a", checkMPclass);
waitForKeyElements (".xjp7ctv > div > span > div > div > div > div > a", checkMPclass);
console.log ("Script run to completion");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment