Skip to content

Commit

Permalink
Auto install the chrome extension on settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
RossBrunton committed Sep 14, 2017
1 parent 51bce92 commit f14f53b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bmat/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ def analytics_and_ads(request):
out["ad_slot_bottom"] = settings.AD_SLOT_BOTTOM

return out

def add_webstore_url(request):
return {"webstore_url":settings.CHROME_EXTENSION_WEBSTORE}
1 change: 1 addition & 0 deletions bmat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"users.context_processors.theme",
"bmat.context_processors.analytics_and_ads",
"tags.context_processors.pinned_tags",
"bmat.context_processors.add_webstore_url",
)

ROOT_URLCONF = 'bmat.urls'
Expand Down
4 changes: 4 additions & 0 deletions bmat/settings_local.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ ANALYTICS_CODE = ""
AD_CLIENT = ""
AD_SLOT_TOP = ""
AD_SLOT_BOTTOM = ""

# URL of the webstore for the chrome extension (leave blank not to use it)
# Must be in the form https://chrome.google.com/webstore/detail/appid
CHROME_EXTENSION_WEBSTORE = "";
12 changes: 12 additions & 0 deletions bmat/static/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ window.bmatFn = function() {
}
}, "html");
});

// Browser detection and specific stuff

// Chrome extension
if("chrome" in window && "webstore" in window.chrome) {
$(".chrome-extension").show();
$("#chrome-extension-install").on("click", function() {
chrome.webstore.install(undefined, function() {}, function(msg) {
console.error("Extension install failed: %s", msg);
});
});
}
};

// These two are ran on page load
Expand Down
1 change: 1 addition & 0 deletions bmat/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>{% block title %}No Title{% endblock %}</title>
<link rel='stylesheet' href='{% static "styles.css" %}'/>
<link rel='stylesheet' href='{% static "theme_"|add:theme|add:".css" %}'/>
<link rel='chrome-webstore-item' href='{{ webstore_url }}'>

{% if analytics_code %}
<script>
Expand Down
8 changes: 8 additions & 0 deletions users/templates/users/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@

<button><a href='{% url "autotags:home" %}' style='color:inherit'>Configure Autotag Settings</a></button>
</div>

{% if webstore_url %}
<div class='box center hidden chrome-extension'>
You can install a browser extension that allows you to add bookmarks directly from a page.<br/><br/>

<button id='chrome-extension-install'>BMAT Extension</button>
</div>
{% endif %}
</section>
</div>

Expand Down

0 comments on commit f14f53b

Please sign in to comment.