commit 36d0773ee9197c992819d1fbbb1b63e95e298921 Author: David Fifield david@bamsoftware.com Date: Sun Oct 23 00:08:33 2011 -0700
Use an iframe for badge embedding.
Dan told me: "Sites will likely want to iframe the script so as not to give it control of the enclosing page." This makes sense. So provide a public embed.html, and add a sample iframe HTML snippet to easily include it. --- README | 4 +- embed.html | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ flashproxy.js | 141 -------------------------------------------------- 3 files changed, 162 insertions(+), 144 deletions(-)
diff --git a/README b/README index 34d1e1d..82e881c 100644 --- a/README +++ b/README @@ -152,9 +152,7 @@ wait a few minutes. It can take a while to download relay descriptors.
Paste in this HTML where you want the badge to appear:
-<script type="text/javascript" src="https://crypto.stanford.edu/flashproxy/flashproxy.js"></script> - -It will be inserted as a span element with the id "flashproxy-badge". +<iframe src="//crypto.stanford.edu/flashproxy/embed.html" width="70px" height="23px" frameBorder="0" scrolling="0"></iframe>
== For developers diff --git a/embed.html b/embed.html new file mode 100644 index 0000000..fc1fe6d --- /dev/null +++ b/embed.html @@ -0,0 +1,161 @@ +<!DOCTYPE html> +<html> +<head> +<script type="text/javascript"> +/* Are circumstances such that we should self-disable and not be a + proxy? We take a best-effort guess as to whether this device runs on + a battery or the data transfer might be expensive. + + Matching mobile User-Agents is complex; but we only need to match + those devices that can also run a recent version of Adobe Flash, + which is a subset of this list: + https://secure.wikimedia.org/wikipedia/en/wiki/Adobe_Flash_Player#Mobile_ope... + + Other resources: + http://www.zytrax.com/tech/web/mobile_ids.html + http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-... + http://search.cpan.org/~cmanley/Mobile-UserAgent-1.05/lib/Mobile/UserAgent.p... +*/ +function flashproxy_should_disable() +{ + var ua; + + ua = window.navigator.userAgent; + if (ua != null) { + const UA_LIST = [ + /\bmobile\b/i, + /\bandroid\b/i, + /\bopera mobi\b/i, + ]; + + for (var i = 0; i < UA_LIST.length; i++) { + var re = UA_LIST[i]; + + if (ua.match(re)) { + return true; + } + } + } + + return false; +} + +/* Create and return a DOM fragment: +<span id=BADGE_ID> +<a href=FLASHPROXY_INFO_URL> + child +</a> +</span> +*/ +function flashproxy_make_container(child) +{ + const BADGE_ID = "flashproxy-badge"; + const FLASHPROXY_INFO_URL = "https://crypto.stanford.edu/flashproxy/"; + + var container; + var a; + + container = document.createElement("span"); + container.setAttribute("id", "flashproxy-badge"); + a = document.createElement("a"); + a.setAttribute("href", FLASHPROXY_INFO_URL); + a.appendChild(child) + container.appendChild(a); + + return container; +} + +/* Create and return a DOM fragment: +<object width=WIDTH height=HEIGHT> + <param name="movie" value=SWFCAT_URL> + <param name="flashvars" value=FLASHVARS> + <embed src=SWFCAT_URL width=WIDTH height=HEIGHT flashvars=FLASHVARS></embed> +</object> +*/ +function flashproxy_make_badge() +{ + const WIDTH = 70; + const HEIGHT = 23; + const FLASHVARS = ""; + const SWFCAT_URL = "https://crypto.stanford.edu/flashproxy/swfcat.swf"; + + var object; + var param; + var embed; + + object = document.createElement("object"); + object.setAttribute("width", WIDTH); + object.setAttribute("height", HEIGHT); + + param = document.createElement("param"); + param.setAttribute("name", "movie"); + param.setAttribute("value", SWFCAT_URL); + object.appendChild(param); + param = document.createElement("param"); + param.setAttribute("name", "flashvars"); + param.setAttribute("value", FLASHVARS); + object.appendChild(param); + + embed = document.createElement("embed"); + embed.setAttribute("src", SWFCAT_URL); + embed.setAttribute("width", WIDTH); + embed.setAttribute("height", HEIGHT); + embed.setAttribute("flashvars", FLASHVARS); + object.appendChild(embed); + + return object; +} + +/* Create and return a non-functional placeholder badge DOM fragment: +<img src=BADGE_IMAGE_URL border="0"> +*/ +function flashproxy_make_dummy_badge() +{ + const BADGE_IMAGE_URL = "https://crypto.stanford.edu/flashproxy/badge.png"; + + var img; + + img = document.createElement("img"); + img.setAttribute("src", BADGE_IMAGE_URL); + img.setAttribute("border", 0); + + return img; +} + +function flashproxy_badge_insert() +{ + var badge; + var e; + + if (flashproxy_should_disable()) { + badge = flashproxy_make_dummy_badge(); + } else { + badge = flashproxy_make_badge(); + } + + /* http://intertwingly.net/blog/2006/11/10/Thats-Not-Write for this trick to + insert right after the <script> element in the DOM. */ + e = document; + while (e.lastChild && e.lastChild.nodeType == 1) { + e = e.lastChild; + } + e.parentNode.appendChild(flashproxy_make_container(badge)); +} +</script> + +<style type="text/css"> +body { + margin: 0; + padding: 0; +} +</style> +</head> +<body> +<script type="text/javascript"> +flashproxy_badge_insert(); +</script> +<noscript> +<a href="https://crypto.stanford.edu/flashproxy/" target="_parent"><img src="badge.png" border="0" alt="I support Internet freedom"></a> +</noscript> +</body> +</html> diff --git a/flashproxy.js b/flashproxy.js deleted file mode 100644 index a16edb3..0000000 --- a/flashproxy.js +++ /dev/null @@ -1,141 +0,0 @@ -/* Are circumstances such that we should self-disable and not be a - proxy? We take a best-effort guess as to whether this device runs on - a battery or the data transfer might be expensive. - - Matching mobile User-Agents is complex; but we only need to match - those devices that can also run a recent version of Adobe Flash, - which is a subset of this list: - https://secure.wikimedia.org/wikipedia/en/wiki/Adobe_Flash_Player#Mobile_ope... - - Other resources: - http://www.zytrax.com/tech/web/mobile_ids.html - http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-... - http://search.cpan.org/~cmanley/Mobile-UserAgent-1.05/lib/Mobile/UserAgent.p... -*/ -function flashproxy_should_disable() -{ - var ua; - - ua = window.navigator.userAgent; - if (ua != null) { - const UA_LIST = [ - /\bmobile\b/i, - /\bandroid\b/i, - /\bopera mobi\b/i, - ]; - - for (var i = 0; i < UA_LIST.length; i++) { - var re = UA_LIST[i]; - - if (ua.match(re)) { - return true; - } - } - } - - return false; -} - -/* Create and return a DOM fragment: -<span id=BADGE_ID> -<a href=FLASHPROXY_INFO_URL> - child -</a> -</span> -*/ -function flashproxy_make_container(child) -{ - const BADGE_ID = "flashproxy-badge"; - const FLASHPROXY_INFO_URL = "https://crypto.stanford.edu/flashproxy/"; - - var container; - var a; - - container = document.createElement("span"); - container.setAttribute("id", "flashproxy-badge"); - a = document.createElement("a"); - a.setAttribute("href", FLASHPROXY_INFO_URL); - a.appendChild(child) - container.appendChild(a); - - return container; -} - -/* Create and return a DOM fragment: -<object width=WIDTH height=HEIGHT> - <param name="movie" value=SWFCAT_URL> - <param name="flashvars" value=FLASHVARS> - <embed src=SWFCAT_URL width=WIDTH height=HEIGHT flashvars=FLASHVARS></embed> -</object> -*/ -function flashproxy_make_badge() -{ - const WIDTH = 70; - const HEIGHT = 23; - const FLASHVARS = ""; - const SWFCAT_URL = "https://crypto.stanford.edu/flashproxy/swfcat.swf"; - - var object; - var param; - var embed; - - object = document.createElement("object"); - object.setAttribute("width", WIDTH); - object.setAttribute("height", HEIGHT); - - param = document.createElement("param"); - param.setAttribute("name", "movie"); - param.setAttribute("value", SWFCAT_URL); - object.appendChild(param); - param = document.createElement("param"); - param.setAttribute("name", "flashvars"); - param.setAttribute("value", FLASHVARS); - object.appendChild(param); - - embed = document.createElement("embed"); - embed.setAttribute("src", SWFCAT_URL); - embed.setAttribute("width", WIDTH); - embed.setAttribute("height", HEIGHT); - embed.setAttribute("flashvars", FLASHVARS); - object.appendChild(embed); - - return object; -} - -/* Create and return a non-functional placeholder badge DOM fragment: -<img src=BADGE_IMAGE_URL border="0"> -*/ -function flashproxy_make_dummy_badge() -{ - const BADGE_IMAGE_URL = "https://crypto.stanford.edu/flashproxy/badge.png"; - - var img; - - img = document.createElement("img"); - img.setAttribute("src", BADGE_IMAGE_URL); - img.setAttribute("border", 0); - - return img; -} - -function flashproxy_badge_insert() -{ - var badge; - var e; - - if (flashproxy_should_disable()) { - badge = flashproxy_make_dummy_badge(); - } else { - badge = flashproxy_make_badge(); - } - - /* http://intertwingly.net/blog/2006/11/10/Thats-Not-Write for this trick to - insert right after the <script> element in the DOM. */ - e = document; - while (e.lastChild && e.lastChild.nodeType == 1) { - e = e.lastChild; - } - e.parentNode.appendChild(flashproxy_make_container(badge)); -} - -flashproxy_badge_insert();