且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以使Greasmonkey脚本在文本文件上运行吗?

更新时间:2023-10-28 13:59:10

是的,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);

然后查看结果.