Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created October 17, 2011 14:07
Show Gist options
  • Save ttscoff/1292666 to your computer and use it in GitHub Desktop.
Save ttscoff/1292666 to your computer and use it in GitHub Desktop.
Add CSS loading to dot.js Safari extension
# 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')
}
})
@adamyonk
Copy link

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?

@adamyonk
Copy link

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