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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
}