Skip to content

Instantly share code, notes, and snippets.

@kofifus
Last active January 31, 2023 05:17
Show Gist options
  • Save kofifus/60f19794a828a2f05d915a670716ecd8 to your computer and use it in GitHub Desktop.
Save kofifus/60f19794a828a2f05d915a670716ecd8 to your computer and use it in GitHub Desktop.
Filter Facebook Marketplace to only show entries in the last hour
// ==UserScript==
// @name     MarketplaceFilterLastHour
// @include  https://www.facebook.com/marketplace/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.

console.log("FACEBOOK MARKETPLACE FILTER LAST HOUR");

let pattern= 'a[href^="/marketplace/item/"]:contains("hours") , a[href^="/marketplace/item/"]:contains("day") , a[href^="/marketplace/item/"]:contains("week")';

function mutationHandler (mutationRecords) {
  mutationRecords.forEach(function (mutation) {
    if (mutation.type=="childList" && typeof mutation.addedNodes=="object" && mutation.addedNodes.length) {
      for (let i=0; i<mutation.addedNodes.length; ++i) {
        if (mutation.addedNodes[i].nodeType===1) elementMutationHandler(mutation.addedNodes[i]);
      }
    } else if (mutation.type == "attributes" && mutation.target.nodeType===1) {
      elementMutationHandler(mutation.target);
    }
  });
}

function elementMutationHandler(elem) {
  $(elem).find(pattern).each(function() { console.log($(this)); $(this).parent().remove(); });
}

// start

let MutationObserver = window.MutationObserver;
let myObserver       = new MutationObserver(mutationHandler);
let obsConfig        = { childList: true, attributes: true, subtree: true,   attributeFilter: ['href'] };
myObserver.observe (document, obsConfig);

setTimeout((function() {
  myObserver.disconnect();
  window.location.reload();
}), 3*60*1000);


$('#globalContainer').attr('style', 'width: 100% !important');
$('#globalContainer:first div:first div:first  div:first').attr('style', 'width: 95% !important');
setInterval((function() {
  $('#globalContainer').attr('style', 'width: 100% !important');
  $('#globalContainer:first div:first div:first  div:first').attr('style', 'width: 95% !important');
}), 1000);
  • Hit the save icon
  • close greasemokey editor
  • refresh your marketplace page
@deltabravozulu
Copy link

If anyone tries to do this in the future, change .../?sort=CREATION_TIME_DESCEND to .../?sortBy=creation_time_descend.

@MichaRotstein
Copy link

@deltabravozulu is this still working for you ? I can't get back to "Classic Facebook"

@deltabravozulu
Copy link

@MichaRotstein I don't think you actually need to use "Classic Facebook" to make it work.

@deltabravozulu
Copy link

BUT I am not 100% sure, to be honest. I was rolling around between a few scripts trying to cobble my own usable one together and I think this one clued me in to the URL variations and so I just wanted to let people know the sort function changed.

I am pretty sure I had this one working but I was annoyed that I couldn't really toggle things in-page (nor could I in the script I wrote--I was a bit lazy with it), so I just went back to the way things were with no scripts at all (aka terrible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment