Greasy Fork

Guardian Anti-Jock

Remove sports stories from the Guardian frontpage, as well as links to the sports sections. This requires that you use what is currently (Jun 2014) the "beta" version of the Guardian, although this will presumably one day become the main version.

目前为 2014-06-16 提交的版本。查看 最新版本

// ==UserScript==
// @name        Guardian Anti-Jock
// @namespace   http://xyxyx.org/
// @include     http://www.theguardian.com/*
// @version     0.2
// @description Remove sports stories from the Guardian frontpage, as well as links to the sports sections.  This requires that you use what is currently (Jun 2014) the "beta" version of the Guardian, although this will presumably one day become the main version.
// @grant       none
// ==/UserScript==

function getSection(sectionName) {
	var sections = document.getElementsByTagName("section");
	for (var i = 0; i < sections.length; i++) {
		if (sections.item(i).attributes.getNamedItem("data-component").value === sectionName) {
			return sections.item(i);
		}
	}
}

function getNavItem(name) {
	var navItems = document.getElementsByClassName("nav__item");
	for (var i = 0; i < navItems.length; i++) {
		var navItem = navItems.item(i);
		var link = navItem.children.item(0);
		if( link.attributes.getNamedItem('data-link-name').value === name) {
			navItem.parentNode.removeChild(navItem);
		}
	}
}

function removeFrontPageStory(pattern) {
        var frontPageItems = document.getElementsByClassName("item__container");
    for (var i = 0; i < frontPageItems.length; i++) {
        var frontPageItem = frontPageItems.item(i);
        var link = frontPageItem.children.item(0).href;
        if (link.match(pattern)) {
            console.log("Matches " + link + ":" + link)
            var container = frontPageItem.parentNode.parentNode;
            console.log("Container = " + container);    
            container.parentNode.removeChild(container);
        }
        
    }
}

try {
	var section;

	section = getSection('sport');
	if (section) {
		section.style.visibility = 'hidden';
	}

	section = getSection('world-cup');
	if (section) {
		section.style.visibility = 'hidden';
	}

	var navItem = getNavItem("/sport");
	if (navItem) {
		navItem.style.visibility = 'hidden';
	}
	
	var navItem = getNavItem("/football");
	if (navItem) {
		navItem.style.visibility = 'hidden';
	}
	
	var navItem = getNavItem("/fashion");
	if (navItem) {
		navItem.style.visibility = 'hidden';
	}
	
    removeFrontPageStory(/\/football\//);
    removeFrontPageStory(/\/sport\//);
    

    
} catch (e) {
	console.log(e);
}