summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-04-06 18:31:26 +1000
committerSavetheinternet <savetheinternet@n0v4.com>2011-04-06 18:31:26 +1000
commit08bbd3f9127204aa4bc8be18fdc6ca6d68d88ff1 (patch)
tree28c204c3907e70f0e49620658f8736d9258c4dce /templates
parent10bd465ea366023769b047050d48b0e81d513b9b (diff)
Post saving/cache and Google Analytics integration
Diffstat (limited to 'templates')
-rw-r--r--templates/main.js42
1 files changed, 40 insertions, 2 deletions
diff --git a/templates/main.js b/templates/main.js
index 7bf5b6d9..296e5c07 100644
--- a/templates/main.js
+++ b/templates/main.js
@@ -1,3 +1,12 @@
+function get_cookie(cookie_name)
+{
+ var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
+ if(results)
+ return (unescape(results[2]));
+ else
+ return null;
+}
+
function highlightReply(id)
{
var divs = document.getElementsByTagName('div');
@@ -20,7 +29,7 @@ function focusId(id)
function generatePassword() {
pass = '';
- chars = '{config[genpassword_chars]}';
+ chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+';
for(i=0;i<8;i++) {
rnd = Math.floor(Math.random() * chars.length);
pass += chars.substring(rnd,rnd + 1);
@@ -33,6 +42,9 @@ function dopost(form) {
if(form.email.value != 'sage')
localStorage.email = form.email.value;
+ saved[document.location] = form.body.value;
+ sessionStorage.body = JSON.stringify(saved);
+
return form.body.value != "" || (typeof form.thread != "undefined" && form.file.value != "");
}
function citeReply(id) {
@@ -44,6 +56,7 @@ var styles = [
{stylesheets:['{stylesheets[name]}', '{stylesheets[uri]}']{!%last?,
}}
];
+var saved = {};
function changeStyle(x) {
localStorage.stylesheet = styles[x][1];
@@ -92,6 +105,28 @@ function init()
if(localStorage.email)
document.getElementsByTagName('form')[0].email.value = localStorage.email;
+
+ if(sessionStorage.body) {
+ saved = JSON.parse(sessionStorage.body);
+ if(get_cookie('{config[cookies][js]}')) {
+ // Remove successful posts
+ successful = JSON.parse(get_cookie('{config[cookies][js]}'));
+ for (var url in successful) {
+ saved[url] = null;
+ }
+ sessionStorage.body = JSON.stringify(saved);
+
+ document.cookie = '{config[cookies][js]}={};expires=0;path=/;';
+ }
+ if(saved[document.location]) {
+ document.getElementsByTagName('form')[0].body.value = saved[document.location];
+ }
+ }
+
+ if(localStorage.body) {
+ document.getElementsByTagName('form')[0].body.value = localStorage.body;
+ localStorage.body = '';
+ }
link = document.getElementsByTagName('a');
for ( i in link ) {
if(typeof link[i] == "object" && link[i].childNodes[0].src) {
@@ -120,4 +155,7 @@ function init()
}
}
-window.onload = init; \ No newline at end of file
+window.onload = init;
+{config[google_analytics]?
+
+var _gaq = _gaq || [];_gaq.push(['_setAccount', '{config[google_analytics]}']);_gaq.push(['_setDomainName', 'none']);_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();} \ No newline at end of file