在新标签页中打开链接 - greasemonkey脚本

时间:2014-12-30 07:47:43

标签: html greasemonkey

我在网上找到了一个greasemonkey脚本,用于在新标签页面中打开网页上的所有链接。我想要做的是编辑它,以便它只打开包含单词forum的特定链接。

这是我目前使用的脚本:

 javascript: (function () {
     {
         var links = document.getElementsByTagName('a');
         for (i in links) {
             window.open(links[i].href);
         }
     }
 })()

如何编辑它以做我想做的事?

3 个答案:

答案 0 :(得分:55)

该脚本完美地适用于Greasemonkey,尽管有很多可以删除的括号。这是我使用的版本:

(function(){
        var links = document.getElementsByTagName('a');
        for (i in links){
            var href = links[i].href;
            if(href.toLowerCase().indexOf('forum') > 0){
               window.open(links[i].href);
            }
        }
    })();

你确定它不起作用吗?可能是您的浏览器只是妨碍了弹出窗口。


关于此的交换意见被取消了,所以为了清楚起见:

OP发现了一个greasemonkey脚本,在Firefox中为所选网页上的每个href打开了一个新标签。

然后他解释说他想要添加一个过滤器,只会打开包含所选关键字的href的标签(在这种情况下,关键字是'论坛')。 我添加了额外的一行来做这件事,这显然是令人满意的。

答案 1 :(得分:9)

另一种方法是查询每个锚标记,将它们放在一个数组中(与nodelist相对),然后使用过滤器在新窗口中有条件地打开它们。

[].forEach.call(document.querySelectorAll('a'),function(el){ if(el.href.toLowerCase().indexOf('forum') > -1) window.open(el.href) })

或者以更易读的形式

[].forEach.call(//access array's prototype to call forEach on
 document.querySelectorAll('a')//the nodelist result of all anchor elements
 ,function(el){ //then use that result to iterate through
  if( el.href.toLowerCase().indexOf('forum') > -1 )//check whether or not 'forum' exists
   window.open(el.href) //and if it does open a new tab with the anchors href
})

一些参考文献

答案 2 :(得分:-1)

要测试包含单词df <- data.frame("a"=c(1,2,3),"b"=c(4,5,6),"c"=c(7,8,9)) label(df[,"a"]) <- "my_a" label(df[,"b"]) <- "my_b" label(df[,"c"]) <- "my_c" ui <- pageWithSidebar( # App title ---- headerPanel("TEST"), # Sidebar panel for inputs ---- sidebarPanel(), # Main panel for displaying outputs ---- mainPanel( tableOutput("base") ) ) server <- function(output,input){ output$base <- renderTable(print(df)) } shinyApp(ui=ui,server=server) 的链接,您可以使用正则表达式。因此代码是:

forum

我编写了用户脚本,用于在新标签页的任何页面上打开外部链接 它具有排除父,邻居和子站点链接的设置 也许这个脚本或其代码会很有用 它可以从这个回购中安装:




通过直接链接 External link newtaber

相关问题