Checking url changes on SPA’s

Trying to check when YouTube’s url changes, i have tried using, onpopstate as well as onhashchange but onpopstate doesnt log or do anything when the url changes and the onhashchange only fires once when the page is refreshed but not when the url changes. A lot of other answers from StackOverflow on this mentioned to use these methods but they dont seem to work, i am doing this with a chrome-react-extension.

the basic code looks like this:

if (/youtube.com/watch(.*)+/.test(window.location.href)) {
  if ("onhashchange" in window) {
    console.log('hash change');
  }
}

I also tried:

window.onpopstate = function(event) {
  alert("location: " + document.location + ", state: " + 
JSON.stringify(event.state));
};

How to give a browser extension all text data input into that browser?

I’m experimenting with Chrome browser extensions. I want to be able to take any text input into the browser (through the URL bar of the browser or onto text boxes on social media sites and so on) and send that text to a server. I’m wondering if this is possible in chrome and what functions I need to use to achieve this?

I suspect the logic of the extension would work something like this: any time a link is clicked where there is text in an input form / text box, extract that text or form input and send it using some JS requests library to a server.

Which Chrome API function can be used to get the text input into a form?

Chrome Storage – Username/Password

I’m having some problems with my chrome extension… I’m trying to save a username and password for auto-filling on another page – problem is it wont let me edit the username, although it fully works on password…

For clarification, brugernavn = username – adgangskode = password.

Popup window

The javascript activated through html popup is following:

Username:

  window.addEventListener('load', function load(event) {
      chrome.storage.local.get(['brugernavn'], function(result) {
          if (result !== undefined && result.brugernavn !== undefined) {
              document.getElementById('brugernavn').value = result.brugernavn;
    }
});

  document.getElementById('gem').onclick = function() {
    chrome.storage.local.remove('brugernavn');
      chrome.storage.local.set({'brugernavn': document.getElementById('brugernavn').value});
    };
});

Password:

  window.addEventListener('load', function load(event) {
      chrome.storage.local.get(['adgangskode'], function(result) {
          if (result !== undefined && result.adgangskode !== undefined) {
              document.getElementById('adgangskode').value = result.adgangskode;
          }
      });

  document.getElementById('gem').onclick = function() {
    chrome.storage.local.remove('adgangskode');
      chrome.storage.local.set({'adgangskode': document.getElementById('adgangskode').value});
};
  });

So password works fully, but I’m not able to edit username to save a new username.

Thanks in advance.

Increment selector and click

If #Remove_05 exists I want to increment the number after the underscore e.g #Remove_% and .click() each element. Is there a more efficient method without repeating?

JS

if(document.getElementById("Remove_05")){
document.getElementById("Remove_06").click();
document.getElementById("Remove_07").click();
document.getElementById("Remove_08").click();
document.getElementById("Remove_09").click();
document.getElementById("Remove_10").click();
}

HTML






I’ve tried this but not too familiar with javascript.

var mydiv = document.getElementById('Remove_');
currentId = 5;

mydiv.addEventListener('click', function() {
   currentId.remove('_' + mydiv.currentId);
   currentId.add('_' + (++mydiv.currentId));
});

Browser-Action / ChromeExtention (Uncaught TypeError: Cannot read property ‘addEventListener’ of null

I’m working on my first Chrome extension and I can’t solve this problem. I get an ‘Uncaught TypeError: Cannot read property ‘addEventListener’ of null’ – Error message refers to the last line of my JS code (please see below).

Any ideas? Any help is much appreciated! Many thanks in advance!

HTML






Enter ID:

Comments

JS

var num1 = document.getElementById('form1');

function a(num1) {
window.open("https://www.facebook.com/search/str/" + num1 + "/photos-
commented", "a") 
};

document.getElementById("form1").addEventListener('click', a(num1));