mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
new strategy for surf mode
This commit is contained in:
parent
0efa3cada0
commit
75f6c5d31b
6 changed files with 47 additions and 7 deletions
6
app.rb
6
app.rb
|
@ -21,7 +21,13 @@ helpers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set :protection, :frame_options => "ALLOW-FROM #{$config['surf_iframe_source']}"
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
if request.host.match /\w+\.#{Addressable::URI.parse($config['surf_proxy_uri']).host}/i
|
||||||
|
surf_proxy
|
||||||
|
end
|
||||||
|
|
||||||
if request.path.match /^\/api\//i
|
if request.path.match /^\/api\//i
|
||||||
@api = true
|
@api = true
|
||||||
content_type :json
|
content_type :json
|
||||||
|
|
29
app/surf.rb
29
app/surf.rb
|
@ -16,6 +16,28 @@ get '/surf/:username' do |username|
|
||||||
erb :'surf', layout: false
|
erb :'surf', layout: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def surf_proxy
|
||||||
|
username = request.host.match /^(\w+)/i
|
||||||
|
resp = RestClient.get "http://#{username}.neocities.org#{request.path}"
|
||||||
|
content_type resp.headers[:content_type]
|
||||||
|
|
||||||
|
if content_type.match(/^text\/html/)
|
||||||
|
body = resp.body+erb(:'surf/_surf_iframe_injection', layout: false)
|
||||||
|
else
|
||||||
|
body = resp.body
|
||||||
|
end
|
||||||
|
|
||||||
|
halt body
|
||||||
|
end
|
||||||
|
|
||||||
|
def surf_proxy_uri(username)
|
||||||
|
$surf_proxy_uri ||= Addressable::URI.parse $config['surf_proxy_uri']
|
||||||
|
new_uri = $surf_proxy_uri.dup
|
||||||
|
new_uri.host = "#{username}.#{new_uri.host}"
|
||||||
|
new_uri.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
get %r{\/surf\/proxy\/([\w-]+)\/(.+)|\/surf\/proxy\/([\w-]+)\/?} do
|
get %r{\/surf\/proxy\/([\w-]+)\/(.+)|\/surf\/proxy\/([\w-]+)\/?} do
|
||||||
captures = params[:captures].compact
|
captures = params[:captures].compact
|
||||||
username = captures.first
|
username = captures.first
|
||||||
|
@ -39,8 +61,10 @@ get %r{\/surf\/proxy\/([\w-]+)\/(.+)|\/surf\/proxy\/([\w-]+)\/?} do
|
||||||
|
|
||||||
site_body.gsub(/(?<name>\b\w+\b)\s*=\s*(?<value>"[^"]*"|'[^']*'|[^"'<>\s]+)/i) do |ele|
|
site_body.gsub(/(?<name>\b\w+\b)\s*=\s*(?<value>"[^"]*"|'[^']*'|[^"'<>\s]+)/i) do |ele|
|
||||||
attributes.each do |attr|
|
attributes.each do |attr|
|
||||||
if ele.match attr
|
if ele.match /#{attr} ?=/
|
||||||
uri = ele.match(/\"(.+)\"|\'(.+)\'/).captures.first
|
ele_match = ele.match(/\"(.+)\"|\'(.+)\'/)
|
||||||
|
next if ele_match.nil? || ele_match.captures.nil?
|
||||||
|
uri = ele_match.captures.first
|
||||||
|
|
||||||
new_ele = nil
|
new_ele = nil
|
||||||
|
|
||||||
|
@ -61,3 +85,4 @@ get %r{\/surf\/proxy\/([\w-]+)\/(.+)|\/surf\/proxy\/([\w-]+)\/?} do
|
||||||
|
|
||||||
new_site_body
|
new_site_body
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
|
@ -77,4 +77,4 @@ map '/sidekiq' do
|
||||||
end
|
end
|
||||||
|
|
||||||
run Sidekiq::Web
|
run Sidekiq::Web
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,13 +63,13 @@
|
||||||
<ul class="row website-Gallery content int-Gall">
|
<ul class="row website-Gallery content int-Gall">
|
||||||
<% @sites.each_with_index do |site,i| %>
|
<% @sites.each_with_index do |site,i| %>
|
||||||
<li>
|
<li>
|
||||||
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>" onclick="return true; surf(<%= ((@current_page-1)*Site::BROWSE_PAGINATION_LENGTH)+i+1 %>); return false">
|
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>" onclick="surf(<%= ((@current_page-1)*Site::BROWSE_PAGINATION_LENGTH)+i+1 %>); return false">
|
||||||
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
|
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
|
||||||
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<a href="<%= site.uri %>" title="<%= site.title %>" onclick="return true; surf(<%= i+1 %>); return false"><%= site.title.shorten(30) %></a>
|
<a href="<%= site.uri %>" title="<%= site.title %>" onclick="surf(<%= i+1 %>); return false"><%= site.title.shorten(30) %></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="site-info">
|
<div class="site-info">
|
||||||
<div class="username">
|
<div class="username">
|
||||||
|
|
|
@ -235,9 +235,8 @@
|
||||||
<a class="close" href="//<%= @site.host %>" alt="close" title="close"></a>
|
<a class="close" href="//<%= @site.host %>" alt="close" title="close"></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<iframe src="<%= "#{$config['surf_proxy_uri']}/surf/proxy/#{@site.username}" %>" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" id="website-frame" name="website-frame"></iframe>
|
<iframe src="<%= "#{surf_proxy_uri @site.username}" %>" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" id="website-frame" name="website-frame"></iframe>
|
||||||
|
|
||||||
<script src="/js/jquery-1.11.0.min.js"></script>
|
<script src="/js/jquery-1.11.0.min.js"></script>
|
||||||
<script src="/js/bootstrap.min.js"></script>
|
<script src="/js/bootstrap.min.js"></script>
|
||||||
|
|
10
views/surf/_surf_iframe_injection.erb
Normal file
10
views/surf/_surf_iframe_injection.erb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<script>
|
||||||
|
function _nc_surf_page_overload() {
|
||||||
|
var ele = document.getElementsByTagName('a')
|
||||||
|
for(var i=0; i<ele.length; i++) {
|
||||||
|
if(ele[i].href.match(/^\w+:\/\//i) && !ele[i].href.match(/^.+\.neocities\.org/i))
|
||||||
|
ele[i].setAttribute('target', '_blank')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_nc_surf_page_overload()
|
||||||
|
</script>
|
Loading…
Add table
Reference in a new issue