如何更改 mIRC 中链接的颜色?

发布于 2024-10-15 05:44:01 字数 89 浏览 10 评论 0原文

在 mIRC 中,我希望所有链接看起来都像 html 链接(带有下划线的蓝色),以便它们在频道和消息中突出显示。我确信我必须编写一个远程脚本,但我不确定代码是什么。

In mIRC I want all links to look like html links (blue with an underline) so they stick out in channels and messages. I'm sure I have to write a remote script but I'm not sure what the code would be.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

说谎友 2024-10-22 05:44:01

更新:这适用于文本中匹配的第一个 URL。我无法完全让它与多个链接一起工作。

请注意,修改通道输出有几个副作用,最值得注意的是多个空格将被压缩为一个(类似于 HTML 中空格的处理方式)。如果您使用任何其他修改通道输出的脚本,这可能会干扰甚至覆盖这些脚本。

我之前没有处理过 mIRC 的 RegEx 函数,因此可能有一种更简洁的方法:

on ^*:TEXT:*:#:{
  set -u %tmp.match /((ht|f)tp[s]?:\S+)/i
  if ($regex(links, $1-, %tmp.match) > 0) {
    set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
    echo $timestamp $chan < $+ $nick $+ > %tmp.text
    halt
  }
}

注释: set -u 在脚本运行后删除变量,< code>$chr(3) 是颜色的控制代码,12 是 URL 蓝色的颜色编号,$chr(31) 是控制下划线代码。

Update: This works on the first URL matched in the text. I couldn't quite get it working with multiple links.

Please note that modifying channel output has several side-effects, most notably is that multiple spaces will be condensed to one (similar to how whitespace is treated in HTML). If you are using any other scripts that modify channel output, this may interfere or even override those scripts.

I haven't dealt with mIRC's RegEx functions before, so there may be a cleaner way of doing this:

on ^*:TEXT:*:#:{
  set -u %tmp.match /((ht|f)tp[s]?:\S+)/i
  if ($regex(links, $1-, %tmp.match) > 0) {
    set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
    echo $timestamp $chan < $+ $nick $+ > %tmp.text
    halt
  }
}

Notes: set -u deletes the variable after the script runs, $chr(3) is the Control Code for Color, 12 is the Color Number for URL Blue, and $chr(31) is the Control Code for Underline.

蘑菇王子 2024-10-22 05:44:01

mIRC“捕手”遵循以下规则:

来自帮助文件(/help catcher):

mIRC 查找以“http://”、“ftp://”、“gopher://”、“www.”和“ftp.”开头的 URL。 mIRC 还会检查以确保地址不会添加到已存在的列表中。超过 256 个字符的地址将被忽略。

正如另一个答案中所述,修改默认行为将导致间距压缩效果,但对于此脚本来说应该不会有太大问题,因为它只会在显示 URL 时触发。 (此外,我使用了 & 前缀,这将使 mIRC 禁用该事件,以防另一个脚本执行了较早的默认文本更改并执行了 /haltdef)

;this is actually needed to bypass mIRC's parsing behavior of strtok(str, ":")
alias urlreg return /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig

;the coloring alias, blue (12), underline (31)
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))

;trigger for the regex event only
on ^&$*:text:$($urlreg):*:{
  ;if we are in a channel, turn nick into @nick if applicable
  var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)

  ;color all the linkes using the predefined alias above
  var %msgs = $regsubex($1-, $urlreg, $urlcolor(\t))

  ;print the message, default timestamp, highlighting options, and nick coloring
  echo -tcrl normal $iif($chan, $v1, $nick) $+(<, %nick, >) %msgs

  ;prevent mIRC's default echo
  haltdef
}

将变成:

<@FooBar> abc www.example.com abc www.example.com abc www.example.com

变为:

<@FooBar> abc ^12www.example.com abc ^12www.example.com abc ^12www.example.com

编辑:

我对 $target 的使用在我原来的答案中是无效的,这导致了 Commander_keen 所描述的问题。现在这个问题应该得到解决。

The mIRC 'catcher' follows the following rules:

From the help File (/help catcher):

mIRC looks for URLs beginning with "http://", "ftp://", "gopher://", "www.", and "ftp.". mIRC also checks to make sure addresses are not added to a list if they already exist. Addresses longer than 256 characters are ignored.

As stated in the other answer, modifying the default behavior will cause a spacing compression effect, but it shouldn't be too much of an issue with this script as it will only trigger when a URL is displayed. (Additionally I used the & prefix which will make mIRC disable the event in case another script has performed an earlier default text altering and executed a /haltdef)

;this is actually needed to bypass mIRC's parsing behavior of strtok(str, ":")
alias urlreg return /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig

;the coloring alias, blue (12), underline (31)
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))

