Greasy Fork

Shined up real nice.

Facebook unsponsored

Block Facebook news feed "sponsored" posts

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// ==UserScript==
// @name         Facebook unsponsored
// @namespace    http://tampermonkey.net/
// @version      1.15
// @description  Block Facebook news feed "sponsored" posts
// @author       solskido
// @supportURL   https://greasyfork.org/en/scripts/22210-facebook-unsponsored/feedback
// @match        https://www.facebook.com/*
// @run-at       document-idle
// @grant        none
//
// Thanks to: enm, Mathieu
//
// ==/UserScript==

(function() {
    'use strict';
    // Selectors
    var streamSelector = 'div[id^="topnews_main_stream"]';
    var storySelectors = [
        'div[id^="hyperfeed_story_id"]',
        'div[data-ownerid^="hyperfeed_story_id"]'
    ];
    var searchedNodes = [{
        // Sponsored
        'selector': [
            'div[id^=feed_subtitle] > span > div > div > a',
            'a.uiStreamSponsoredLink'
        ],
        'content': {
            'af':      ['Geborg'],
            'am':      ['የተከፈለበት ማስታወቂያ'],
            'ar':      ['إعلان مُموَّل'],
            'as':      ['পৃষ্ঠপোষকতা কৰা'],
            'ay':      ['Yatiyanaka'],
            'az':      ['Sponsor dəstəkli'],
            'be':      ['Рэклама'],
            'bg':      ['Спонсорирано'],
            'br':      ['Paeroniet'],
            'bs':      ['Sponzorirano'],
            'bn':      ['সৌজন্যে'],
            'ca':      ['Patrocinat'],
            'cb':      ['پاڵپشتیکراو'],
            'co':      ['Spunsurizatu'],
            'cs':      ['Sponzorováno'],
            'cx':      ['Giisponsoran'],
            'cy':      ['Noddwyd'],
            'da':      ['Sponsoreret'],
            'de':      ['Gesponsert'],
            'el':      ['Χορηγούμενη'],
            'en':      ['Sponsored', 'Chartered'],
            'eo':      ['Reklamo'],
            'es':      ['Publicidad', 'Patrocinado'],
            'et':      ['Sponsitud'],
            'eu':      ['Babestua'],
            'fa':      ['دارای پشتیبانی مالی'],
            'fi':      ['Sponsoroitu'],
            'fo':      ['Stuðlað'],
            'fr':      ['Commandité', 'Sponsorisé'],
            'fy':      ['Sponsore'],
            'ga':      ['Urraithe'],
            'gl':      ['Patrocinado'],
            'gn':      ['Oñepatrosinapyre'],
            'gx':      ['Χορηγούμενον'],
            'hi':      ['प्रायोजित'],
            'hu':      ['Hirdetés'],
            'id':      ['Bersponsor'],
            'it':      ['Sponsorizzata'],
            'ja':      ['広告'],
            'jv':      ['Disponsori'],
            'kk':      ['Демеушілік көрсеткен'],
            'km':      ['បានឧបត្ថម្ភ'],
            'lo':      ['ໄດ້ຮັບການສະໜັບສະໜູນ'],
            'mk':      ['Спонзорирано'],
            'ml':      ['സ്പോൺസർ ചെയ്തത്'],
            'mn':      ['Ивээн тэтгэсэн'],
            'mr':      ['प्रायोजित'],
            'ms':      ['Ditaja'],
            'ne':      ['प्रायोजित'],
            'nl':      ['Gesponsord'],
            'or':      ['ପ୍ରଯୋଜିତ'],
            'pa':      ['ਸਰਪ੍ਰਸਤੀ ਪ੍ਰਾਪਤ'],
            'pl':      ['Sponsorowane'],
            'ps':      ['تمويل شوي'],
            'pt':      ['Patrocinado'],
            'ru':      ['Реклама'],
            'sa':      ['प्रायोजितः |'],
            'si':      ['අනුග්‍රහය දක්වන ලද'],
            'so':      ['La maalgeliyey'],
            'sv':      ['Sponsrad'],
            'te':      ['స్పాన్సర్ చేసినవి'],
            'th':      ['ได้รับการสนับสนุน'],
            'tl':      ['May Sponsor'],
            'tr':      ['Sponsorlu'],
            'tz':      ['ⵉⴷⵍ'],
            'uk':      ['Реклама'],
            'ur':      ['تعاون کردہ'],
            'vi':      ['Được tài trợ'],
            'zh-Hans': ['赞助内容'],
            'zh-Hant': ['贊助']
        }
    }, {
        // Suggested Post
        'selector': [
            '.fbUserPost div > div > span > span',
            '.fbUserStory div > div > span > span',
            '.fbUserContent div > div > span > span'
        ],
        'content': {
            'af':        ['Voorgestelde Plasing'],
            'am':        ['የሚመከር ልጥፍ'],
            'ar':        ['منشور مقترح'],
            'as':        ['পৰামৰ্শিত প\'ষ্ট'],
            'az':        ['Təklif edilən yazılar'],
            'be':        ['Прапанаваны допіс'],
            'bg':        ['Предложена публикация'],
            'bn':        ['প্রস্তাবিত পোস্ট'],
            'br':        ['Embannadenn aliet'],
            'bs':        ['Predloženi sadržaj'],
            'ca':        ['Publicació suggerida'],
            'cb':        ['بابەتی پێشنیارکراو'],
            'co':        ['Posti cunsigliati'],
            'cs':        ['Navrhovaný příspěvek'],
            'cx':        ['Gisugyot nga Pagpatik'],
            'cy':        ['Neges a Awgrymir'],
            'da':        ['Foreslået opslag'],
            'de':        ['Vorgeschlagener Beitrag'],
            'el':        ['Προτεινόμενη δημοσίευση'],
            'en':        ['Suggested Post', 'Recommended fer ye eye'],
            'eo':        ['Proponita afiŝo'],
            'es':        ['Publicación sugerida'],
            'et':        ['Soovitatud postitus'],
            'eu':        ['Iradokitako argitalpena'],
            'fa':        ['پست پیشنهادی'],
            'fi':        ['Ehdotettu julkaisu'],
            'fo':        ['Viðmælt uppslag'],
            'fr':        ['Publication suggérée'],
            'fy':        ['Oanrikkemandearre berjocht'],
            'ga':        ['Postáil Mholta'],
            'gl':        ['Publicación suxerida'],
            'gn':        ['Ojeikuaaukáva iporãva ojehecha'],
            'gx':        ['Παϱαινουμένη Ἔκϑεσις'],
            'hi':        ['सुझाई गई पोस्ट'],
            'hu':        ['Ajánlott bejegyzés'],
            'it':        ['Post consigliato'],
            'id':        ['Saran Kiriman'],
            'ja':        ['おすすめの投稿'],
            'jv':        ['Kiriman sing Disaranake'],
            'kk':        ['Ұсынылған жазба'],
            'km':        ['ការប្រកាសដែលបានណែនាំ'],
            'ko':        ['추천 게시물'],
            'lo':        ['ໂພສຕ໌ແນະນຳ', 'ຜູ້ສະໜັບສະໜູນ'],
            'mk':        ['Предложена објава'],
            'ml':        ['നിർദ്ദേശിച്ച പോ‌സ്റ്റ്'],
            'mn':        ['Санал болгосон нийтлэл'],
            'mr':        ['सुचवलेली पोस्ट'],
            'ms':        ['Kiriman Dicadangkan'],
            'ne':        ['सुझाव गरिएको पोस्ट'],
            'nl':        ['Voorgesteld bericht'],
            'or':        ['ପ୍ରସ୍ତାବିତ ପୋଷ୍ଟ'],
            'pa':        ['ਸੁਝਾਈ ਗਈ ਪੋਸਟ'],
            'pl':        ['Proponowany post'],
            'ps':        ['وړاندیز شوې ځړونه'],
            'pt':        ['Publicação sugerida'],
            'ru':        ['Рекомендуемая публикация'],
            'sa':        ['उपॆक्षित प्रकटनं'],
            'si':        ['යෝජිත පළ කිරීම'],
            'so':        ['Bandhig la soo jeediye'],
            'sv':        ['Föreslaget inlägg'],
            'te':        ['సూచింపబడిన పోస్ట్'],
            'th':        ['โพสต์ที่แนะนำ'],
            'tl':        ['Iminungkahing Post'],
            'tr':        ['Önerilen Gönderiler', 'Önerilen Gönderi'],
            'tz':        ['ⵜⴰⵥⵕⵉⴳⵜ ⵉⵜⵜⵓⵙⵓⵎⵔⵏ'],
            'uk':        ['Рекомендований допис'],
            'ur':        ['تجویز کردہ مراسلہ'],
            'vi':        ['Bài viết được đề xuất'],
            'zh-Hans':   ['推荐帖子'],
            'zh-Hant':   ['推薦帖子', '推薦貼文']
        }
    }, {
        // Popular Live Video                                                      // A Video You May Like                                                           // Suggested Page
        'selector': [
            '.fbUserPost div > div > div:not(.userContent)',
            '.fbUserStory div > div > div:not(.userContent)',
            '.fbUserContent div > div > div:not(.userContent)'
        ],
        'exclude': function(node) {
            if(!node) {
                return true;
            }

            return (node.children && node.children.length);
        },
        'content': {
            'af':        ['Popular Live Video', 'Gewilde Live Video',              '\'n Video waarvan jy dalk sal hou'],
            'ar':        ['مباشر رائج'                                            ,'فيديو قد يعجبك'],
            'as':        ['Popular Live Video',                                    'আপুনি ভাল পাব পৰা এটা ভিডিঅ\''],
            'az':        ['Popular Live Video',                                    'Bu video sənin xoşuna gələ bilər'],
            'bg':        ['Популярно видео на живо',                               'Видео, което е възможно да харесате'],
            'bn':        ['জনপ্রিয় লাইভ ভিডিও',                                     'আপনার পছন্দ হতে পারে এমন একটি ভিডিও'],
            'br':        ['Video Siaran Langsung Populer',                         'Sebuah Video yang Mungkin Anda Suka'],
            'bs':        ['Video Siaran Langsung Populer',                         'Sebuah Video yang Mungkin Anda Suka'],
            'ca':        ['Video Siaran Langsung Populer',                         'Sebuah Video yang Mungkin Anda Suka'],
            'cs':        ['Populární živé vysílání',                               'Video, které by se vám mohlo líbit'],
            'cx':        ['Popular Live Video',                                    'Usa ka Video nga Mahimong Ganahan Ka'],
            'da':        ['Populær livevideo',                                     'En video, du måske vil synes godt om'],
            'de':        ['Beliebtes Live-Video',                                  'Ein Video, das dir gefallen könnte'],
            'en':        ['Popular Live Video',                                    'A Video You May Like',                                                           'Suggested Page'],
            'es':        ['Vídeo en directo popular', 'Video en vivo popular',     'Un video que te puede gustar', 'Un vídeo que te puede gustar'],
            'fi':        ['Suosittu live-video'],
            'fr':        ['Vidéo en direct populaire',                             'Une vidéo que vous pourriez aimer'],
            'hi':        ['लोकप्रिय लाइव वीडियो',                                     'वह वीडियो जो आपको पसंद हो सकता है'],
            'hu':        ['Népszerű élő videó',                                    'Egy videó, amely esetleg tetszik neked'],
            'it':        ['Video in diretta popolare',                             'Un video che potrebbe piacerti'],
            'id':        ['Video Siaran Langsung Populer',                         'Sebuah Video yang Mungkin Anda Suka'],
            'ja':        ['人気ライブ動画',                                         'おすすめの動画'],
            'jv':        ['Video Siaran Langsung Populer',                         'Video sing Menawa Sampeyan Seneng'],
            'kk':        ['Popular Live Video',                                    'A Video You May Like'],
            'km':        ['Popular Live Video',                                    'វីដេអូ​ដែល​អ្នក​ប្រហែល​ជាចូលចិត្ត'],
            'ko':        ['인기 라이브 방송',                                       '회원님이 좋아할 만한 동영상'],
            'lo':        ['Popular Live Video',                                    'A Video You May Like'],
            'mk':        ['Popular Live Video',                                    'Видео кое можеби ќе ти се допадне'],
            'ml':        ['ജനപ്രിയ Live വീഡിയോ',                             'നിങ്ങൾക്ക് ഇഷ്‌ടമാകാനിടയുള്ള ‌വീഡിയോ'],
            'mn':        ['Popular Live Video',                                    'Танд таалагдаж магадгүй бичлэг'],
            'mr':        ['प्रसिद्ध थेट व्हिडिओ',                                        'एक व्हिडिओ जो कदाचित आपल्याला आवडू शकतो'],
            'ms':        ['Video Live Popular',                                    'Video Yang Anda Mungkin Suka'],
            'ne':        ['Popular Live Video',                                    'तपाईंले मन पराउन सक्ने भिडियो'],
            'nl':        ['Populaire livevideo',                                   'Een video die je misschien leuk vindt', 'Een video die je wellicht leuk vindt'],
            'or':        ['Popular Live Video',                                    'ଏକ ଭିଡିଓ ଆପଣ ହୁଏତ ଲାଇକ୍ କରିପାରନ୍ତି'],
            'pa':        ['ਪ੍ਰਸਿੱਧ ਲਾਈਵ ਵੀਡੀਓਜ਼',                                      'ਕੋਈ ਵੀਡੀਓ ਜੋ ਸ਼ਾਇਦ ਤੁਹਾਨੂੰ ਪਸੰਦ ਹੋਵੇ'],
            'pl':        ['Popularna transmisja wideo na żywo',                    'Film, który może Ci się spodobać'],
            'pt':        ['Vídeo em direto popular', 'Vídeo ao vivo popular',      'Um vídeo de que talvez gostes', 'Um vídeo que você talvez curta'],
            'ru':        ['Популярный прямой эфир',                                'Вам может понравиться это видео'],
            'sa':        ['Popular Live Video',                                    'A Video You May Like'],
            'si':        ['Popular Live Video',                                    'ඔබ කැමති විය හැකි වීඩියෝවක්'],
            'so':        ['Popular Live Video',                                    'A Video You May Like'],
            'te':        ['ప్రసిద్ధ ప్రత్యక్ష ప్రసార వీడియో',                            'మీకు నచ్చే వీడియో'],
            'th':        ['Popular Live Video',                                    'วิดีโอที่คุณอาจจะถูกใจ'],
            'tr':        ['Popular Live Video',                                    'Hoşuna Gidebilecek Bir Video'],
            'uk':        ['Popular Live Video',                                    'Відео, яке може вам сподобатися'],
            'ur':        ['Popular Live Video',                                    'ویڈیو جو شائد آپ کو پسند آئے'],
            'vi':        ['Video trực tiếp phổ biến',                              'Một video bạn có thể thích',                                                     'Trang được đề xuất'],
            'zh-Hans':   ['热门直播视频',                                           '猜你喜欢'],
            'zh-Hant':   ['熱門直播視訊', '熱門直播視像',                            '你可能會喜歡的影片', '你可能會喜歡的影片']
        }
    }, {
      // Popular Across Facebook
        'selector': [
            '.fbUserPost > div > div > div',
            '.fbUserStory > div > div > div',
            '.fbUserContent > div > div > div'
        ],
        'content': {
            'af':        ['Oral op Facebook gewild'],
            'ar':        ['رائج على فيسبوك'],
            'az':        ['Feysbukda məşhur'],
            'bs':        ['Populer Lintas Facebook'],
            'ca':        ['Populer Lintas Facebook'],
            'cb':        ['Popular Across Facebook', '‎Popular Across Facebook‎'],
            'cs':        ['Populární na Facebooku'],
            'cx':        ['Sikat sa Kinatibuk-an sa Facebook'],
            'da':        ['Populært på Facebook'],
            'de':        ['Beliebt auf Facebook'],
            'en':        ['Popular Across Facebook'],
            'eo':        ['Popular Across Facebook'],
            'es':        ['Popular en Facebook'],
            'et':        ['Popular Across Facebook'],
            'eu':        ['Popular Across Facebook'],
            'fa':        ['داستان پرطرفدار در فیس‌بوک'],
            'fi':        ['Suosittua Facebookissa'],
            'fo':        ['Popular Across Facebook'],
            'fr':        ['Populaire sur Facebook'],
            'fy':        ['Popular Across Facebook'],
            'ga':        ['Popular Across Facebook'],
            'gl':        ['Popular Across Facebook'],
            'gn':        ['Ojehechavéva Facebook-pe'],
            'id':        ['Populer Lintas Facebook'],
            'it':        ['Popolare su Facebook'],
            'ja':        ['Facebookで人気'],
            'jv':        ['Populer Ing Facebook'],
            'ko':        ['Facebook에서 인기 있는 콘텐츠'],
            'ms':        ['Terkenal Diseluruh Facebook'],
            'pl':        ['Popularne na Facebooku'],
            'ps':        ['Popular Across Facebook', '‎Popular Across Facebook‎'],
            'pt':        ['Populares em todo o Facebook', 'Conteúdos populares no Facebook'],
            'nl':        ['Populair op Facebook'],
            'ru':        ['Популярно на Facebook'],
            'sv':        ['Populärt på Facebook'],
            'tl':        ['Sikat sa Facebook'],
            'ur':        ['پورے Facebook میں مقبول'],
            'vi':        ['Phổ biến trên Facebook'],
            'zh-Hans':   ['Facebook 大热门'],
            'zh-Hant':   ['廣受 Facebook 用戶歡迎']
        }
    }, {
        // Page Stories You May Like
        'selector': [
            'div[title] > div > div > div > div'
        ],
        'content': {
            'ar':        ['أحداث الصفحات التي قد تعجبك'],
            'cb':        ['سەرهاتەکانی پەڕە کە ڕەنگە بەدڵت بن'],
            'de':        ['Seitenmeldungen, die dir gefallen könnten'],
            'en':        ['Page Stories You May Like'],
            'es':        ['Historias de páginas que te pueden gustar'],
            'fa':        ['داستان‌های صفحه‌ای که شاید بپسندید'],
            'fr':        ['Actualités de Pages à voir'],
            'it':        ['Notizie interessanti delle Pagine che ti piacciono'],
            'ja':        ['おすすめのページストーリー'],
            'ko':        ['회원님이 좋아할 만한 페이지 소식'],
            'pl':        ['Zdarzenia stron, które mogą Ci się spodobać'],
            'pt':        ['Histórias da Página que você talvez curta'],
            'ru':        ['Новости Страниц, которые могут вам понравиться'],
            'tr':        ['Beğenebileceğin Sayfa Haberleri'],
            'ur':        ['صفحہ کی کہانیاں جو شاید آپ کو پسند آئیں'],
            'vi':        ['Tin bài bạn có thể thích'],
            'zh-Hans':   ['猜你喜欢'],
            'zh-Hant':   ['你可能會喜歡的粉絲專頁動態', '你可能會喜歡的專頁動態']
        }
    }, {
        // Suggestions From Related Pages
        'selector': [
            'div > div > span'
        ],
        'content': {
          'en':          ['Suggestions From Related Pages'],
          'vi':          ['Thêm đề xuất từ các Trang liên quan']
        }
    }];

    var language = document.documentElement.lang;
    var nodeContentKey = (('innerText' in document.documentElement) ? 'innerText' : 'textContent');
    var mutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

    // Default to 'en' when the current language isn't yet supported
    var i;
    for(i = 0; i < searchedNodes.length; i++) {
        if(searchedNodes[i].content[language]) {
            searchedNodes[i].content = searchedNodes[i].content[language];
        }
        else {
            searchedNodes[i].content = searchedNodes[i].content.en;
        }
    }

    var body;
    var stream;
    var observer;

    function block(story) {
        if(!story) {
            return;
        }

        story.remove();
    }

    function isSponsored(story) {
        if(!story) {
            return false;
        }

        var nodes;
        var nodeContent;

        var typeIterator;
        var selectorIterator;
        var nodeIterator;
        var targetIterator;
        for(typeIterator = 0; typeIterator < searchedNodes.length; typeIterator++) {
            for(selectorIterator = 0; selectorIterator < searchedNodes[typeIterator].selector.length; selectorIterator++) {
                nodes = story.querySelectorAll(searchedNodes[typeIterator].selector[selectorIterator]);
                for(nodeIterator = 0; nodeIterator < nodes.length; nodeIterator++) {
                    nodeContent = nodes[nodeIterator][nodeContentKey];
                    if(nodeContent) {
                        for(targetIterator = 0; targetIterator < searchedNodes[typeIterator].content.length; targetIterator++) {
                            if(searchedNodes[typeIterator].exclude && searchedNodes[typeIterator].exclude(nodes[nodeIterator])) {
                                continue;
                            }

                            if(nodeContent.trim() == searchedNodes[typeIterator].content[targetIterator]) {
                                return true;
                            }
                        }
                    }
                }
            }
        }

        return false;
    }

    function process() {
        // Locate the stream every iteration to allow for FB SPA navigation which
        // replaces the stream element
        stream = document.querySelector(streamSelector);
        if(!stream) {
            return;
        }

        var i;
        var j;
        var stories;
        for(i = 0; i < storySelectors.length; i++) {
            stories = stream.querySelectorAll(storySelectors[i]);
            if(!stories.length) {
                return;
            }

            for(j = 0; j < stories.length; j++) {
                if(isSponsored(stories[j])) {
                    block(stories[j]);
                }
            }
        }
    }

    if(mutationObserver) {
        body = document.querySelector('body');
        if(!body) {
            return;
        }

        observer = new mutationObserver(process);
        observer.observe(body, {
            'childList': true,
            'subtree': true
        });
    }
})();