Skip to content
Permalink
Browse files

Fix #1 to work around the pjax replacing

  • Loading branch information...
robario committed Aug 28, 2013
1 parent 68e5a25 commit e702082bf91024cd2c1a225b8020bebcf9ef19cc
Showing with 28 additions and 19 deletions.
  1. +28 −19 github-diff-ws.user.js
@@ -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.
You can’t perform that action at this time.