;trigger for the regex event only
on ^&$*:text:$($urlreg):*:{
  ;if we are in a channel, turn nick into @nick if applicable
  var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)

  ;color all the linkes using the predefined alias above
  var %msgs = $regsubex($1-, $urlreg, $urlcolor(\t))

  ;print the message, default timestamp, highlighting options, and nick coloring
  echo -tcrl normal $iif($chan, $v1, $nick) $+(<, %nick, >) %msgs

  ;prevent mIRC's default echo
  haltdef
}

will turn:

<@FooBar> a b c www.example.com a b c www.example.com a b c www.example.com

into:

<@FooBar> a b c ^12www.example.com a b c ^12www.example.com a b c ^12www.example.com

Edit:

My use of $target was invalid in my original answer which resulted in the issue commander_keen described. This should now be fixed.

半衬遮猫 2024-10-22 05:44:01

我只是想补充一点,它需要使用 //echo 才能将文本输出到正确的通道,否则文本将被发送到状态窗口等。

此外,我会添加 -bf 和 -m 参数以将消息视为正常的用户消息并应用默认的闪烁/蜂鸣设置,否则该消息不会使通道表现得好像有新消息一样。

因此,jnpcl 脚本的总结为 //echo -bfmtrl,即使尊重时间戳设置(即 -t),

Wiz 的解决方案也可能会从其中的一些中受益也发生了变化。

亲切的问候

PS:jnpcl 的脚本滞后于没有 http:// 的 www 链接的 URL 突出显示,并且在查询窗口中突出显示。最后一个问题当然可以通过在 ^*:TEXT:*:?:{ 块上添加第二个 //echo -bfmtl $nick 轻松解决。 $+ $尼克 $+ > %tmp.text,但我想知道是否可以在一个 ON:TEXT 处理程序中完成。

不幸的是,当检测到查询中的链接并且查询中的文本保持原样时,Wiz 的脚本总是最终发送到状态窗口。似乎 $target 不能按预期的查询工作,它使用自己的昵称,但我不知道解决方案。
因此,在 jnpcl 的代码中使用 Wiz 的正则表达式并进行上述改进,最终会在通道中使用以下工作代码并查询 http 和 www 链接等。目前:

;URL highlighting for channels
    on ^*:TEXT:*:#:{
      set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
      if ($regex(links, $1-, %tmp.match) > 0) {
        set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
        //echo -bfmtlr $chan < $+ $nick $+ > %tmp.text
        halt
      }
    }

;URL highlighting for queries
    on ^*:TEXT:*:?:{
      set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
      if ($regex(links, $1-, %tmp.match) > 0) {
        set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
        //echo -bfmtlr $nick < $+ $nick $+ > %tmp.text
        halt
      }
    }

我很高兴看到 Wiz 的解决方案也可以使用查询。在我看来,这比两个事件块更干净。在那之前,上面的代码应该代表了两者的优点。

I just wanted to add that it requires to use //echo in order to get the text output to the correct channel for me, otherwise the text will be sent to the status-window or so.

Additionally I would add the -bf and -m parameters to treat the message as normal user-message and apply the default flashing/beep settings, otherweise the message won't make the channel act as if there is a new message.

So that would sum up as //echo -bfmtrl for jnpcl's script, even respecting the timestamp-settiings (that's the -t)

Wiz's solution might profit from a few of those changes, too.

kind regards

PS: jnpcl's script lags the URL-highlighting for www-links without http:// and highlight in query windows, yet. Last issue can of course easily be resolved by adding a second on ^*:TEXT:*:?:{ block with //echo -bfmtl $nick < $+ $nick $+ > %tmp.text, but I wonder if it can be done in one ON:TEXT Handler.

Wiz's script unfortunately always ends up in sending to the status window when a link in a query is detected and the text in the query stays as is. Seems like $target doesn't work as expected for queries, it uses the own nick, but I don't know a solution for that.
So using Wiz's regex in jnpcl's code with the improvements mentioned above ends up in the following working code in channels AND queries for http AND www links etc. for now:

;URL highlighting for channels
    on ^*:TEXT:*:#:{
      set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
      if ($regex(links, $1-, %tmp.match) > 0) {
        set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
        //echo -bfmtlr $chan < $+ $nick $+ > %tmp.text
        halt
      }
    }

;URL highlighting for queries
    on ^*:TEXT:*:?:{
      set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
      if ($regex(links, $1-, %tmp.match) > 0) {
        set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
        //echo -bfmtlr $nick < $+ $nick $+ > %tmp.text
        halt
      }
    }

I'd be happy to see Wiz's solution work with queries, too. That would be cleaner than two event-blocks in my eyes. Until then the above code should represent a best of both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文