Last active
February 24, 2024 22:26
-
-
Save JarrettR/a4b1ecb12aa8e1982d0f41b6b9886bf3 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name FBMP Hider | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-01-11 | |
// @description try to take over the world! | |
// @author You | |
// @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== | |
var localStorageName = "FBMarketHide"; | |
var hiddenIds = ["12234", "3800851237024"]; | |
//localStorage[localStorageName]=JSON.stringify(hiddenIds); | |
function addHidden(id) { | |
console.log("Adding " + id + " to the hidden list"); | |
var store = GM_getValue('FBMarketHide'); | |
//alert(store); | |
var value = JSON.parse(store) + ''; | |
//alert(value); | |
var ids = value.split(','); | |
ids.push(id); | |
GM_setValue('FBMarketHide',JSON.stringify(ids)); | |
} | |
function getMPId(url) { | |
var ids = url.split('/'); | |
//console.log(url.split('/')[3]); | |
return ids[3]; | |
} | |
function hideMPClass(jNode, id) { | |
//var id = getMPId(jNode.attr("href")); | |
if (id != null) { | |
console.log("Hiding " + id); | |
jNode.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 (hiddenIds.includes(id)) { | |
hideMPClass(jNode, id); | |
} else { | |
insertMPHideButton(jNode, id); | |
} | |
} | |
(function() { | |
console.log ("Do you see this?"); | |
var store = GM_getValue(localStorageName); | |
if (store == null) { | |
console.log("Added default key"); | |
GM_setValue(localStorageName,JSON.stringify([''])) | |
} | |
hiddenIds = JSON.parse(store).toString().split(','); | |
waitForKeyElements (".xjp7ctv > div > span > 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