Skip to content
Browse files

Fixed some activation bugs. Line numbers toggleable. Sigth toggleable.

  • Loading branch information...
1 parent 37f35e3 commit d6c4ca6ab0f1ab56262d61e7aef2a50f23ff9dae Tomás Senart committed
Showing with 92 additions and 78 deletions.
  1. +1 −1 .gitignore
  2. +3 −3 LICENSE.md
  3. +1 −1 README.md
  4. +1 −1 css/ascetic.css
  5. +1 −1 css/dark.css
  6. +1 −1 css/default.css
  7. +1 −1 css/github.css
  8. +1 −2 css/main.css
  9. +1 −1 css/popup.css
  10. +3 −3 css/reset.css
  11. +1 −1 css/sunburst.css
  12. +1 −1 css/vs.css
  13. +4 −3 js/background.js
  14. +46 −33 js/content_script.js
  15. +15 −15 js/languages/objc.js
  16. +1 −1 js/languages/smalltalk.js
  17. +1 −1 js/languages/vhdl.js
  18. +3 −3 js/options.js
  19. +1 −0 js/reset.js
  20. +1 −1 manifest.json
  21. +3 −3 options.html
  22. +1 −1 popup.html
View
2 .gitignore
@@ -1,3 +1,3 @@
.DS_Store
sight.zip
-package.sh
+package.sh
View
6 LICENSE.md
@@ -35,8 +35,8 @@ modification, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- * Neither the name of highlight.js nor the names of its contributors
- may be used to endorse or promote products derived from this software
+ * Neither the name of highlight.js nor the names of its contributors
+ may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
@@ -73,4 +73,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+OTHER DEALINGS IN THE SOFTWARE.
View
2 README.md
@@ -10,4 +10,4 @@ I want it! But how?
===================
You can now [install it](http://chrome.google.com/extensions/detail/epmaefhielclhlnmjofcdapbeepkmggh) on the Google Chrome Gallery.
-After installing just access any github raw url to [try it out](http://github.com/tsenart/sight/raw/master/js/inject.js).
+After installing just access any github raw url to [try it out](http://github.com/tsenart/sight/raw/master/js/inject.js).
View
2 css/ascetic.css
@@ -40,4 +40,4 @@ pre .tex .command {
body {
background: white; color: black;
-}
+}
View
2 css/dark.css
@@ -97,4 +97,4 @@ pre .tex .formula {
body {
background: #444444;
color: white;
-}
+}
View
2 css/default.css
@@ -111,4 +111,4 @@ pre .tex .formula {
body {
background: #F0F0F0;
-}
+}
View
2 css/github.css
@@ -124,4 +124,4 @@ pre .tex .formula {
body {
color: #000;
background: #f8f8ff;
-}
+}
View
3 css/main.css
@@ -89,7 +89,6 @@ pre code {
ul#line-numbers {
float: left;
- display: none;
padding: 10px;
margin-right: 10px;
list-style: none inside;
@@ -104,4 +103,4 @@ ul#line-numbers li {
.clear {
clear: both;
-}
+}
View
2 css/popup.css
@@ -27,4 +27,4 @@ body > p {
#close_popup:hover {
color: black;
-}
+}
View
6 css/reset.css
@@ -68,7 +68,7 @@ ins {
/* change colours to suit your needs */
mark {
background-color:#ff9;
- color:#000;
+ color:#000;
font-style:italic;
font-weight:bold;
}
@@ -91,7 +91,7 @@ table {
hr {
display:block;
height:1px;
- border:0;
+ border:0;
border-top:1px solid #cccccc;
margin:1em 0;
padding:0;
@@ -99,4 +99,4 @@ hr {
input, select {
vertical-align:middle;
-}
+}
View
2 css/sunburst.css
@@ -140,4 +140,4 @@ pre .deletion {
body {
background: #000; color: #f8f8f8;
-}
+}
View
2 css/vs.css
@@ -71,4 +71,4 @@ pre .phpdoc,
pre .javadoc,
pre .xmlDocTag {
color: rgb(128, 128, 128);
-}
+}
View
7 js/background.js
@@ -1,4 +1,4 @@
-var loadJs = function(uri, cb) {
+var loadJs = function(uri, cb) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState < 4) return;
@@ -13,7 +13,6 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.lang !== undefined) {
window.tab_langs[sender.tab.id] = request.lang;
- chrome.pageAction.show(sender.tab.id);
}
!!request.preferences && sendResponse({
@@ -32,5 +31,7 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status != 'complete') return;
(!!window.tab_langs && !!window.tab_langs[tabId]) && (delete window.tab_langs[tabId]);
- chrome.tabs.executeScript(tabId, {file: 'js/content_script.js'});
+ chrome.tabs.executeScript(tabId, {file: 'js/content_script.js'}, function(){
+ chrome.pageAction.show(tabId);
+ });
});
View
79 js/content_script.js
@@ -12,6 +12,45 @@ if (!isNormalPage || isSighted) chrome.extension.sendRequest({preferences: true}
return str.replace(specials, "\\$&");
};
+ function handleKeyboardShortcuts(e) {
+ if (e.keyCode == 76) toggleLineNumbers();
+ else if (e.keyCode == 71) lineNumbersJump();
+ }
+
+ function lineNumbersJump(e) {
+ var line_numbers = document.querySelector('#line-numbers');
+ if (!line_numbers || getComputedStyle(line_numbers).display == 'none') return;
+ var line = prompt("Go to line number...", "");
+ var el = document.querySelector('#line-' + line);
+ el && el.scrollIntoViewIfNeeded();
+ }
+
+ function activateLineNumbers() { // Call one time only!
+ var line_numbers = document.querySelector('#line-numbers');
+ line_numbers && line_numbers.parentNode.removeChild(line_numbers);
+ var code = document.querySelector('pre');
+ var nlines = code.innerText.split(/\n/).length;
+ line_numbers = document.createElement('ul');
+ line_numbers.setAttribute('id', 'line-numbers');
+ for(i = 1; i <= nlines; ++i) {
+ var li = document.createElement('li')
+ li.setAttribute('id', 'line-' + i);
+ li.textContent = i;
+ line_numbers.appendChild(li);
+ }
+ document.body.insertBefore(line_numbers, code);
+ }
+
+ function toggleLineNumbers() {
+ var line_numbers = document.querySelector('#line-numbers');
+ !!line_numbers && line_numbers.style.setProperty('display', {
+ 'block': 'none',
+ '': 'none',
+ 'none': 'block'
+ }[line_numbers.style.display]);
+ }
+
+
if (!lang) {
var table = [
"cpp", ["c", "h", "cpp", "c++", "hpp", "h++"],
@@ -49,6 +88,7 @@ if (!isNormalPage || isSighted) chrome.extension.sendRequest({preferences: true}
break;
}
}
+
if (!lang) {
var url = document.location.href.split('/').pop().toLowerCase();
for (var e = table.length - 1; e >= 0; e -= 2)
@@ -81,7 +121,7 @@ if (!isNormalPage || isSighted) chrome.extension.sendRequest({preferences: true}
}).shift();
if (lang && lang.length > 0) lang = table[table.indexOf(lang) - 1];
}
-
+
}
}
};
@@ -123,39 +163,12 @@ if (!isNormalPage || isSighted) chrome.extension.sendRequest({preferences: true}
code.classList.add(lang);
hljs.highlightBlock(code.firstChild, ' ', false);
- var toggleLineNumbers = function() {
- var line_numbers = document.querySelector('#line-numbers');
- if(!line_numbers) {
- var code = document.querySelector('pre');
- var nlines = code.innerText.split(/\n/).length;
- line_numbers = document.createElement('ul');
- line_numbers.setAttribute('id', 'line-numbers');
- for(i = 1; i <= nlines; ++i) {
- var li = document.createElement('li')
- li.setAttribute('id', 'line-' + i);
- li.textContent = i;
- line_numbers.appendChild(li);
- }
- document.body.insertBefore(line_numbers, code);
- }
- line_numbers.style.display = {'block':'none','none':'block'}[String(window.getComputedStyle(line_numbers).display)];
- };
-
- if (!isSighted && eval(prefs.line_numbers)) {
- toggleLineNumbers();
- document.addEventListener("keyup", function(e) {
- var line_numbers = document.querySelector('#line-numbers');
- if (e.keyCode == 71 && window.getComputedStyle(line_numbers).display == 'block') {
- var line = prompt("Go to line number...", "");
- var el = document.querySelector('#line-' + line);
- el && el.scrollIntoViewIfNeeded();
- }
- if (e.keyCode == 76)
- toggleLineNumbers();
- });
-
+ if (!isSighted) {
+ !!eval(prefs.line_numbers) && activateLineNumbers();
+ document.onkeyup = handleKeyboardShortcuts;
}
- !isSighted && document.body.classList.add('sighted');
+
+ document.body.classList.add('sighted');
document.body.style.display = 'block';
});
});
View
30 js/languages/objc.js
@@ -3,31 +3,31 @@ Language: Objective C
*/
hljs.LANGUAGES.objc = function(){
- var OBJC_KEYWORDS = {
+ var OBJC_KEYWORDS = {
'keyword': {
'false': 1, 'int': 1, 'float': 1, 'while': 1, 'private': 1, 'char': 1,
'catch': 1, 'export': 1, 'sizeof': 2, 'typedef': 2, 'const': 1,
- 'struct': 1, 'for': 1, 'union': 1, 'unsigned': 1, 'long': 1,
- 'volatile': 2, 'static': 1, 'protected': 1, 'bool': 1, 'mutable': 1,
- 'if': 1, 'public': 1, 'do': 1, 'return': 1, 'goto': 1, 'void': 2,
- 'enum': 1, 'else': 1, 'break': 1, 'extern': 1, 'true': 1, 'class': 1,
+ 'struct': 1, 'for': 1, 'union': 1, 'unsigned': 1, 'long': 1,
+ 'volatile': 2, 'static': 1, 'protected': 1, 'bool': 1, 'mutable': 1,
+ 'if': 1, 'public': 1, 'do': 1, 'return': 1, 'goto': 1, 'void': 2,
+ 'enum': 1, 'else': 1, 'break': 1, 'extern': 1, 'true': 1, 'class': 1,
'asm': 1, 'case': 1, 'short': 1, 'default': 1, 'double': 1, 'throw': 1,
- 'register': 1, 'explicit': 1, 'signed': 1, 'typename': 1, 'try': 1,
- 'this': 1, 'switch': 1, 'continue': 1, 'wchar_t': 1, 'inline': 1,
+ 'register': 1, 'explicit': 1, 'signed': 1, 'typename': 1, 'try': 1,
+ 'this': 1, 'switch': 1, 'continue': 1, 'wchar_t': 1, 'inline': 1,
'readonly': 1, 'assign': 1, 'property': 1, 'protocol': 10, 'self': 1,
- 'synchronized': 1, 'end': 1, 'synthesize': 50, 'id': 1, 'optional': 1,
+ 'synchronized': 1, 'end': 1, 'synthesize': 50, 'id': 1, 'optional': 1,
'required': 1, 'implementation': 10, 'nonatomic': 1,'interface': 1,
'super': 1, 'unichar': 1, 'finally': 2, 'dynamic': 2, 'nil': 1
},
'built_in': {
'YES': 5, 'NO': 5, 'NULL': 1, 'IBOutlet': 50, 'IBAction': 50,
- 'NSString': 50, 'NSDictionary': 50, 'CGRect': 50, 'CGPoint': 50,
- 'NSRange': 50, 'release': 1, 'retain': 1, 'autorelease': 50,
+ 'NSString': 50, 'NSDictionary': 50, 'CGRect': 50, 'CGPoint': 50,
+ 'NSRange': 50, 'release': 1, 'retain': 1, 'autorelease': 50,
'UIButton': 50, 'UILabel': 50, 'UITextView': 50, 'UIWebView': 50,
- 'MKMapView': 50, 'UISegmentedControl': 50, 'NSObject': 50,
- 'UITableViewDelegate': 50, 'UITableViewDataSource': 50, 'NSThread': 50,
- 'UIActivityIndicator': 50, 'UITabbar': 50, 'UIToolBar': 50,
- 'UIBarButtonItem': 50, 'UIImageView': 50, 'NSAutoreleasePool': 50,
+ 'MKMapView': 50, 'UISegmentedControl': 50, 'NSObject': 50,
+ 'UITableViewDelegate': 50, 'UITableViewDataSource': 50, 'NSThread': 50,
+ 'UIActivityIndicator': 50, 'UITabbar': 50, 'UIToolBar': 50,
+ 'UIBarButtonItem': 50, 'UIImageView': 50, 'NSAutoreleasePool': 50,
'UITableView': 50, 'BOOL': 1, 'NSInteger': 20, 'CGFloat': 20,
'NSException': 50, 'NSLog': 50
}
@@ -62,7 +62,7 @@ hljs.LANGUAGES.objc = function(){
className: 'title',
begin: '<', end: '>',
lexems: hljs.IDENT_RE
- }
+ }
]
},
{
View
2 js/languages/smalltalk.js
@@ -49,4 +49,4 @@ hljs.LANGUAGES.smalltalk = function(){
}
]
};
-}();
+}();
View
2 js/languages/vhdl.js
@@ -14,7 +14,7 @@ hljs.LANGUAGES.vhdl = {
'keyword': { 'abs': 1, 'access': 1, 'after': 1, 'alias': 1, 'all': 1, 'and': 1, 'architecture': 2, 'array': 1, 'assert': 1, 'attribute': 1, 'begin': 1, 'block': 1, 'body': 1, 'buffer': 1, 'bus': 1, 'case': 1, 'component': 2, 'configuration': 1, 'constant': 1, 'disconnect': 2, 'downto': 2, 'else': 1, 'elsif': 1, 'end': 1, 'entity': 2, 'exit': 1, 'file': 1, 'for': 1, 'function': 1, 'generate': 2, 'generic': 2, 'group': 1, 'guarded': 2, 'if': 0, 'impure': 2, 'in': 1, 'inertial': 1, 'inout': 1, 'is': 1, 'label': 1, 'library': 1, 'linkage': 1, 'literal': 1, 'loop': 1, 'map': 1, 'mod': 1, 'nand': 1, 'new': 1, 'next': 1, 'nor': 1, 'not': 1, 'null': 1, 'of': 1, 'on': 1, 'open': 1, 'or': 1, 'others': 1, 'out': 1, 'package': 1, 'port': 2, 'postponed': 1, 'procedure': 1, 'process': 1, 'pure': 2, 'range': 1, 'record': 1, 'register': 1, 'reject': 1, 'return': 1, 'rol': 1, 'ror': 1, 'select': 1, 'severity': 1, 'signal': 1, 'shared': 1, 'sla': 1, 'sli': 1, 'sra': 1, 'srl': 1, 'subtype': 2, 'then': 1, 'to': 1, 'transport': 1, 'type': 1, 'units': 1, 'until': 1, 'use': 1, 'variable': 1, 'wait': 1, 'when': 1, 'while': 1, 'with': 1, 'xnor': 1, 'xor': 1},
'type': { 'boolean': 1, 'bit': 1, 'character': 1, 'severity_level': 2, 'integer': 1, 'time': 1, 'delay_length': 2, 'natural': 1, 'positive': 1, 'string': 1, 'bit_vector': 2, 'file_open_kind': 2, 'file_open_status': 2, 'std_ulogic': 2, 'std_ulogic_vector': 2, 'std_logic': 2, 'std_logic_vector': 2 }
},
-
+
contains: ['comment', 'string', 'number', 'literal']
},
View
6 js/options.js
@@ -17,17 +17,17 @@ document.addEventListener("DOMContentLoaded", function() {
document.getElementById('line-numbers').style.display = line_numbers ? 'block' : 'none';
localStorage.line_numbers = line_numbers;
});
-
+
localStorage.theme = localStorage.theme || 'sunburst';
localStorage.font = localStorage.font || 'Inconsolata';
localStorage.line_numbers = localStorage.line_numbers || true;
-
+
loadCSS('css/' + localStorage.theme + '.css');
document.querySelector('#theme option[value="' + localStorage.theme + '"]').selected = true;
document.querySelector('#font option[value="' + localStorage.font + '"]').selected = true;
document.querySelector('code').style.fontFamily = localStorage.font;
document.querySelector('#line-numbers').style.fontFamily = localStorage.font;
- document.querySelector('#line-numbers').style.display = eval(localStorage.line_numbers) ? 'block' : 'display';
+ document.querySelector('#line-numbers').style.display = eval(localStorage.line_numbers) ? 'block' : 'none';
document.querySelector('#show-line-numbers').checked = eval(localStorage.line_numbers);
document.querySelector('code').style.fontFamily = localStorage.font;
hljs.initHighlighting();
View
1 js/reset.js
@@ -8,4 +8,5 @@ if (!!pre) {
document.body.removeAttribute('style'); document.body.removeAttribute('class');
for(var i = 0; i < els.length; ++i)
els[i].parentNode.removeChild(els[i]);
+document.onkeyup = null;
document.body.style.display = 'block';
View
2 manifest.json
@@ -11,7 +11,7 @@
"default_icon": "images/icon19.png",
"default_popup": "popup.html"
},
- "icons": {
+ "icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
View
6 options.html
@@ -1,6 +1,6 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
+<!DOCTYPE html>
+<html lang="en">
+ <head>
<meta charset="utf-8">
<script src="/js/highlight.js"></script>
<script src="/js/languages/ruby.js"></script>
View
2 popup.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html>
+<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

0 comments on commit d6c4ca6

Please sign in to comment.
Something went wrong with that request. Please try again.