ページの要素変更


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>無題 1</title>
</head>

<body>
<div id="target">ここを変更する</div>
<div>ここは変更しない</div>
</body>

</html>

{
 "name": "My Third Extension",
 "version": "1.0",
 "manifest_version": 2,
 
 "description": "タブで開かれているページにスクリプトを実行する",
 
 "permissions": [
  "tabs", 
  "http://*/*",
  "https://*/*"
    ],
 
 "background": {
        "scripts": ["background.js"]
    },
 
 "browser_action": {
  "default_icon": "icon.png",
  "default_title": "chrome.windows.create"//指定しないとnameが表示
 }
}
var ele = "document.getElementById('target')";
unification = ele + ".innerHTML = '変更する'";

chrome.browserAction.onClicked.addListener(function () {

    chrome.tabs.executeScript(null,{ code: unification });
});


0 件のコメント: