Created
October 17, 2011 14:07
-
-
Save ttscoff/1292666 to your computer and use it in GitHub Desktop.
Add CSS loading to dot.js Safari extension
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
# Adding CSS loading to dot.js Safari Extension | |
################################# | |
# /usr/local/bin/djsd line 33-42 | |
# just need to add "css" to the detect origin function | |
def detect_origin(req) | |
path = req.path | |
origin = req.header['origin'] | |
search = path.gsub('/','').gsub(/\.(js|css)$/,'') + '$' | |
if origin.length == 1 && path.length != 1 && origin[0].match(search) | |
origin[0] | |
end | |
end | |
################################# | |
# Append to dotjs.js in the Safari extension | |
# Same as the load for js files, but look for ".css" and use "<style>" | |
$.ajax({ | |
url: 'http://localhost:3131/'+window.location.host.replace('www.','')+'.css', | |
dataType: 'text', | |
success: function(d){ | |
$('head').append($('<style>').text(d)); | |
}, | |
error: function(){ | |
console.log('no dotjs server found at localhost:3131') | |
} | |
}) |
Also, if you set up the cert in Safari like they recommend on the dotjs repo, then you need to change to https
on line 22.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for hacking this together! When I request
.css
files after making these changes, I just get the// dotjs is working! //
text. Any ideas why?