Browse Source

Place stylesheet selector as the last element, not the second last.

pull/40/head
Savetheinternet 13 years ago
parent
commit
4c145b28bc
  1. 393
      main.js
  2. 2
      templates/main.js

393
main.js

@ -1,197 +1,196 @@
function get_cookie(cookie_name) function get_cookie(cookie_name)
{ {
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
if(results) if(results)
return (unescape(results[2])); return (unescape(results[2]));
else else
return null; return null;
} }
function highlightReply(id) function highlightReply(id)
{ {
if(window.event !== undefined && event.which == 2) { if(window.event !== undefined && event.which == 2) {
// don't highlight on middle click // don't highlight on middle click
return true; return true;
} }
var divs = document.getElementsByTagName('div'); var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) for (var i = 0; i < divs.length; i++)
{ {
if (divs[i].className.indexOf('post') != -1) if (divs[i].className.indexOf('post') != -1)
divs[i].className = divs[i].className.replace(/highlighted/, ''); divs[i].className = divs[i].className.replace(/highlighted/, '');
} }
if (id) { if (id) {
post = document.getElementById('reply_'+id); post = document.getElementById('reply_'+id);
if(post) if(post)
post.className += ' highlighted'; post.className += ' highlighted';
} }
} }
function focusId(id) function focusId(id)
{ {
document.getElementById(id).focus(); document.getElementById(id).focus();
init(); init();
} }
function generatePassword() { function generatePassword() {
pass = ''; pass = '';
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+'; chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+';
for(i=0;i<8;i++) { for(i=0;i<8;i++) {
rnd = Math.floor(Math.random() * chars.length); rnd = Math.floor(Math.random() * chars.length);
pass += chars.substring(rnd,rnd + 1); pass += chars.substring(rnd,rnd + 1);
} }
return pass; return pass;
} }
function dopost(form) { function dopost(form) {
localStorage.name = form.name.value.replace(/ ##.+$/, ''); localStorage.name = form.name.value.replace(/ ##.+$/, '');
if(form.email.value != 'sage') if(form.email.value != 'sage')
localStorage.email = form.email.value; localStorage.email = form.email.value;
saved[document.location] = form.body.value; saved[document.location] = form.body.value;
sessionStorage.body = JSON.stringify(saved); sessionStorage.body = JSON.stringify(saved);
return form.body.value != "" || form.file.value != ""; return form.body.value != "" || form.file.value != "";
} }
function citeReply(id) { function citeReply(id) {
body = document.getElementById('body'); body = document.getElementById('body');
if (document.selection) { if (document.selection) {
// IE // IE
body.focus(); body.focus();
sel = document.selection.createRange(); sel = document.selection.createRange();
sel.text = '>>' + id + '\n'; sel.text = '>>' + id + '\n';
} else if (body.selectionStart || body.selectionStart == '0') { } else if (body.selectionStart || body.selectionStart == '0') {
// Mozilla // Mozilla
start = body.selectionStart; start = body.selectionStart;
end = body.selectionEnd; end = body.selectionEnd;
body.value = body.value.substring(0, start) + '>>' + id + '\n' + body.value.substring(end, body.value.length); body.value = body.value.substring(0, start) + '>>' + id + '\n' + body.value.substring(end, body.value.length);
} else { } else {
// ??? // ???
body.value += '>>' + id + '\n'; body.value += '>>' + id + '\n';
} }
} }
var selectedstyle = 'Yotsuba B'; var selectedstyle = 'Yotsuba B';
var styles = [ var styles = [
['Yotsuba B', '/Tinyboard/stylesheets/default.css'], ['Yotsuba B', '/Tinyboard/stylesheets/default.css'],
['Yotsuba', '/Tinyboard/stylesheets/yotsuba.css'] ['Yotsuba', '/Tinyboard/stylesheets/yotsuba.css']
]; ];
var saved = {}; var saved = {};
function changeStyle(x) { function changeStyle(x) {
localStorage.stylesheet = styles[x][1]; localStorage.stylesheet = styles[x][1];
document.getElementById('stylesheet').href = styles[x][1]; document.getElementById('stylesheet').href = styles[x][1];
selectedstyle = styles[x][0]; selectedstyle = styles[x][0];
} }
if(localStorage.stylesheet) { if(localStorage.stylesheet) {
for(x=0;x<styles.length;x++) { for(x=0;x<styles.length;x++) {
if(styles[x][1] == localStorage.stylesheet) { if(styles[x][1] == localStorage.stylesheet) {
changeStyle(x); changeStyle(x);
break; break;
} }
} }
} }
function rememberStuff() { function rememberStuff() {
if(document.forms.post) { if(document.forms.post) {
if(!localStorage.password) if(!localStorage.password)
localStorage.password = generatePassword(); localStorage.password = generatePassword();
document.forms.post.password.value = localStorage.password; document.forms.post.password.value = localStorage.password;
if(localStorage.name) if(localStorage.name)
document.forms.post.name.value = localStorage.name; document.forms.post.name.value = localStorage.name;
if(localStorage.email) if(localStorage.email)
document.forms.post.email.value = localStorage.email; document.forms.post.email.value = localStorage.email;
if (window.location.hash.indexOf('q') == 1) if (window.location.hash.indexOf('q') == 1)
citeReply(window.location.hash.substring(2)); citeReply(window.location.hash.substring(2));
if(sessionStorage.body) { if(sessionStorage.body) {
saved = JSON.parse(sessionStorage.body); saved = JSON.parse(sessionStorage.body);
if(get_cookie('serv')) { if(get_cookie('serv')) {
// Remove successful posts // Remove successful posts
successful = JSON.parse(get_cookie('serv')); successful = JSON.parse(get_cookie('serv'));
for (var url in successful) { for (var url in successful) {
saved[url] = null; saved[url] = null;
} }
sessionStorage.body = JSON.stringify(saved); sessionStorage.body = JSON.stringify(saved);
document.cookie = 'serv={};expires=0;path=/;'; document.cookie = 'serv={};expires=0;path=/;';
} }
if(saved[document.location]) { if(saved[document.location]) {
document.forms.post.body.value = saved[document.location]; document.forms.post.body.value = saved[document.location];
} }
} }
if(localStorage.body) { if(localStorage.body) {
document.forms.post.body.value = localStorage.body; document.forms.post.body.value = localStorage.body;
localStorage.body = ''; localStorage.body = '';
} }
} }
} }
function init_expanding() { function init_expanding() {
link = document.getElementsByTagName('a'); link = document.getElementsByTagName('a');
for ( i in link ) { for ( i in link ) {
if(typeof link[i] == "object" && link[i].childNodes[0].src && link[i].className != 'file') { if(typeof link[i] == "object" && link[i].childNodes[0].src && link[i].className != 'file') {
link[i].onclick = function(e) { link[i].onclick = function(e) {
if(e.which == 2) { if(e.which == 2) {
return true; return true;
} }
if(!this.tag) { if(!this.tag) {
this.tag = this.childNodes[0].src; this.tag = this.childNodes[0].src;
this.childNodes[0].src = this.href; this.childNodes[0].src = this.href;
this.childNodes[0].style.width = 'auto'; this.childNodes[0].style.width = 'auto';
this.childNodes[0].style.height = 'auto'; this.childNodes[0].style.height = 'auto';
this.childNodes[0].style.opacity = '0.4'; this.childNodes[0].style.opacity = '0.4';
this.childNodes[0].style.filter = 'alpha(opacity=40)'; this.childNodes[0].style.filter = 'alpha(opacity=40)';
this.childNodes[0].onload = function() { this.childNodes[0].onload = function() {
this.style.opacity = '1'; this.style.opacity = '1';
this.style.filter = ''; this.style.filter = '';
} }
} else { } else {
this.childNodes[0].src = this.tag; this.childNodes[0].src = this.tag;
this.childNodes[0].style.width = 'auto'; this.childNodes[0].style.width = 'auto';
this.childNodes[0].style.height = 'auto'; this.childNodes[0].style.height = 'auto';
this.tag = ''; this.tag = '';
} }
return false; return false;
} }
} }
} }
} }
function init() function init()
{ {
newElement = document.createElement('div'); newElement = document.createElement('div');
newElement.className = 'styles'; newElement.className = 'styles';
for(x=0;x<styles.length;x++) { for(x=0;x<styles.length;x++) {
style = document.createElement('a'); style = document.createElement('a');
style.innerHTML = '[' + styles[x][0] + ']'; style.innerHTML = '[' + styles[x][0] + ']';
style.href = 'javascript:changeStyle(' + x + ');'; style.href = 'javascript:changeStyle(' + x + ');';
if(selectedstyle == styles[x][0]) if(selectedstyle == styles[x][0])
style.className = 'selected'; style.className = 'selected';
newElement.appendChild(style); newElement.appendChild(style);
} }
document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild) document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling)
if(document.forms.postcontrols) { if(document.forms.postcontrols) {
document.forms.postcontrols.password.value = localStorage.password; document.forms.postcontrols.password.value = localStorage.password;
} }
if(window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) if(window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1))
highlightReply(window.location.hash.substring(1)); highlightReply(window.location.hash.substring(1));
init_expanding(); init_expanding();
} }
var RecaptchaOptions = { var RecaptchaOptions = {
theme : 'clean' theme : 'clean'
}; };
window.onload = init; window.onload = init;

2
templates/main.js

@ -177,7 +177,7 @@ function init()
newElement.appendChild(style); newElement.appendChild(style);
} }
document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild) document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling)
if(document.forms.postcontrols) { if(document.forms.postcontrols) {
document.forms.postcontrols.password.value = localStorage.password; document.forms.postcontrols.password.value = localStorage.password;

Loading…
Cancel
Save