Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add bar mode for the clippy haters. JSHintd code.
- Loading branch information
Showing
4 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
Install it, and bask in His glory. | ||
|
||
## [Click here to install](https://github.com/downloads/rixth/jsbeautify-for-chrome/jsbeautify-for-chrome.crx) | ||
* [Click here to install with Clippy](https://github.com/downloads/rixth/jsbeautify-for-chrome/jsbeautify-for-chrome-with-clippy.crx) | ||
* [Click here to install without Clippy](https://github.com/downloads/rixth/jsbeautify-for-chrome/jsbeautify-for-chrome-without-clippy.crx) | ||
|
||
![screenshot](http://i.imgur.com/rJEg1.png) | ||
![screenshot with clippy](http://i.imgur.com/rJEg1.png) | ||
|
||
If you haven't got the love for Clippy, you can use an alert bar instead. | ||
|
||
![screenshot without clippy](http://i.imgur.com/ZhXnX.png) | ||
|
||
Uses [JSBeautify](http://jsbeautifier.org). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,75 @@ | ||
/*jshint browser: true, jquery: true, indent: 2, white: true, curly: true, forin: true, noarg: true, immed: true, newcap: false, noempty: true, nomen: true, eqeqeq: true, undef: true*/ | ||
/*globals chrome, js_beautify*/ | ||
|
||
(function () { | ||
if (!location.href.match(/\.js(?:\?|$)/)) { | ||
if (!location.href.match(/\.js(?:\?|$)/) || document.body.querySelectorAll('*').length !== 1) { | ||
return; | ||
} | ||
|
||
var clippy = document.createElement('div'), | ||
yes = document.createElement('a'), | ||
var notification = document.createElement('div'), | ||
no = document.createElement('a'), | ||
autoHideInterval, | ||
secondsTillHide = 4; | ||
secondsTillHide = 4, | ||
useClippy = true, | ||
formatConfirmElement, | ||
yes; | ||
|
||
clippy.id = 'jsb4c-clippy'; | ||
clippy.style.backgroundImage = 'url(' + chrome.extension.getURL("img/its-clippy-motherfuckers.png") + ')'; | ||
|
||
yes.id = 'jsb4c-yes'; | ||
yes.appendChild(document.createTextNode('Yes')); | ||
notification.id = 'jsb4c-' + (useClippy ? 'clippy' : 'bar'); | ||
|
||
no.id = 'jsb4c-no'; | ||
no.appendChild(document.createTextNode('No (' + secondsTillHide + ')')); | ||
|
||
clippy.appendChild(yes); | ||
clippy.appendChild(no); | ||
if (useClippy) { | ||
yes = document.createElement('a'); | ||
yes.id = 'jsb4c-yes'; | ||
yes.appendChild(document.createTextNode('Yes')); | ||
|
||
notification.style.backgroundImage = 'url(' + chrome.extension.getURL("img/its-clippy-motherfuckers.png") + ')'; | ||
notification.appendChild(yes); | ||
formatConfirmElement = yes; | ||
} else { | ||
notification.appendChild(document.createTextNode('This looks like a JavaScript file. Click this bar to format it.')); | ||
no.style.backgroundImage = 'url(' + chrome.extension.getURL("img/close-icon.png") + ')'; | ||
formatConfirmElement = notification; | ||
} | ||
|
||
notification.appendChild(no); | ||
document.body.appendChild(notification); | ||
|
||
document.body.appendChild(clippy); | ||
|
||
setTimeout(function () { | ||
clippy.className = 'jsb4c-visible'; | ||
}, 350); | ||
|
||
no.addEventListener('click', function (event) { | ||
clippy.className = ''; | ||
gtfoClippy(); | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}, false); | ||
|
||
yes.addEventListener('click', function (event) { | ||
formatConfirmElement.addEventListener('click', function (event) { | ||
var code = document.getElementsByTagName('pre')[0]; | ||
code.textContent = js_beautify(code.textContent); | ||
|
||
clippy.className = ''; | ||
gtfoClippy(); | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}, false); | ||
|
||
function gtfoClippy() { | ||
notification.className = ''; | ||
setTimeout(function () { | ||
notification.parentNode.removeChild(notification); | ||
}, 1000); | ||
} | ||
|
||
setTimeout(function () { | ||
notification.className = 'jsb4c-visible'; | ||
}, 350); | ||
|
||
// Auto timer to make clippy go away | ||
autoHideInterval = setInterval(function () { | ||
if (secondsTillHide <= 0) { | ||
clippy.className = ''; | ||
gtfoClippy(); | ||
clearInterval(autoHideInterval); | ||
} else { | ||
no.innerHTML = no.innerHTML.replace(/\d/, secondsTillHide); | ||
} | ||
secondsTillHide--; | ||
}, 1000); | ||
}()); | ||
}()); |