xonecas.io
124
Cr

chrome-hijs / commit 0d88348

initial commit

sean2011-07-21 0d883489b3635bbf1291d38ae19606fa7a634e64

4 files changed

README.md+1−0
@@ -0,0 +1 @@
1+# HIJS for CHROME
highlight.css+6−0
@@ -0,0 +1,6 @@
1+pre .keyword { font-weight: bold }
2+pre .string, pre .regexp { color: green }
3+pre .class, pre .special { color: blue }
4+pre .number { color: pink }
5+pre .comment { color: grey }
6+
hijs.js+96−0
@@ -0,0 +1,96 @@
1+//set the selector
2+window.hijs = 'pre';
3+
4+(function (hijs) {
5+//
6+// hijs - JavaScript Syntax Highlighter
7+//
8+// Copyright (c) 2010 Alexis Sellier
9+//
10+
11+// All elements which match this will be syntax highlighted.
12+var selector = hijs || 'code';
13+
14+var keywords = ('var function if else for while break switch case do new null in with void '
15+ +'continue delete return this true false throw catch typeof with instanceof').split(' '),
16+ special = ('eval window document undefined NaN Infinity parseInt parseFloat '
17+ +'encodeURI decodeURI encodeURIComponent decodeURIComponent').split(' ');
18+
19+// Syntax definition
20+// The key becomes the class name of the <span>
21+// around the matched block of code.
22+var syntax = [
23+ ['comment', /(\/\*(?:[^*\n]|\*+[^\/*])*\*+\/)/g],
24+ ['comment', /(\/\/[^\n]*)/g],
25+ ['string' , /("(?:(?!")[^\\\n]|\\.)*"|'(?:(?!')[^\\\n]|\\.)*')/g],
26+ ['regexp' , /(\/.+\/[mgi]*)(?!\s*\w)/g],
27+ ['class' , /\b([A-Z][a-zA-Z]+)\b/g],
28+ ['number' , /\b([0-9]+(?:\.[0-9]+)?)\b/g],
29+ ['keyword', new(RegExp)('\\b(' + keywords.join('|') + ')\\b', 'g')],
30+ ['special', new(RegExp)('\\b(' + special.join('|') + ')\\b', 'g')]
31+];
32+var nodes, table = {};
33+
34+if (/^[a-z]+$/.test(selector)) {
35+ nodes = document.getElementsByTagName(selector);
36+} else if (/^\.[\w-]+$/.test(selector)) {
37+ nodes = document.getElementsByClassName(selector.slice(1));
38+} else if (document.querySelectorAll) {
39+ nodes = document.querySelectorAll(selector);
40+} else {
41+ nodes = [];
42+}
43+
44+for (var i = 0, children; i < nodes.length; i++) {
45+ children = nodes[i].childNodes;
46+
47+ for (var j = 0, str; j < children.length; j++) {
48+ code = children[j];
49+
50+ if (code.length >= 0) { // It's a text node
51+ // Don't highlight command-line snippets
52+ if (! /^\$\s/.test(code.nodeValue.trim())) {
53+ syntax.forEach(function (s) {
54+ var k = s[0], v = s[1];
55+ code.nodeValue = code.nodeValue.replace(v, function (_, m) {
56+ return '\u00ab' + encode(k) + '\u00b7'
57+ + encode(m) +
58+ '\u00b7' + encode(k) + '\u00bb';
59+ });
60+ });
61+ }
62+ }
63+ }
64+}
65+for (var i = 0; i < nodes.length; i++) {
66+ nodes[i].innerHTML =
67+ nodes[i].innerHTML.replace(/\u00ab(.+?)\u00b7(.+?)\u00b7\1\u00bb/g, function (_, name, value) {
68+ value = value.replace(/\u00ab[^\u00b7]+\u00b7/g, '').replace(/\u00b7[^\u00bb]+\u00bb/g, '');
69+ return '<span class="' + decode(name) + '">' + escape(decode(value)) + '</span>';
70+ });
71+}
72+
73+function escape(str) {
74+ return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
75+}
76+
77+// Encode ASCII characters to, and from Braille
78+function encode (str, encoded) {
79+ table[encoded = str.split('').map(function (s) {
80+ if (s.charCodeAt(0) > 127) { return s }
81+ return String.fromCharCode(s.charCodeAt(0) + 0x2800);
82+ }).join('')] = str;
83+ return encoded;
84+}
85+function decode (str) {
86+ if (str in table) {
87+ return table[str];
88+ } else {
89+ return str.trim().split('').map(function (s) {
90+ if (s.charCodeAt(0) - 0x2800 > 127) { return s }
91+ return String.fromCharCode(s.charCodeAt(0) - 0x2800);
92+ }).join('');
93+ }
94+}
95+
96+})(window.hijs);
manifest.json+17−0
@@ -0,0 +1,17 @@
1+{
2+ "name": "Hijs for chrome",
3+ "version": "0.0.1",
4+ "description": "Hijs as chrome extension for reading .js files.",
5+ "permissions" : [
6+ "http://*/*.js",
7+ "https://*/*.js"
8+ ],
9+ "content_scripts": [
10+ {
11+ "matches": ["http://*/*.js", "https://*/*.js"],
12+ "js": ["hijs.js"],
13+ "css": ["highlight.css"]
14+ }
15+ ]
16+}
17+