Skip to content

Add check for page's referrer before auto download. #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ var Downloads = {
Downloads.observeGUIOSFilter();
Downloads.observePopState();
Downloads.filterGUIS();
Downloads.triggerAutoDownload();
},

triggerAutoDownload: function() {
var ref = document.referrer;
var src = $('#auto-download-link').attr('href');

if (this.shouldAutoDownload(ref, src)) {
$('.downloading .hide').show();
document.location = src;
}
},

shouldAutoDownload: function(ref, src) {
if (!ref || !src) {
return false;
}
return ref.indexOf(document.location.origin) === 0;
},

getOSFilter: function() {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/downloads.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@
display: none;
color: $orange;
}

.downloading .hide {
display: none;
}
6 changes: 2 additions & 4 deletions app/views/downloads/download_windows.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<div id="main">
<h1>Downloading Git</h1>
<div class="callout downloading">
<h3>Your download is starting...</h3>
<h3 class="hide">Your download is starting...</h3>
<p>
<%= raw "You are downloading the latest (<strong>#{@download.version.name}</strong>) <strong>#{@bitness}</strong> version of <strong>Git for Windows</strong>. This is the most recent <a href='#{@project_url}'>maintained build</a>. It was released <strong>#{time_ago_in_words @download.release_date} ago</strong>, on #{@download.release_date.strftime("%Y-%m-%d")}." %>
</p>
<p>
<%= raw "<strong>If your download hasn't started, <a href=\"#{@download.url}\">click here to download manually</a>.</strong>" %>
<%= raw "<strong><a id=\"auto-download-link\" href=\"#{@download.url}\">Click here to download manually</a><span class=\"hide\">, if your download hasn't started.</span></strong>" %>
</p>
<h3>Other Git for Windows downloads</h3>
<h4>Git for Windows Setup</h4>
Expand All @@ -34,7 +34,6 @@
<p class="small">
<%= raw "The current source code release is version <strong>#{@latest.name}</strong>. If you want the newer version, you can build it from <a href=\"#{@source_url}\">the source code</a>." %>
</p>
<iframe frameborder="0" height="1" src="<%= @download.url %>" width="1"></iframe>
</div>
<h2>Now What?</h2>
<p>
Expand Down Expand Up @@ -64,4 +63,3 @@
</li>
</ul>
</div>

6 changes: 2 additions & 4 deletions app/views/downloads/downloading.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
<div id="main">
<h1>Downloading Git</h1>
<div class="callout downloading">
<h3>Your download is starting...</h3>
<h3 class="hide">Your download is starting...</h3>
<p>
<%= raw "You are downloading version <strong>#{@download.version.name}</strong> of Git for the <strong>#{@platform.capitalize}</strong> platform. This is the most recent <a href='#{@project_url}'>maintained build</a> for this platform. It was released <strong>#{time_ago_in_words @download.release_date} ago</strong>, on #{@download.release_date.strftime("%Y-%m-%d")}." %>
</p>
<p>
<%= raw "<strong>If your download hasn't started, <a href=\"#{@download.url}\">click here to download manually</a>.</strong>" %>
<%= raw "<strong><a id=\"auto-download-link\" href=\"#{@download.url}\">Click here to download manually</a><span class=\"hide\">, if your download hasn't started.</span></strong>" %>
</p>
<p class="small">
<%= raw "The current source code release is version <strong>#{@latest.name}</strong>. If you want the newer version, you can build it from <a href=\"#{@source_url}\">the source code</a>." %>
</p>
</div>
<iframe frameborder="0" height="1" src="<%= @download.url %>" width="1"></iframe>
<h2>Now What?</h2>
<p>
Now that you have downloaded Git, it's time to start using it.
Expand Down Expand Up @@ -49,4 +48,3 @@
</li>
</ul>
</div>