[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] Add text to options page when flashproxy cookie is not present.
commit d0015faf0d56767cdbf8afa5462e908e81d1b0c6
Author: Alexandre Allaire <alexandre.allaire@xxxxxxxxxxxxxx>
Date: Fri Dec 21 13:55:41 2012 -0500
Add text to options page when flashproxy cookie is not present.
If the user visits the page with no cookie set, some text informs
him that he has not chosen a setting yet, and that his browser may
be used as a proxy depending on how the badge has been configured by
the website admin. The "configuration" in question is whether the badge is hosted
with the "cookierequired" query parameter or not.
---
proxy/options.html | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-
proxy/options.js | 68 -------------------------------------------------
2 files changed, 70 insertions(+), 70 deletions(-)
diff --git a/proxy/options.html b/proxy/options.html
index f5c03a3..1126850 100644
--- a/proxy/options.html
+++ b/proxy/options.html
@@ -56,7 +56,7 @@ JavaScript to change your options.
</noscript>
<div id="setting">
</div>
-<div id="buttons" style="display: none;">
+<div onclick="update_setting_text()" id="buttons" style="display: none;">
<button onclick="set_cookie_allowed()">Yes</button>
<button onclick="set_cookie_disallowed()">No</button>
</div>
@@ -67,6 +67,74 @@ in order to set flash proxy settings.
</p>
</div>
</div>
-<script type="text/javascript" src="options.js"></script>
+<script type="text/javascript">
+
+var COOKIE_NAME = "flashproxy-allow";
+/* max-age is not supported in IE. */
+var COOKIE_LIFETIME = "Thu, 01 Jan 2038 00:00:00 GMT";
+
+function set_cookie_allowed() {
+ document.cookie = COOKIE_NAME + "=1 ;path=/ ;expires=" + COOKIE_LIFETIME;
+}
+
+function set_cookie_disallowed() {
+ document.cookie = COOKIE_NAME + "=0 ;path=/ ;expires=" + COOKIE_LIFETIME;
+}
+
+/* Returns the value of the cookie, or undefined
+ if the cookie is not present. */
+function read_cookie() {
+ var split, name, value;
+ var cookies = document.cookie.split(";");
+
+ for (i in cookies) {
+ split = cookies[i].split("=");
+ name = split[0];
+ value = split[1];
+
+ while (name[0] === " ")
+ name = name.substr(1);
+ if (COOKIE_NAME === name)
+ return value;
+ }
+ return undefined;
+}
+
+/* Updates the text telling the user what his current setting is.*/
+function update_setting_text() {
+ var setting = document.getElementById("setting");
+ var prefix = "<p>Your current setting is: ";
+ var value = read_cookie();
+
+ if (value === undefined) {
+ setting.innerHTML = prefix + "unspecified. Your browser may or may not " +
+ "run as a proxy, depending on how the website " +
+ "administrator has configured the badge. Click " +
+ "the buttons below to change your setting.";
+ } else if (value === "1") {
+ setting.innerHTML = prefix + "use my browser as a proxy. " +
+ "Click no below to change your setting.</p>";
+ } else {
+ setting.innerHTML = prefix + "do not use my browser as a proxy. " +
+ "Click yes below to change your setting.</p>";
+ }
+}
+
+window.onload = function () {
+ if (navigator.cookieEnabled) {
+ var buttons = document.getElementById("buttons");
+ buttons.style.display = "block";
+ update_setting_text();
+ } else {
+ document.getElementById("cookies_disabled").style.display = "block";
+ /* Manually set the text here as otherwise it will refer to
+ the buttons, which don't show if cookies are disabled. */
+ document.getElementById("setting").innerHTML = "<p>Your current setting is: " +
+ "unspecified. Your browser may or may not " +
+ "run as a proxy, depending on how the website " +
+ "administrator has configured the badge.</p>";
+ }
+};
+</script>
</body>
</html>
diff --git a/proxy/options.js b/proxy/options.js
deleted file mode 100644
index c9a8713..0000000
--- a/proxy/options.js
+++ /dev/null
@@ -1,68 +0,0 @@
-/* This is the javascript for the opt-in page. It sets/deletes
- a cookie which controls whether the flashproxy javascript
- code should run or disable itself. */
-
-var COOKIE_NAME = "flashproxy";
-/* max-age is not supported in IE. */
-var COOKIE_LIFETIME = "Thu, 01 Jan 2020 00:00:00 GMT";
-
-/* This wrapper will attach events correctly in older
- versions of IE. */
-function add_event(elem, evt, handler) {
- if (elem.attachEvent)
- elem.attachEvent("on" + evt, handler);
- else
- elem.addEventListener(evt, handler);
-}
-
-function set_cookie_allowed() {
- document.cookie = COOKIE_NAME + "=1;path=/ ;expires=" + COOKIE_LIFETIME;
-}
-
-function set_cookie_disallowed() {
- document.cookie = COOKIE_NAME + "=0;path=/ ;expires=" + COOKIE_LIFETIME;
-}
-
-add_event(window, "load", function () {
-
- function cookie_present() {
- var cookies = document.cookie.split(";");
-
- for (i in cookies) {
- var name = cookies[i].split("=")[0];
-
- while (name[0] === " ")
- name = name.substr(1);
- if (COOKIE_NAME === name)
- return true;
- }
- return false;
- }
-
- /* Updates the text telling the user what his current setting is.*/
- function update_setting_text() {
- var setting = document.getElementById("setting");
- var prefix = "<p>Your current setting is: ";
-
- if (cookie_present()) {
- setting.innerHTML = prefix + "use my browser as a proxy. " +
- "Click no below to change your setting.</p>";
- } else {
- setting.innerHTML = prefix + "do not use my browser as a proxy. " +
- "Click yes below to change your setting.</p>";
- }
- }
-
- if (navigator.cookieEnabled) {
- var buttons = document.getElementById("buttons");
- add_event(buttons, "click", update_setting_text);
- buttons.style.display = "block";
- update_setting_text();
- } else {
- document.getElementById("cookies_disabled").style.display = "block";
- /* Manually set the text here as otherwise it will refer to
- the buttons, which don't show if cookies are disabled. */
- document.getElementById("setting").innerHTML = "<p>Your current setting is: " +
- "do not use my browser as a proxy.</p>";
- }
-});
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits