├── manifest.json └── script.js /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Clickbait Stopper", 3 | "description": "Grrrr", 4 | "version": "1.0", 5 | "content_scripts": [ 6 | { 7 | "matches": [""], 8 | "js": ["script.js"] 9 | } 10 | ], 11 | "manifest_version": 2 12 | } 13 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | // create a baitlist to check our page content against 2 | const list = [ 3 | /^\d+ (\w+ )?(animals|pictures|lessons|movies|secrets|shows|stories|things|times|trailers|tumblr|tweets)/i, 4 | /^\d+ of the \w+est/i, 5 | /^can you/i, 6 | /^here['’]s (how|what)/i, 7 | /^this could/i, 8 | /all (he|she|they) did was/i, 9 | /all the best/i, 10 | /best comeback/i, 11 | /can['’]t handle/i, 12 | /can teach us about/i, 13 | /didn['’]t know what/i, 14 | /get rid of/i, 15 | /how one (man|woman)/i, 16 | /how \w+ are you/i, 17 | /may affect/i, 18 | /never realized/i, 19 | /(pictures|photos) of/i, 20 | /secret of/i, 21 | /signs you['’]?re/i, 22 | /somebody needs to/i, 23 | /things that will/i, 24 | /trump/i, 25 | /until you see/i, 26 | /you (need to|should) (know|watch)/i, 27 | /we bet you can/i, 28 | /we can (tell|guess) (what )?your/i, 29 | /we need to talk about/i, 30 | /what could possibly/i, 31 | /what happens/i, 32 | /what (he|she|they) found/i, 33 | /what I learned about/i, 34 | /what this/i, 35 | /what to expect/i, 36 | /when (he|she|they)/i, 37 | /when this (man|woman|baby|child|puppy|dog|kitten)/i, 38 | /when you read these/i, 39 | /who['’]d thougt/i, 40 | /why we really shouldn['’]?t/i, 41 | /with this one/i, 42 | /will never tell/i, 43 | /won['’]?t believe/i, 44 | /\s(celebrit|epic|fantastic|genius|heartbreaking|incredibl|powerful|shocking|teen|terribl|unusual|weirdly)/i 45 | ]; 46 | 47 | // function to compare string to our baitlist. 48 | function isClickbait( string ) { 49 | // is the string short than 20 or longer than 100 characters? Probably not a title. 50 | if ( string.length < 20 || string.length > 100 ) return false; 51 | // it is? let's compare it to our baitlist 52 | return list.some( function ( clickbait, i ) { 53 | // if it matches, log the offending string to the console and return it to our strike function 54 | if ( clickbait.test( string ) ) { 55 | 56 | console.log( i, string ); 57 | return true; 58 | 59 | } 60 | 61 | } ); 62 | 63 | } 64 | 65 | // found some clickbait? Let's strike it through 66 | function strikeIfClickbait( element ) { 67 | 68 | if ( isClickbait( element.textContent.trim() ) ) { 69 | 70 | element.style.textDecoration = 'line-through'; 71 | 72 | } 73 | 74 | } 75 | 76 | 77 | function strikeClickbaitLinks( element ) { 78 | 79 | const elements = element.getElementsByTagName( 'a' ); 80 | [ ...elements ].forEach( strikeIfClickbait ); 81 | 82 | } 83 | 84 | function initObserver() { 85 | 86 | const observer = new MutationObserver( function ( mutations ) { 87 | 88 | mutations.forEach( function ( mutation ) { 89 | 90 | mutation.addedNodes.forEach( function ( node ) { 91 | 92 | if ( node.nodeType === Node.ELEMENT_NODE ) strikeClickbaitLinks( node ); 93 | 94 | } ); 95 | 96 | } ); 97 | 98 | } ); 99 | 100 | observer.observe( document.body, { childList: true, subtree: true } ); 101 | 102 | } 103 | 104 | strikeClickbaitLinks( document.body ); 105 | // invoke the initObserver function to start the checking process 106 | initObserver(); 107 | --------------------------------------------------------------------------------