V2EX打开新帖跳到第一页

V2EX打开新帖跳到第一页;翻页在当前页面打开

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           V2EX打开新帖跳到第一页
// @description    V2EX打开新帖跳到第一页;翻页在当前页面打开
// @author         ss
// @include        https://*.v2ex.com/*
// @include        https://v2ex.com/*
// @version        2021.11.30
// @grant        none
// @namespace https://greasyfork.org/users/314878
// ==/UserScript==

(function(){
    var topicLinks = document.getElementsByClassName('topic-link');
    var linksHot = document.querySelectorAll(".item_hot_topic_title a")
    if (topicLinks.length) {
        for (var i=0; i<topicLinks.length; i++) {
            topicLinks[i].href = topicLinks[i].href.split('#')[0] + '?p=1';
        }
    }
    if (linksHot.length) {
        for (var i=0; i<linksHot.length; i++) {
            linksHot[i].href = linksHot[i].href.split('#')[0] + '?p=1';
        }
    }
    const pages = document.getElementsByClassName('page_normal')
    for (let i = 0; i < pages.length; i++) {
        pages[i].target = "_self"
    }
})()