Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修改Stumbleupon URL';并提供到内容页的直接链接?_Javascript_Url_Google Chrome_Userscripts_Stumbleupon - Fatal编程技术网

Javascript 如何修改Stumbleupon URL';并提供到内容页的直接链接?

Javascript 如何修改Stumbleupon URL';并提供到内容页的直接链接?,javascript,url,google-chrome,userscripts,stumbleupon,Javascript,Url,Google Chrome,Userscripts,Stumbleupon,这个问题是针对所有狂热的绊脚石,在那里。。。 当遇到障碍时,URL会被修改为如下所示。正如您所看到的,所有原始内容前面都有 http://www.stumbleupon.com/su/...之后是直接URL 如果我遇到一些有趣的事情,我喜欢通过复制URL并将其粘贴到任何需要的地方来分享。问题是,当任何人点击它时,它会为他们打开stumblebar并将他们带到内容中。我宁愿只有直接的联系 http://www.stumbleupon.com/su/1NKFju/:10yM7NnNO:GEYExz6

这个问题是针对所有狂热的绊脚石,在那里。。。 当遇到障碍时,URL会被修改为如下所示。正如您所看到的,所有原始内容前面都有
http://www.stumbleupon.com/su/...
之后是直接URL

如果我遇到一些有趣的事情,我喜欢通过复制URL并将其粘贴到任何需要的地方来分享。问题是,当任何人点击它时,它会为他们打开stumblebar并将他们带到内容中。我宁愿只有直接的联系

http://www.stumbleupon.com/su/1NKFju/:10yM7NnNO:GEYExz6R/toti.jjsoft.hu/public8/nyar1779/a28.jpg
http://www.stumbleupon.com/su/1uGF9s/:11Sd-1n0R:GEYExz6R/www.popularmechanics.com/technology/how-to/home-theater/4342672/
http://www.stumbleupon.com/su/237YPB/:GdOWpKe.:GEYExz6R/nerdsguidetoreading.com/Nerds_Guide_to_Reading/Science_Fiction.html/
http://www.stumbleupon.com/su/2pkYws/:1f+I-KON5:GEYExz6R/www.wizards.com/dnd/images/wd_maps/FRposterLarge_150.jpg/
http://www.stumbleupon.com/su/1ceVWt/:1fdJgD$uT:GEYExz6R/www.psych.upenn.edu/~andrewbg/images/Bluebell-carpet-480.jpg/
http://www.stumbleupon.com/su/2DdDRI/:GvgBVfdV:M-wRpADk/www.nature.com/news/higgs-triumph-opens-up-field-of-dreams-1.10970/
正如你所看到的,前面大多数stumble行话的长度几乎相同。但是,第三个和最后一个字符短1个字符

我想知道是否可以编写一个用户脚本,在每次我跌跌撞撞地进入一个新页面时,将跌跌撞撞的内容去掉,只留下直接链接


我想保留StumbleBar,但是当我到达我新的StumblePage时,编辑URL并删除它,而不是实际重新加载页面

由于Stumbleupon URL字段由固定数量的斜杠(/)分隔,因此可以使用正则表达式获取URL,如下所示:

var targURL = location.href.replace (
    /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
    , "http://$1"
);

堆栈溢出不是(通常)脚本编写服务,但我毫不费力地修改了一个现有脚本,它似乎可以工作

更新:以下是一个Greasemonkey脚本,因为这是问题最初指定的内容。要在Chrome中使用它,请安装Tampermonkey扩展

// ==UserScript==
// @name     _Stumbleupon, add direct link to content page
// @include  http://www.stumbleupon.com/su/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==

$("#tb-like").before ( '                                                    \
    <li id      = "gmDirectLinkDisp"                                        \
        class   = "tb-btn tb-hide-visitor"                                  \
        title   = "Click for the direct link to the target page, below."    \
    >                                                                       \
        <button>Direct link</button>                                        \
    </li>                                                                   \
' );

$("#gmDirectLinkDisp button").click ( function () {
    var targURL = location.href.replace (
        /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
        , "http://$1"
    );
    window.prompt (
        "Press 'Ctrl+C' to copy to the clipboard; "
        + "then press `Enter` to close this dialog."
        , targURL
    );
} );

