summaryrefslogtreecommitdiffstats
path: root/.config/qutebrowser/greasemonkey/linkedin.js
blob: d0eb289558a23695f3c9c77e524a67c36b7562cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==UserScript==
// @name         linkedin css
// @match        *://*.linkedin.com/*
// @grant        none
// @inject-into  content
// ==/UserScript==

(function() {
    'use strict';

    // Selectors
    const storySelector = '.feed-shared-update-v2';
    const descriptionSelector = '.update-components-text-view';

    // Search strings
    const searchStrings = {
        'da': ['Promoveret'],
        'en': ['Promoted'],
        'es': ['Promocionado'],
        'fr': ['Post sponsorisé']
    };

    const language = searchStrings.hasOwnProperty(document.documentElement.lang) ? document.documentElement.lang : 'en';

    function blockSponsoredPosts() {
        const stories = document.querySelectorAll(storySelector);
        for (const story of stories) {

            // console.log('Handling story', story);
            // if (story.style.display == 'none') {
            //   continue;
            // }

            const descriptions = story.querySelectorAll(descriptionSelector);
            console.debug('Found descriptions', descriptions);

            for (const description of descriptions) {
                console.debug('Handling description', description);

                const descriptionContent = description.innerText.trim();
                if (searchStrings[language].find(searchString => searchString == descriptionContent)) {

                    console.debug('Blocked sponsored story', story);
                    story.style.display = 'none';
                }
            }
        }
    }

    const observer = new MutationObserver(blockSponsoredPosts);
    observer.observe(document.body, {
        'childList': true,
        'subtree': true
    });

    blockSponsoredPosts();

    GM_addStyle(`
        .scaffold-layout__aside {
            visibility: hidden;
        }
    `)

})();
remember that computers suck.