Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote content_script. Changed brushAlias variable location, because…
… of referencing problems
- Loading branch information
Showing
31 changed files
with
172 additions
and
207 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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
settings = false | ||
|
||
chrome.extension.sendRequest {method: "getSettingsWithAction"}, (response) -> | ||
settings = response.settings; | ||
|
||
if syntaxtic.windowLoaded | ||
console.log 'Loaded' | ||
syntaxtic.doHighlight() | ||
else | ||
console.log 'Issuing onload' | ||
window.onload = () -> | ||
syntaxtic.windowLoaded = true | ||
syntaxtic.doHighlight() | ||
|
||
syntaxtic = | ||
windowLoaded : false, | ||
doHighlight : () -> | ||
return if not settings | ||
|
||
hasHtmlContentType = () -> | ||
console.log 'has html content?' | ||
result = false | ||
metaTags = document.getElementsByTagName('meta') | ||
console.log 'Meta Tags:', metaTags | ||
for tag in metaTags | ||
console.log 'Tag:', tag, metaTags[tag] | ||
httpEquiv = tag.httpEquiv | ||
content = tag.content | ||
continue if httpEquiv is 'undefined' | ||
|
||
if httpEquiv.toLowerCase() == "content-type" && content.toLowerCase().match("html") | ||
result = true | ||
break | ||
|
||
return result | ||
|
||
highlight = () -> | ||
if !document.body.innerHTML.match("003ew0hdafa1119dadfa39aje") | ||
if document.body.firstChild != null && document.getElementsByTagName('pre')[0] == document.body.firstChild | ||
document.body.innerHTML = """ | ||
<!-- 003ew0hdafa1119dadfa39aje --> | ||
<script type="syntaxhighlighter" class="brush: #{window.brushAlias}"> | ||
<![CDATA[#{document.body.firstChild.innerHTML}]]> | ||
</script> | ||
""" | ||
|
||
css1 = document.createElement("link") | ||
css1.href = chrome.extension.getURL("styles/shCore.css") | ||
css1.type = "text/css" | ||
css1.rel = "stylesheet" | ||
document.head.appendChild(css1) | ||
|
||
css2 = document.createElement("link") | ||
css2.href = chrome.extension.getURL("styles/" + settings.theme) | ||
css2.type = "text/css" | ||
css2.rel = "stylesheet" | ||
document.head.appendChild(css2) | ||
|
||
css3 = document.createElement("style") | ||
css3.appendChild(document.createTextNode(".toolbar {display:none}")) | ||
document.head.appendChild(css3) | ||
|
||
SyntaxHighlighter.highlight() | ||
|
||
beautifyCsv = () -> | ||
strData = document.body.firstChild.innerHTML | ||
csvArray = CsvToArray(strData, ",") | ||
maxColLengthsHash = [1..csvArray[0].length].map (i) -> -1 | ||
csvArrayDecoded = [1..csvArray.length].map (i) -> [] | ||
|
||
for firstDimension, i in csvArray | ||
for orig, j in firstDimension | ||
strDecode = html_entity_decode(orig) | ||
csvArrayDecoded[i][j] = strDecode | ||
if strDecode.length > maxColLengthsHash[j] | ||
maxColLengthsHash[j] = strDecode.length | ||
|
||
newCsvData = "" | ||
for firstDimension, k in csvArray | ||
for secondDimension, l in firstDimension | ||
newCsvData += " " for m in [0..maxColLengthsHash[l] - csvArrayDecoded[k][l].length] | ||
|
||
newCsvData += secondDimension | ||
if(l + 1 == firstDimension.length) | ||
newCsvData += '\n' | ||
else | ||
newCsvData += ", " | ||
|
||
document.body.firstChild.innerHTML = newCsvData | ||
window.brushAlias = "plain" | ||
|
||
checkForObjectiveC = -> | ||
strData = document.body.innerHTML; | ||
if strData.match(/(@interface|@protocol|@INTERFACE|@PROTOCOL)/)? | ||
return "objc" | ||
else | ||
return "cpp" | ||
|
||
changeFontSize = () -> | ||
styleElement = document.createElement('style') | ||
styleElement.type = 'text/css' | ||
styleElement.id = 'fontSizeOverride' | ||
document.getElementsByTagName('head')[0].appendChild(styleElement) | ||
newNode = document.createTextNode("body {font-size: " + settings.fontSize + " !important;}") | ||
styleElement.appendChild(newNode) | ||
|
||
applyPageSpecificSettings = () -> | ||
if(settings.gutterBlacklist.indexOf(document.location.href) > -1) | ||
loadScript(chrome.extension.getURL("toggle_gutter.js")); | ||
if(settings.highlightBlacklist.indexOf(document.location.href) > -1) | ||
loadScript(chrome.extension.getURL("toggle_highlight.js")); | ||
|
||
loadScript = (url, callback) -> | ||
head = document.getElementsByTagName('head')[0]; | ||
script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = url; | ||
|
||
script.onreadystatechange = callback; | ||
script.onload = callback; | ||
|
||
head.appendChild(script); | ||
|
||
# ######################### | ||
# MAIN | ||
# ######################### | ||
|
||
console.log 'Main' | ||
if window.brushAlias? && window.brushAlias != "" && !hasHtmlContentType() | ||
if(window.brushAlias == 'csv') | ||
beautifyCsv() | ||
|
||
if(window.brushAlias == 'cHeader') | ||
window.brushAlias = checkForObjectiveC() | ||
|
||
highlight() | ||
|
||
changeFontSize() | ||
applyPageSpecificSettings() | ||
|
||
|
||
window.onload = () -> | ||
syntaxtic.windowLoaded = true |
This file was deleted.
Oops, something went wrong.
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 +1 @@ | ||
var brushAlias = 'as3'; | ||
window.brushAlias = 'as3'; |
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 +1 @@ | ||
var brushAlias = 'bibtex'; | ||
window.brushAlias = 'bibtex'; |
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 +1 @@ | ||
var brushAlias = 'cHeader'; | ||
window.brushAlias = 'cHeader'; |
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 +1 @@ | ||
var brushAlias = 'lisp'; | ||
window.brushAlias = 'lisp'; |
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 +1 @@ | ||
var brushAlias = "clojure"; | ||
window.brushAlias = "clojure"; |
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 +1 @@ | ||
var brushAlias = "cpp"; | ||
window.brushAlias = "cpp"; |
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 +1 @@ | ||
var brushAlias = "csharp"; | ||
window.brushAlias = "csharp"; |
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 +1 @@ | ||
var brushAlias = "css"; | ||
window.brushAlias = "css"; |
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 +1 @@ | ||
var brushAlias = 'csv'; | ||
window.brushAlias = 'csv'; |
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 +1 @@ | ||
var brushAlias = "diff"; | ||
window.brushAlias = "diff"; |
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 +1 @@ | ||
var brushAlias = "erlang"; | ||
window.brushAlias = "erlang"; |
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 +1 @@ | ||
var brushAlias = "groovy"; | ||
window.brushAlias = "groovy"; |
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 +1 @@ | ||
var brushAlias = "java"; | ||
window.brushAlias = "java"; |
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 +1 @@ | ||
var brushAlias = "javafx"; | ||
window.brushAlias = "javafx"; |
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 +1 @@ | ||
var brushAlias = "js"; | ||
window.brushAlias = "js"; |
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 +1 @@ | ||
var brushAlias = "less"; | ||
window.brushAlias = "less"; |
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 +1 @@ | ||
var brushAlias = "objc"; | ||
window.brushAlias = "objc"; |
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 +1 @@ | ||
var brushAlias = "perl"; | ||
window.brushAlias = "perl"; |
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 +1 @@ | ||
var brushAlias = "plain"; | ||
window.brushAlias = "plain"; |
Oops, something went wrong.