0

Creating the First-time extension for third party sites https://www.viki.com/videos/1151474v to get all or particular element name using get element by ID or tag name and run automatically when the page refreshed or content of the page reloads.

var temp =  document.getElementById('html5_player_id_html5');
 alert('Element temp : ' + temp);

Result: Null

var v = document.getElementsByClassName("ad-point");
  alert('Element temp : ' + v[0]); 
  while (v.length >0) v[0];
  alert("Hello timetext");

Result: Undefined

I start getting a null value when trying to get an element by particular Id or Undefined when clicking the button.

HTML:

        <button class="btn_click" id="btn_click_id">Click</button>

JavaScript

document.addEventListener('DOMContentLoaded', function() {
  var link = document.getElementById('btn_click_id');
  // onClick's logic below:
  link.addEventListener('click', function() {
   alert("Button click " + link );

   func();
  });
});   

function func() 
{
 var t = document.getElementById("html5_player_id");
  if(typeof(t) != 'undefined' && t != null)
  {
    alert("T :" + t.length);
    console.log(" Chrome extension go D4d html5 exit");
    timedText();
    alert('Element exists!');          
  } 
   else{
        func();
        alert('Element does not exist!');
       }
}


function timedText() {   setTimeout(myTimeout, 1000) }

function myTimeout()
{ 
  var v = document.getElementsByTagName('id');

  while (v.length >0) v[0];
  alert('Element temp : ' + v[0]); 
  alert("timetext run");
}

and console not working if I used console.log so I used

Kunal
  • 13
  • 7
  • 1) To access web pages you need to put that code in a content script 2) `while (v.length >0) v[0];` will hang the tab if there's at least one element inside `v`. – wOxxOm Mar 21 '20 at 13:01
  • I already try it but it runs one time only after the content page(next video load) it stops working and the same issue appears. '{ "manifest_version": 2, "name" : "D4D", "description" : "Extension was created for learning purpose. ", "version": "0.0.1", "icons": { "128" : "icon.png" }, "browser_action" : { "default_icon" : "icon.png", "default_popup" : "popup.html" }, "content_scripts" : [{ "matches" : ["https://www.viki.com/videos/*"],"js : [ "content.js"] }], "background" : ["activeTab","declarativeContent" ], }' – Kunal Mar 22 '20 at 08:32
  • That is an AJAX-driven site, see [this answer](https://stackoverflow.com/a/39508954). – wOxxOm Mar 22 '20 at 08:45

0 Answers0