Search code examples
javascriptgoogle-chromegreasemonkeytampermonkey

Change every word with TamperMonkey


I want to get every word or every sentence (not HTML code) from the page, then send it to the server via POST, get response and change that word/sentence/whole text with the response.

My code runs after click from TamperMonkey context menu:

// ==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');

How can I get text from the body without HTML code?


Solution

  • A simple answer is:

    document.body.innerText;