v2ex-helper

v2ex小助手

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         v2ex-helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description v2ex小助手
// @author       ycz0926
// @match        https://www.v2ex.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    /////////////////////////////////////////
    // 1、回到顶端按钮
    /////////////////////////////////////////
    document.body.innerHTML += '<a href="#" id="back-to-top">回到顶端</a>';
    var top_button = document.getElementById('back-to-top');

    //为按钮添加css样式
    top_button.style.position = 'fixed';
    top_button.style.bottom = '3em';
    top_button.style.right = '3em';
    top_button.style.textDecoration = 'none';
    top_button.style.color = '#EEEEEE';
    top_button.style.backgroundColor = 'rgba(0, 0, 0, 0.3)';
    top_button.style.fontSize = '12px';
    top_button.style.padding = '1em';
    top_button.style.display = 'none';
    top_button.style.borderRadius = '3px';
    top_button.style.border = '1px solid #CCCCCC';

    // 滚动窗口来判断按钮显示或隐藏
    window.addEventListener('scroll', function () {
        if (window.scrollY > 1000) {
            document.getElementById('back-to-top').style.display = 'block';
        } else {
            document.getElementById('back-to-top').style.display = 'none';
        }
    });

    // 点击回到顶部
    document.getElementById('back-to-top').addEventListener('click', function (event) {
        event.preventDefault();

        window.scrollTo(0, 0);
        setTimeout(function () {
            document.getElementById('back-to-top').style.display = 'none';
        }, 100);
    });

    /////////////////////////////////////////
    // 2、新标签页打开帖子
    /////////////////////////////////////////
    document.body.addEventListener('mousedown', function (e) {
        var a = e.target;
        var parent = a.parentElement;
        if (parent.className !== 'item_title') return;
        a.target = '_blank';
    });

    /////////////////////////////////////////
    // 3、高亮作者回复
    /////////////////////////////////////////
    var author = document.getElementsByClassName('header')[0].children[0].children[0].getAttribute('href');
    var all_cell_div = document.getElementsByClassName('cell');

    for (var i in all_cell_div) {
        if (all_cell_div[i].id !== "") {
            try {
                var href = all_cell_div[i].children[0].children[0].children[0].children[2].children[2].children[0].getAttribute('href');
                var box = all_cell_div[i].children[0].children[0].children[0].children[2];
                if (author == href) {
                    box.style.backgroundColor = 'rgb(250, 255, 189)';
                }
            } catch (e) {
                //console.log(e);
                continue;
            }
        }
    }
})();