Skip to content

Instantly share code, notes, and snippets.

@elebetsamer
Last active March 31, 2018 05:38
Show Gist options
  • Select an option

  • Save elebetsamer/dd719bbde83a9c54d609fd8b5d8ef6e8 to your computer and use it in GitHub Desktop.

Select an option

Save elebetsamer/dd719bbde83a9c54d609fd8b5d8ef6e8 to your computer and use it in GitHub Desktop.

Revisions

  1. elebetsamer revised this gist Mar 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion yahoo-block-news.user.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    // @grant none
    // ==/UserScript==

    // For a screen shot with some notes, view here: https://user-images.githubusercontent.com/75610/38160011-56f5c556-346a-11e8-84d1-e451ec3fb234.png
    // For a screen shot with some notes, view here: https://user-images.githubusercontent.com/75610/38160042-eb867558-346a-11e8-8729-d36bcdb784f7.png

    // How often do you want to remove blocked articles
    var intervalSeconds = 5;
  2. elebetsamer revised this gist Mar 31, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion yahoo-block-news.user.js
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,27 @@
    // ==UserScript==
    // @name Remove yahoo.com news articles
    // @namespace https://github.com/elebetsamer
    // @version 0.2
    // @version 0.3
    // @description Remove unwanted news articles from the yahoo.com home page. You can set categories to block or sources.
    // @author elebetsamer
    // @match http*://*.yahoo.com
    // @icon https://mbp.yimg.com/sy/rz/l/favicon.ico
    // @grant none
    // ==/UserScript==

    // For a screen shot with some notes, view here: https://user-images.githubusercontent.com/75610/38160011-56f5c556-346a-11e8-84d1-e451ec3fb234.png

    // How often do you want to remove blocked articles
    var intervalSeconds = 5;

    // List the categories you want blocked
    // example: ['Celebrity', 'Lifestyle', 'Style']
    // example (if you don't want to block any categories): []
    var blockedCategories = ['Celebrity', 'Lifestyle', 'Style'];

    // List the news sources you want blocked
    // example: ['Yahoo Lifestyle', 'Esquire']
    // example (if you don't want to block any article sources): []
    var blockedSources = ['Yahoo Lifestyle', 'Esquire'];

    var styleRules = [];
  3. elebetsamer revised this gist Mar 31, 2018. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions yahoo-block-news.user.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    // ==UserScript==
    // @name Remove yahoo.com news articles
    // @namespace https://github.com/elebetsamer
    // @version 0.1
    // @version 0.2
    // @description Remove unwanted news articles from the yahoo.com home page. You can set categories to block or sources.
    // @author elebetsamer
    // @include http*://*.yahoo.com
    // @match http*://*.yahoo.com
    // @icon https://mbp.yimg.com/sy/rz/l/favicon.ico
    // @grant none
    // ==/UserScript==
    @@ -26,7 +26,7 @@ var styleRules = [];
    styleRules.push('li.js-stream-ad {display: none;}');

    applyStyles();
    setInterval(removeNews, (intervalSeconds * 1000));
    removeNews();

    function applyStyles() {
    if (!document.getElementById('custom-yahoo-styles')) {
    @@ -71,4 +71,6 @@ function removeNews() {
    }
    }
    });

    setTimeout(removeNews, (intervalSeconds * 1000));
    }
  4. elebetsamer created this gist Mar 31, 2018.
    74 changes: 74 additions & 0 deletions yahoo-block-news.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    // ==UserScript==
    // @name Remove yahoo.com news articles
    // @namespace https://github.com/elebetsamer
    // @version 0.1
    // @description Remove unwanted news articles from the yahoo.com home page. You can set categories to block or sources.
    // @author elebetsamer
    // @include http*://*.yahoo.com
    // @icon https://mbp.yimg.com/sy/rz/l/favicon.ico
    // @grant none
    // ==/UserScript==

    // How often do you want to remove blocked articles
    var intervalSeconds = 5;

    // List the categories you want blocked
    // example: ['Celebrity', 'Lifestyle', 'Style']
    var blockedCategories = ['Celebrity', 'Lifestyle', 'Style'];

    // List the news sources you want blocked
    // example: ['Yahoo Lifestyle', 'Esquire']
    var blockedSources = ['Yahoo Lifestyle', 'Esquire'];

    var styleRules = [];

    // Hide the "Sponsored" news
    styleRules.push('li.js-stream-ad {display: none;}');

    applyStyles();
    setInterval(removeNews, (intervalSeconds * 1000));

    function applyStyles() {
    if (!document.getElementById('custom-yahoo-styles')) {
    // An element where we can put in custom styles
    const styles = document.createElement('style');

    styles.id = 'custom-yahoo-styles';

    // Set the content for our style element
    styles.textContent = styleRules.join();

    // Add the style element to the page
    document.body.append(styles);

    console.info('The custom styles were added to the page.');
    }
    }

    function removeNews() {
    const items = document.querySelectorAll('.js-applet-view-container-main .js-stream-content');

    console.info('Running removeNews function');

    items.forEach(element => {
    const headlineCategoryElement = element.querySelector('.strm-headline-label span, .js-content-label span');
    const headlineSourceElement = element.querySelector('.strm-headline-label span + span, .js-content-label span + span');
    const headlineTitleElement = element.querySelector('.js-stream-item-title span');

    if (headlineCategoryElement && headlineSourceElement && headlineTitleElement) {
    const articleCategory = headlineCategoryElement.textContent.trim();
    const articleSource = headlineSourceElement.textContent.trim();
    const articleTitle = headlineTitleElement.textContent.trim();
    const isBlockedCategory = blockedCategories.indexOf(articleCategory) != -1;
    const isBlockedSource = blockedSources.indexOf(articleSource) != -1;

    if (isBlockedCategory) {
    element.remove();
    console.info(`Removed a news item because it matched a blocked category. Category: "${articleCategory}"; Article: "${articleTitle}"`);
    } else if (isBlockedSource) {
    element.remove();
    console.info(`Removed a news item because it matched a blocked source. Source: "${articleSource}"; Article: "${articleTitle}"`);
    }
    }
    });
    }