Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.addEventListener('load', function() {
- var challenges = document.getElementById('challenges'),
- challenge, i, len;
- function change(e) {
- if(e && e.target && e.target.tagName === 'LI') {
- // if this func is called from the listener, check if it's the element we want
- e = e.target.querySelector('a.btn[data-action="play"][data-challenge-id]:not(atchd)');
- if(e) {
- e.setAttribute('atchd', '1'); // this is so we know we grabbed it already
- e.textContent = 'Accept [atchd]';
- processElem(e); // do a callback
- }
- } else {
- // if this func isn't called from the listener, grab all current un-grabbed buttons
- e = challenges.querySelectorAll('a.btn[data-action="play"][data-challenge-id]:not(atchd)');
- if(e.length !== 0) {
- len = e.length;
- for (i = 0; i < len; i += 1) {
- challenge = e[i];
- challenge.setAttribute('atchd', '1'); // this is so we know we grabbed it already
- challenge.textContent = 'Accept [atchd]';
- processElem(e); // do a callback
- }
- }
- }
- }
- function processElem(element) {
- // do whatever we want with the anchor node element
- }
- // it found the common ancestor
- if(challenges) {
- change(); // run it for the first time
- challenges.addEventListener('DOMNodeInserted', change, false); // listen for changes
- }
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement