V
V
Vimake2014-01-12 22:04:06
JavaScript
Vimake, 2014-01-12 22:04:06

How to implement an extension for Chrome?

I'm making a Chrome extension for VK.
Here is the manifest:

{
   "browser_action": {
      "default_icon": "48.png"
   },
   "content_scripts": [ {
      "include_globs": [ "http://vk.com/*", "https://vk.com/*" ],
      "js": [ "mainscript.js" ],
      "matches": [ "http://*/*", "https://*/*" ],
      "run_at": "document_idle"
   } ],
   "converted_from_user_script": true,
   "icons": {
      "128": "128.png",
      "48": "48.png"
   },
   "manifest_version": 2,
   "name": "Расширялочка",
   "update_url": "https://clients2.google.com/service/update2/crx",
   "version": "1.0"
}

Here is the js script:
setTimeout(check_user_page(), 5000)

function check_user_page(){
var profile=document.getElementById('profile_short');
if(!profile) return false;
var page_prison_user_info=document.getElementById('page_user_info');
if(page_user_info) return false;
alert("мы у юзверя!!!");
 }

The problem is this:
The message should knock out after opening the page of the user or his friends.
But the message knocks out only after reloading the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
buzzi888, 2014-01-13
@buzzi888

you can use DOM MutationObserver.
hang a handler for adding / changing / deleting #profile_short or #page_user_info and the browser will notify you about changes in these elements when they occur (they will be loaded by Ajax and added to the DOM, for example)
you can read it even easier here
- track url changes, it will help with this onhashchange event

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question