GM_addStyle ( "                             \
    #gmDirectLinkDisp {                     \
        float:              left;           \
    }                                       \
    #gmDirectLinkDisp button {              \
        padding:            0;              \
        margin-top:         10px;           \
    }                                       \
" );
/==UserScript==
//@name\u Stumbleupon,添加到内容页的直接链接
//@包括http://www.stumbleupon.com/su/*
//@需要http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
//@grant GM_addStyle
//==/UserScript==
美元(“#tb样”)。之前('\
  • \ 直接链接\
  • \ ' ); $(“#gmDirectLinkDisp按钮”)。单击(函数(){ var targURL=location.href.replace( /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i ,“http://$1” ); window.prompt( “按“Ctrl+C”复制到剪贴板;” +“然后按'Enter'关闭此对话框。” ,targURL ); } ); GM_addStyle(“\ #gmDirectLinkDisp{\ 浮动:左\ } \ #gmDirectLinkDisp按钮{\ 填充:0\ 边缘顶部:10px\ } \ " );
    由于Stumbleupon URL字段由固定数量的斜杠(/)分隔,因此可以使用正则表达式获取URL,如下所示:

    var targURL = location.href.replace (
        /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
        , "http://$1"
    );
    

    堆栈溢出不是(通常)脚本编写服务,但我毫不费力地修改了一个现有脚本,它似乎可以工作

    更新:以下是一个Greasemonkey脚本,因为这是问题最初指定的内容。要在Chrome中使用它,请安装Tampermonkey扩展

    // ==UserScript==
    // @name     _Stumbleupon, add direct link to content page
    // @include  http://www.stumbleupon.com/su/*
    // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    // @grant    GM_addStyle
    // ==/UserScript==
    
    $("#tb-like").before ( '                                                    \
        <li id      = "gmDirectLinkDisp"                                        \
            class   = "tb-btn tb-hide-visitor"                                  \
            title   = "Click for the direct link to the target page, below."    \
        >                                                                       \
            <button>Direct link</button>                                        \
        </li>                                                                   \
    ' );
    
    $("#gmDirectLinkDisp button").click ( function () {
        var targURL = location.href.replace (
            /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
            , "http://$1"
        );
        window.prompt (
            "Press 'Ctrl+C' to copy to the clipboard; "
            + "then press `Enter` to close this dialog."
            , targURL
        );
    } );
    
    GM_addStyle ( "                             \
        #gmDirectLinkDisp {                     \
            float:              left;           \
        }                                       \
        #gmDirectLinkDisp button {              \
            padding:            0;              \
            margin-top:         10px;           \
        }                                       \
    " );
    
    /==UserScript==
    //@name\u Stumbleupon,添加到内容页的直接链接
    //@包括http://www.stumbleupon.com/su/*
    //@需要http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    //@grant GM_addStyle
    //==/UserScript==
    美元(“#tb样”)。之前('\
    
  • \ 直接链接\
  • \ ' ); $(“#gmDirectLinkDisp按钮”)。单击(函数(){ var targURL=location.href.replace( /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i ,“http://$1” ); window.prompt( “按“Ctrl+C”复制到剪贴板;” +“然后按'Enter'关闭此对话框。” ,targURL ); } ); GM_addStyle(“\ #gmDirectLinkDisp{\ 浮动:左\ } \ #gmDirectLinkDisp按钮{\ 填充:0\ 边缘顶部:10px\ } \ " );
    使用StumbleUpon Firefox扩展,您将直接被绊倒到URL,而不是它的框架版本。地址栏中显示的URL前面不会有stumbleupon.com/su/xxxx

    使用StumbleUpon Firefox扩展,您将直接进入URL,而不是它的框架版本。地址栏中显示的URL前面不会有stumbleupon.com/su/xxxx

    谢谢你的回复。我对/characters也有同样的想法,但我没有javascript背景,所以我一直在努力解决其余的问题。从表面上看,这比我原先想象的要困难得多。我安装了这个脚本,但对我来说,它不能在Windows或Ubuntu上运行。铬v。21.0.1180.60这个问题被标记为“Greasemonkey”,意思是Firefox,没有提到Chrome。这个