Skip to content

Commit

Permalink
release 0.16.0, add ignore spaces feature, close #5
Browse files Browse the repository at this point in the history
  • Loading branch information
camsong committed Sep 15, 2016
1 parent a04d304 commit c7668c7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Amazing native-like 'Download' button in file detail page!

![show notifications](https://cloud.githubusercontent.com/assets/948896/14252559/860a154a-faba-11e5-8721-1b69070b3cdb.png)

#### 7. Ignore whitespace feature

Add 'Ignore Spaces' and 'Show Spaces' button to let you ignore whitespace in code review. The trick behind this is adding `?w=1` to any diff URL will remove any changes only in whitespace, enabling you to see only that code that has changed.

![Ignore whitespace](https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67)

### TODO

* Download folder on one click
Expand Down
58 changes: 58 additions & 0 deletions ignore-spaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var IgnoreSpace = {
init: function() {
if (document.querySelectorAll('.ignore-spaces-btn')) {
document.querySelectorAll('.ignore-spaces-btn').forEach(function(node) {
node.remove();
})
}
if (this.isValid()) {
if (this.isCurrentIgnore()) {
this.renderShowSpacesBtn();
} else {
this.renderIgnoreSpacesBtn();
}
}
},

// Check if it's code review diff page. like https://github.com/angular/angular.js/pull/10539/files?w=1
isValid() {
return document.querySelector('.diffbar') && document.querySelector('.pr-review-tools');
},

isCurrentIgnore() {
return location.search.indexOf('w=1') > -1;
},

renderShowSpacesBtn() {
// remove w=1 in url
let url = location.href.replace('w=1&', '').replace('&w=1', '').replace('?w=1', '');
this.addBtn(this.newBtn(url, 'Show Spaces', 'Click to show spaces in the Diff'));
},

renderIgnoreSpacesBtn() {
// add w=1 in url
let url = location.href + (location.href.indexOf('?') > -1 ? '&w=1' : '?w=1');
this.addBtn(this.newBtn(url, 'Ignore Spaces', 'Click to hide spaces in the Diff'));
},

newBtn(url, text, hint) {
let btn = document.createElement('a');
btn.setAttribute('class', 'btn btn-sm btn-primary tooltipped tooltipped-n ignore-spaces-btn');
btn.setAttribute('style', 'float: left; margin-right: 20px');
btn.setAttribute('href', url);
btn.setAttribute('aria-label', hint);
btn.textContent = text;
return btn;
},

addBtn(btn) {
document.querySelector('.pr-review-tools').prepend(btn);
}
}

IgnoreSpace.init();

// 当使用 pjax 更新页面时执行
document.addEventListener('_pjax:end', function() {
IgnoreSpace.init();
}, false);
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Octo Mate",
"description": "Missing mate of GitHub, making single file download effortless and with more features",
"default_locale": "en",
"version": "0.15.2",
"version": "0.16.0",
"background": {
"persistent": false,
"page": "background.html"
Expand All @@ -18,7 +18,7 @@
"matches": ["https://github.com/*"],
"run_at": "document_end",
"css": ["style.css"],
"js": ["jquery-2.1.3.min.js", "page.js", "config.js", "script.js", "show-size.js", "tab-size.js", "panel.js"]
"js": ["jquery-2.1.3.min.js", "page.js", "config.js", "script.js", "show-size.js", "tab-size.js", "panel.js", "ignore-spaces.js"]
}
],
"browser_action": {
Expand Down

0 comments on commit c7668c7

Please sign in to comment.