我可以使Greasmonkey脚本在文本文件上运行吗? [英] Can I Make Greasmonkey Scripts Run On Text Files?

查看:46
本文介绍了我可以使Greasmonkey脚本在文本文件上运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络服务器将日志作为纯文本提供.
可以使用Greasemonkey对日志进行某种格式设置还是只能在HTML内容上使用它?

My web-server serves up the logs as plain text.
Is it possible to use Greasemonkey to do some formatting of the logs or is it only possible to use it on HTML content?

我可以在加载时强制将文本转换成HTML,然后再处理吗?

Could I force the text into HTML on load then process it after?

推荐答案

是的,Greasemonkey适用于文本文件.

Yes, Greasemonkey works on text files.

请注意,当诸如Firefox或Chrome等浏览器显示纯文本文件时,浏览器会将其包装在动态的< pre> 元素中,如下所示:

Note that when a browser such as Firefox or Chrome displays a plain text file, the browser wraps it in a dynamic <pre> element, like so:

<html><head>...</head>
<body>
    <pre>
        <!-- Actual content of text file is here. -->
    </pre>
</body></html>

为获得最佳结果,请在编写脚本时将其考虑在内.

For best results, take that into account when scripting.

例如,对于此公共文本文件(I of U,开放源代码许可),请使用Greasemonkey,Tampermonkey,Scriptish等安装此脚本:

For example, for this public text file (U of I, Open Source License), install this script using Greasemonkey, Tampermonkey, Scriptish, etc.:

// ==UserScript==
// @name     _Manip text file
// @include  http://llvm.org/releases/2.8/LICENSE.TXT
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// ==/UserScript==

var pageTextNd  = $("body > pre");
var newPageTxt  = pageTextNd.text ().replace (/\bLLVM\b/gi, "Ernst Blofeld");
//-- Rewrite the page
pageTextNd.text (newPageTxt);

然后查看结果.

这篇关于我可以使Greasmonkey脚本在文本文件上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