使用 TamperMonkey 更改每个单词
Change every word with TamperMonkey
我想从页面中获取每个单词或每个句子(不是 HTML 代码),然后通过 POST 将其发送到服务器,获取响应并更改 word/sentence/whole带有回复的文本。
我的代码在从 TamperMonkey 上下文菜单中单击后运行:
// ==UserScript==
// @name name
// @namespace https://github.com/...
// @version 1.0
// @description description
// @copyright 2016+, 31SDS14
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// ==/UserScript==
GM_registerMenuCommand('Change that words!', function() {
alert(document.body.innerHTML);
//here send every word or whole sentences to the server via POST and replace those words with received response
}, 'r');
如何在没有 HTML 代码的情况下从正文中获取文本?
一个简单的答案是:
document.body.innerText;
我想从页面中获取每个单词或每个句子(不是 HTML 代码),然后通过 POST 将其发送到服务器,获取响应并更改 word/sentence/whole带有回复的文本。
我的代码在从 TamperMonkey 上下文菜单中单击后运行:
// ==UserScript==
// @name name
// @namespace https://github.com/...
// @version 1.0
// @description description
// @copyright 2016+, 31SDS14
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// ==/UserScript==
GM_registerMenuCommand('Change that words!', function() {
alert(document.body.innerHTML);
//here send every word or whole sentences to the server via POST and replace those words with received response
}, 'r');
如何在没有 HTML 代码的情况下从正文中获取文本?
一个简单的答案是:
document.body.innerText;