ZeroCruft

Removes the cruft from the new zerohedge

当前为 2016-07-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           ZeroCruft
// @version        1.1
// @namespace      1bae28cfed0eddb302b3ac9b578412a3
// @author         Dan Garthwaite <[email protected]>
// @description    Removes the cruft from the new zerohedge
// @include        http://*zerohedge.com/*
// @run-at         document-end
// ==/UserScript==

(function() {
    'use strict';
    var page = document.getElementById('page');
    var sidebarLeft = document.getElementById('sidebar-left');
    var sidebarRight = document.getElementById('sidebar-right');

    page.style.maxWidth = "80em";
    page.style.marginLeft = page.style.marginRight = "auto";
    sidebarLeft.remove();
    sidebarRight.remove();

    var jk = function(a, inc) {
        if (!a.length) { return; }
        for (var i = 0; i < a.length; i++) {
            if (a[i].classList.contains('jk-current')) {
                var next = (i + inc) % a.length;
                a[i].classList.toggle('jk-current');
                a[next].classList.toggle('jk-current');
                break;
            }
        }
    };

    /* Do jk navigation */
    $('head').append('<style>.jk-current {outline: 1px solid navy;}</style>');
    var arts = document.getElementsByTagName("article");
    if (arts.length > 3) {
        arts[2].classList.add('jk-current');
        jk(arts, 1);
    }
    $(document.body).keypress(function (event) {
        // ignore keypresses in input fields
        if (document.activeElement.tagName == 'INPUT') {
            return;
        }

        if (arts.length === 0) {
            return;
        }

        var key = String.fromCharCode(event.which).toUpperCase();

        if (key === 'J' || key === ' ') { // J or space for next
            jk(arts, 1);
        } else if (key == 'K') { // K for back
            jk(arts, -1);
        } else if (key == 'O' || event.which == 13) {
            var toClick = $(".jk-current").find('a')[0];
            console.log("toClick = " + toClick);
            toClick.click();
        } else {
            return;
        }

        //scroll .jk-current to top of window
        $('html, body').animate({
            scrollTop: $(".jk-current").offset().top - 100
        }, 200);
    });
})();