Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace symbols on a webpage with Chrome extension
    primarykey
    data
    text
    <p>I'm trying to figure out how to write a simple Chrome extension which allows to transliterate web pages from one alphabet to another. Unfortunately Google's documentation on Chrome extensions is pretty much confusing for a beginner. I've seen a lot of similar questions here, f.ex. <a href="https://stackoverflow.com/questions/5797661/replace-text-in-website-with-chrome-content-script-extension">Replace text in website with Chrome content script extension</a>, but still can't get it clear. In a trial run I'm trying to replace all "a"'s in the page with "Z"'s.</p> <p>Here's my Manifest.json:</p> <pre><code>{ "name": "My Chrome extension", "version": "0.1", "browser_action": { "default_icon": "icon.png" }, "permissions": [ "tabs", "http://*/*", "https://*/*" ], "content_scripts": [{ "matches": ["http://*/*", "https://*/*"], "js": ["myscript.js"] }] } </code></pre> <p>Myscript.js:</p> <pre><code>chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript( null, {code:"document.body.innerHTML = document.body.innerHTML.replace(new RegExp("a", "g"), "Z")"}); }); </code></pre> <p>But this fails to work. If I include only one line into Myscript.js:</p> <pre><code>document.body.innerHTML = document.body.innerHTML.replace(new RegExp("a", "g"), "Z"); </code></pre> <p>then all 'a' letters get replaced with 'Z' as soon as the page has loaded, but this is not my goal, as I want to get it working only after the extension button is pressed.</p> <p>Any help will be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload