setMutationHandler

MutationObserver wrapper to wait for the specified CSS selector

< Valutazione su setMutationHandler

Recensione: Bene - lo script funziona

§
Pubblicato: 22/03/2018

Attempting to use this to show post ID on FB Posts

You wrote a script over about a year ago or so for me that showed the exact time on FB posts, I've tweaked that script a little bit to show the times in a different way and including seconds, but I'm now wanting to add a post id to the script.

I've been successful using document.querySelector("a._5pcq").getAttribute("href");

but, the issue I get is that each status shows the same post number, the same ID. I know you'll know how to fix this, it's related to the nodes and like you did for the times [i++], but I don't know how to incorporate it.

Here's the current script in a working state but with the issue described above. I hope you'll help. Thanks.

https://pastebin.com/zV45XMFG

woxxomAutore
§
Pubblicato: 22/03/2018

From what I see in devtools inspector, _5pcq is a parent element of each abbr element which your script observes in setMutationHandler(document, 'abbr[data-utime]', expandDates); so you need to move var y = line inside the loop right before abbr.insertAdjacentHTML:

var y = abbr.closest('a._5pcq').href;

or, better yet, with a fallback:

var y = (abbr.closest('a._5pcq') || {}).href || '';
§
Pubblicato: 22/03/2018
Modificato: 22/03/2018

That might have worked, I managed to do it this way instead prior to reading your response.

https://pastebin.com/V4UX1jEn

Thank you for responding, and thank you for helping me. It means the world to me.

I also managed to get rid of the hundreds of replacements in the script, now there's only a few. But I do have to ask you if there might be a better way of doing this one.

' on ' + abbr.title.replace(/am|pm/,'')

.replace(/0\d/, number => number[1]) // Replaces 01-09 Months to 1-9

// Fix for the Years being replaced by the above.
.replace(210,2010).replace(211,2011)
.replace(212,2012).replace(213,2013)
.replace(214,2014).replace(215,2015)
.replace(216,2016).replace(217,2017)
.replace(218,2018).replace(219,2019)

Pubblica risposta

Accedi per pubblicare una risposta.