V2EX.js

V2EX助手

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         V2EX.js
// @namespace    https://github.com/zhihaofans
// @version      0.6.2
// @description  V2EX助手
// @author       zhihaofans
// @match        https://www.v2ex.com/*
// @match        https://v2ex.com/*
// @grant        none
// @icon         https://www.v2ex.com/static/img/icon_rayps_64.png
// ==/UserScript==
$(document).ready(function() {
    //搜索改为百度
    $("#Search form").submit(function() {
        var q = $("#q");
        if (q.val() !== "") {
            var url = "https://www.baidu.com/s?wd=site:v2ex.com%20" + q.val();
            if (navigator.userAgent.indexOf('iPad') > -1 || navigator.userAgent.indexOf('iPod') > -1 || navigator.userAgent.indexOf('iPhone') > -1) {
                location.href = url;
            } else {
                window.open(url, "_blank");
            }
            return false;
        } else {
            return false;
        }
    });
    var nowurl = location.pathname;
    //超链接改为新标签打开
    if (nowurl == "/" || nowurl.substr(0, 6) == "/?tab=" || nowurl.substr(0, 4) == "/go/" || nowurl == "/recent") {
        $("span.item_title a").attr("target", "_blank");
    }
    //楼主标记
    if (nowurl.substr(0, 3) == "/t/") {
        $("a[rel=nofollow]").attr("target", "_blank");
        $(".inner a").attr("target", "_blank");
        $(".inner:first a").removeAttr("target");
        var lzname = $(".header .gray a").text();
        var replynum = $("div.cell[id^=r_] strong a").length;
        for (var aa = 0; aa < replynum; aa++) {
            // console.log($("div.cell[id^=r_]:eq("+aa+") strong a").text());
            if ($("div.cell[id^=r_]:eq(" + aa + ") strong a").text() == lzname) {
                $("div.cell[id^=r_]:eq(" + aa + ") strong").html($("div.cell[id^=r_]:eq(" + aa + ") strong").html() + "&nbsp;[楼主]");
            }
        }
    }
    //屏蔽右侧广告
    $("#Rightbar .box .sidebar_compliance").parent().hide();
    //原搜索删除
    $("#Search form").removeAttr("onsubmit");
});