V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
samtoto
V2EX  ›  分享发现

v2ex 的下一主题

  •  
  •   samtoto · 2016-10-25 16:06:38 +08:00 · 36437 次点击
    这是一个创建于 2748 天前的主题,其中的信息可能已经有所发展或是发生改变。

    复制以下代码到 chrome 的 console 。高手勿喷,插件勿喷。

    window.location.href = 'https://www.v2ex.com/t/' + (Number(document.location.href.replace(/https:\/\/www\.v2ex\.com\/t\/(\d?)/i, '$1'))+1)
    
    第 1 条附言  ·  2016-10-25 16:42:40 +08:00

    回复里有大神,学习他们的,所以也可以用

    location.pathname.substring()
    
    19 条回复    2016-10-29 10:43:25 +08:00
    yhxx
        1
    yhxx  
       2016-10-25 16:17:04 +08:00
    Number('$1') 是想做什么
    yhxx
        2
    yhxx  
       2016-10-25 16:19:29 +08:00
    哦看错了
    还以为是有一个新的“ theme ”
    timor
        3
    timor  
       2016-10-25 16:21:44 +08:00
    404 错误.
    samtoto
        4
    samtoto  
    OP
       2016-10-25 16:24:21 +08:00
    @yhxx Number 是 js 里的将 string 转为 数字
    $1 是字符转换的时候的正则表达式里的
    分开写是
    ```javascript
    var urlBase = 'https://www.v2ex.com/t/';
    var urlNow = document.location.href;
    var nextNum = Number(urlNow.replace(/https:\/\/www\.v2ex\.com\/t\/(\d?)/i, '$1')) + 1;
    var url = urlBase + nextNum;
    window.location.href = url
    ```
    samtoto
        5
    samtoto  
    OP
       2016-10-25 16:25:29 +08:00
    @timor 哦哦 因为没有下一个主题了,你可以找一个老一点的主题比如: https://www.v2ex.com/t/1 在这个页面试试。
    samtoto
        6
    samtoto  
    OP
       2016-10-25 16:26:16 +08:00
    其实就是想骗点铜币而已,(逃
    ahu
        7
    ahu  
       2016-10-25 16:27:57 +08:00
    404: Not Found
    dofy
        8
    dofy  
       2016-10-25 16:28:14 +08:00
    简单点可以直接操作 location.pathname
    samtoto
        9
    samtoto  
    OP
       2016-10-25 16:29:10 +08:00
    @dofy 确实!不是前端 js 不熟 哈哈哈哈哈哈!
    samtoto
        10
    samtoto  
    OP
       2016-10-25 16:29:28 +08:00
    @ahu 见 5L
    yhxx
        11
    yhxx  
       2016-10-25 16:37:31 +08:00
    格式这么固定
    'www.v2ex.com/t/'+ (window.location.href.substring(23,29) * 1 + 1)
    这样就行了吧
    samtoto
        12
    samtoto  
    OP
       2016-10-25 16:40:36 +08:00
    @yhxx 这个是玉!不错学习了!!!
    imgalaxy
        13
    imgalaxy  
       2016-10-25 17:49:54 +08:00
    location.pathname="/t/"+(location.href.split(/[/#]/)[4]-(-1))
    imgalaxy
        14
    imgalaxy  
       2016-10-25 17:51:49 +08:00
    第二个 pathname 换成 href 还能再短 4 个字符
    samtoto
        15
    samtoto  
    OP
       2016-10-25 17:53:50 +08:00 via iPhone
    @imgalaxy 嗯嗯,受教了
    imgalaxy
        16
    imgalaxy  
       2016-10-25 18:14:24 +08:00
    location.href=location.href.split(/[/#]/)[4]*1+1
    最终版 不摸鱼了 继续写代码
    tpsxiong
        17
    tpsxiong  
       2016-10-26 07:29:02 +08:00 via iPhone
    。。为啥不手动改地址栏?
    samtoto
        18
    samtoto  
    OP
       2016-10-26 08:25:51 +08:00
    @tpsxiong 就是一时兴起 ^_^
    mingyun
        19
    mingyun  
       2016-10-29 10:43:25 +08:00
    @imgalaxy 厉害了我的哥
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2627 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:48 · PVG 21:48 · LAX 06:48 · JFK 09:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.