Skip to content

Commit

Permalink
Fix #1 to work around the pjax replacing
Browse files Browse the repository at this point in the history
  • Loading branch information
robario committed Aug 28, 2013
1 parent 68e5a25 commit e702082
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions github-diff-ws.user.js
Expand Up @@ -7,23 +7,32 @@
return;
}

var a = document.createElement('a');
a.setAttribute('class', 'minibutton');
if (/[&?]w=/.test(location.search)) {
a.innerText = 'Cognize WS';
a.onclick = function() {
var search = location.search.replace(/[&?]w=/g, '');
if (search) {
location.search = search;
} else {
location.href = location.pathname + location.hash;
}
};
} else {
a.innerText = 'Ignore WS';
a.onclick = function() {
location.search += location.search ? '&w=' : '?w=';
};
}
toc.getElementsByClassName('explain')[0].insertBefore(a, toc.getElementsByClassName('show-diff-stats')[0]);
var updateUI = function(toc) {
var a = document.createElement('a');
a.setAttribute('class', 'minibutton');
if (/[&?]w=/.test(location.search)) {
a.innerText = 'Cognize WS';
a.onclick = function() {
var search = location.search.replace(/[&?]w=/g, '');
if (search) {
location.search = search;
} else {
location.href = location.pathname + location.hash;
}
};
} else {
a.innerText = 'Ignore WS';
a.onclick = function() {
location.search += location.search ? '&w=' : '?w=';
};
}
toc.getElementsByClassName('explain')[0].insertBefore(a, toc.getElementsByClassName('show-diff-stats')[0]);
};

document.getElementById('js-repo-pjax-container').addEventListener('DOMNodeInserted', function(event) {
if (event.target.id == 'toc') {
updateUI(event.target);
}
}, false);
updateUI(toc);
})();

0 comments on commit e702082

Please sign in to comment.