jordwest / news-feed-eradicator

A browser extension that deletes your news feed and replaces it with a nice quote
MIT License
1.16k stars 280 forks source link

LinkedIn post eradication #275

Open imanhaq01 opened 6 months ago

imanhaq01 commented 6 months ago

Hi there, I'm using the extension on an edge browser for LinkedIn and the news feed eradicator eradicates any posts by other people that I click on for my notification centre unless I pause the setting or turn it off, which it only used to do for the news feed.

https://github.com/jordwest/news-feed-eradicator/assets/100493216/d7617fa7-f0af-4f76-b460-50ee751e1927

I hope that demonstrates the issue correctly. Please let me know if there is any other information you need.

james-tindal commented 5 months ago

LinkedIn changed the behaviour of the notifications page. Posts now link to linkedin.com/feed?highlightUpdateUrn=... That page shows the post at the top followed by the usual feed.

Two possible solutions: Detect highlightedUpdateUrn in the query params and

james-tindal commented 5 months ago

Here's a userscript to fix this problem:

Click here ```js // ==UserScript== // @name Fix LinkedIn notifications page // @description Fix notification links so they go to the post or activity page instead of the feed. // @version 2024-01-19 // @match https://www.linkedin.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=linkedin.com // ==/UserScript== (() => { 'use strict' /* Monkey-patch locationchange event */ const oldPushState = history.pushState history.pushState = function pushState() { const ret = oldPushState.apply(this, arguments) window.dispatchEvent(new Event('locationchange')) return ret } const oldReplaceState = history.replaceState history.replaceState = function replaceState() { const ret = oldReplaceState.apply(this, arguments) window.dispatchEvent(new Event('locationchange')) return ret } window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange'))) /* Listen for notifications page */ continueIfNotificationsPage() window.addEventListener('locationchange', continueIfNotificationsPage) async function continueIfNotificationsPage() { if (!isNotificationsPage()) return const cardList = await waitForElement({ target: "nt-card-list", ancestor: 'application-outlet' }) changeLinks(cardList) } function changeLinks(cardList) { const initial_notification_elements = cardList.children // change link for initial 10 loaded notifications for(const el of initial_notification_elements) changeLink(el) // change link for any notifications that load later const listener = mutation_records => mutation_records .forEach(mr => mr.addedNodes.forEach(node => node.nodeName === 'DIV' && changeLink(node))) observeMutations({ element: cardList, listener, childList: true }) } function changeLink (notification_element) { const link_element = notification_element .querySelector('a.nt-card__headline') const url = link_element.attributes.href.value const newUrl = url .replace(/^\/feed\/\?highlightedUpdateUrn=urn%3Ali%3Aactivity%3A(\d{19}).*/, '/feed/update/urn:li:activity:$1') link_element.setAttribute('href', newUrl) remove_click_events(link_element) } /* ... */ function observeMutations({ element, listener, ...options }) { const observer = new MutationObserver(listener) observer.observe(element, options) return observer } function waitForElement({ ancestor, target }) { const ancestorEl = document.getElementsByClassName(ancestor)[0] const search = ancestorEl.getElementsByClassName(target) if (search.length > 0) return Promise.resolve(search[0]) return new Promise(resolve => { const observer = observeMutations({ listener, element: ancestorEl, childList: true, subtree: true }) function listener(mutationRecords) { for (const mutationRecord of mutationRecords) { for (const node of mutationRecord.addedNodes) if (node?.classList?.contains?.(target)) { observer.disconnect() resolve(node) } }} }) } // Remove click events overriding the new href function remove_click_events(element) { element.outerHTML = element.outerHTML } function isNotificationsPage() { const matchNotificationsPage = /^https:\/\/www\.linkedin\.com\/notifications\/?\??.*$/ return matchNotificationsPage.test(window.location) } })() ```