Get favicon switching working, reduce redundancy

This commit is contained in:
Zixaphir 2014-01-11 10:44:33 -07:00
parent 8c7677e405
commit 9d6e29616d
3 changed files with 38 additions and 8 deletions

View File

@ -11997,7 +11997,7 @@
g.BOARD = new Board(boardID);
req = null;
onload = function(e) {
var board, mainStyleSheet, newStyleSheet, style, type, _ref;
var board, findStyle, mainStyleSheet, newStyleSheet, sfw, style, type, _ref;
if (e.type === 'abort') {
req.onloadend = null;
return;
@ -12030,10 +12030,20 @@
return;
}
Navigate.updateTitle(board);
_ref = board.ws_board ? [(d.cookie.match(/ws\_style\=([^;]+)/) || ['', 'Yotsuba B New'])[1], 'ws_style'] : [(d.cookie.match(/nws\_style\=([^;]+)/) || ['', 'Yotsuba New'])[1], 'nws_style'], style = _ref[0], type = _ref[1];
sfw = !!board.ws_board;
findStyle = function(regex, base) {
var style;
style = d.cookie.match(regex);
return (style ? style[1] : base);
};
_ref = sfw ? [findStyle(/ws\_style\=([^;]+)/, 'Yotsuba B New'), 'ws_style'] : [findStyle(/nws\_style\=([^;]+)/, 'Yotsuba New'), 'nws_style'], style = _ref[0], type = _ref[1];
$.globalEval("var style_group = '" + type + "'");
mainStyleSheet = $('link[title=switch]', d.head);
newStyleSheet = $("link[title='" + style + "']", d.head);
Favicon.SFW = sfw;
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
$.add(d.head, Favicon.el);
Favicon["switch"]();
mainStyleSheet.href = newStyleSheet.href;
return Main.setClass();
};

View File

@ -11986,7 +11986,7 @@
g.BOARD = new Board(boardID);
req = null;
onload = function(e) {
var board, mainStyleSheet, newStyleSheet, style, type, _ref;
var board, findStyle, mainStyleSheet, newStyleSheet, sfw, style, type, _ref;
if (e.type === 'abort') {
req.onloadend = null;
return;
@ -12019,10 +12019,20 @@
return;
}
Navigate.updateTitle(board);
_ref = board.ws_board ? [(d.cookie.match(/ws\_style\=([^;]+)/) || ['', 'Yotsuba B New'])[1], 'ws_style'] : [(d.cookie.match(/nws\_style\=([^;]+)/) || ['', 'Yotsuba New'])[1], 'nws_style'], style = _ref[0], type = _ref[1];
sfw = !!board.ws_board;
findStyle = function(regex, base) {
var style;
style = d.cookie.match(regex);
return (style ? style[1] : base);
};
_ref = sfw ? [findStyle(/ws\_style\=([^;]+)/, 'Yotsuba B New'), 'ws_style'] : [findStyle(/nws\_style\=([^;]+)/, 'Yotsuba New'), 'nws_style'], style = _ref[0], type = _ref[1];
$.globalEval("var style_group = '" + type + "'");
mainStyleSheet = $('link[title=switch]', d.head);
newStyleSheet = $("link[title='" + style + "']", d.head);
Favicon.SFW = sfw;
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
$.add(d.head, Favicon.el);
Favicon["switch"]();
mainStyleSheet.href = newStyleSheet.href;
return Main.setClass();
};

View File

@ -135,11 +135,16 @@ Navigate =
return unless board
Navigate.updateTitle board
[style, type] = if board.ws_board then [
(d.cookie.match(/ws\_style\=([^;]+)/) or ['', 'Yotsuba B New'])[1]
sfw = !!board.ws_board
findStyle = (regex, base) ->
style = d.cookie.match regex
return (if style then style[1] else base)
[style, type] = if sfw then [
findStyle /ws\_style\=([^;]+)/, 'Yotsuba B New'
'ws_style'
] else [
(d.cookie.match(/nws\_style\=([^;]+)/) or ['', 'Yotsuba New'])[1]
findStyle /nws\_style\=([^;]+)/, 'Yotsuba New'
'nws_style'
]
@ -148,7 +153,12 @@ Navigate =
mainStyleSheet = $ 'link[title=switch]', d.head
newStyleSheet = $ "link[title='#{style}']", d.head
mainStyleSheet.href = newStyleSheet.href
Favicon.SFW = sfw
Favicon.el.href = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico"
$.add d.head, Favicon.el # Changing the href alone doesn't update the icon on Firefox
Favicon.switch()
mainStyleSheet.href = newStyleSheet.href
Main.setClass()