Fuck that.

This commit is contained in:
Nicolas Stepien 2013-02-11 00:15:10 +01:00
parent 8b836aec8d
commit 64cd4a9043
2 changed files with 19 additions and 118 deletions

View File

@ -20,7 +20,7 @@
// @icon https://github.com/MayhemYDG/4chan-x/raw/stable/img/icon.gif // @icon https://github.com/MayhemYDG/4chan-x/raw/stable/img/icon.gif
// ==/UserScript== // ==/UserScript==
/* 4chan X Alpha - Version 3.0.0 - 2013-02-10 /* 4chan X Alpha - Version 3.0.0 - 2013-02-11
* http://mayhemydg.github.com/4chan-x/ * http://mayhemydg.github.com/4chan-x/
* *
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com> * Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
@ -932,33 +932,24 @@
}); });
$.on(toggleBar, 'click', this.toggleBar); $.on(toggleBar, 'click', this.toggleBar);
$.prepend(headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]); $.prepend(headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]);
try { $.asap((function() {
this.setBoardList();
} catch (err) {
Main.handleErrors({
message: '"Header (board list)" crashed.',
error: err
});
}
return $.asap((function() {
return d.body; return d.body;
}), function() { }), function() {
return $.prepend(d.body, Header.headerEl); return $.prepend(d.body, Header.headerEl);
}); });
return $.asap((function() {
return $.id('boardNavDesktop');
}), this.setBoardList);
}, },
setBoardList: function() { setBoardList: function() {
Get.boardsConfig(function(boardsConfig) { var a, nav;
return $('.board-title', Header.headerEl).textContent = boardsConfig[g.BOARD].title; if (nav = $.id('boardNavDesktop')) {
}); if (a = $("a[href$='/" + g.BOARD + "/']", nav)) {
return $.ready(function() { a.className = 'current';
var nav, _ref; $('.board-title', Header.headerEl).textContent = a.title;
if (nav = $.id('boardNavDesktop')) {
if ((_ref = $("a[href$='/" + g.BOARD + "/']", nav)) != null) {
_ref.className = 'current';
}
return $.add($('.board-list', Header.headerEl), Array.prototype.slice.call(nav.childNodes));
} }
}); return $.add($('.board-list', Header.headerEl), Array.prototype.slice.call(nav.childNodes));
}
}, },
toggleBoardList: function() { toggleBoardList: function() {
var headerEl, node, showBoardList; var headerEl, node, showBoardList;
@ -2418,55 +2409,6 @@
}; };
Get = { Get = {
boardsConfig: (function() {
var boardsConfig, callbacks, parseBoardsConfig;
boardsConfig = null;
callbacks = [];
parseBoardsConfig = function() {
var board, boardName, callback, _i, _j, _len, _len1, _ref;
if (this.status !== 200) {
return;
}
boardsConfig = {};
_ref = JSON.parse(this.response).boards;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
board = _ref[_i];
boardName = board.board;
delete board.board;
boardsConfig[boardName] = board;
}
for (_j = 0, _len1 = callbacks.length; _j < _len1; _j++) {
callback = callbacks[_j];
callback(boardsConfig);
}
callbacks = null;
boardsConfig.lastModified = this.getResponseHeader('Last-Modified');
return $.set('boardsConfig', boardsConfig);
};
return function(cb) {
var lastModified;
if (boardsConfig) {
cb(boardsConfig);
return;
}
if (boardsConfig = $.get('boardsConfig', null)) {
cb(boardsConfig);
lastModified = boardsConfig.lastModified;
} else {
if (callbacks.push(cb) > 1) {
return;
}
lastModified = 0;
}
return $.ajax('//api.4chan.org/boards.json', {
onloadend: parseBoardsConfig
}, {
headers: {
'If-Modified-Since': lastModified
}
});
};
})(),
postFromRoot: function(root) { postFromRoot: function(root) {
var board, index, link, post, postID; var board, index, link, post, postID;
link = $('a[title="Highlight this post"]', root); link = $('a[title="Highlight this post"]', root);

View File

@ -37,24 +37,17 @@ Header =
$.prepend headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar] $.prepend headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]
try
@setBoardList()
catch err
Main.handleErrors
message: '"Header (board list)" crashed.'
error: err
$.asap (-> d.body), -> $.asap (-> d.body), ->
$.prepend d.body, Header.headerEl $.prepend d.body, Header.headerEl
$.asap (-> $.id 'boardNavDesktop'), @setBoardList
setBoardList: -> setBoardList: ->
Get.boardsConfig (boardsConfig) -> if nav = $.id 'boardNavDesktop'
$('.board-title', Header.headerEl).textContent = boardsConfig[g.BOARD].title if a = $ "a[href$='/#{g.BOARD}/']", nav
$.ready -> a.className = 'current'
if nav = $.id 'boardNavDesktop' $('.board-title', Header.headerEl).textContent = a.title
$("a[href$='/#{g.BOARD}/']", nav)?.className = 'current' $.add $('.board-list', Header.headerEl),
$.add $('.board-list', Header.headerEl), Array::slice.call nav.childNodes
Array::slice.call nav.childNodes
toggleBoardList: -> toggleBoardList: ->
node = @firstElementChild.firstChild node = @firstElementChild.firstChild
@ -1345,40 +1338,6 @@ Build =
container container
Get = Get =
boardsConfig: (->
boardsConfig = null
callbacks = []
parseBoardsConfig = ->
return if @status isnt 200
boardsConfig = {}
for board in JSON.parse(@response).boards
boardName = board.board
delete board.board
boardsConfig[boardName] = board
for callback in callbacks
callback boardsConfig
callbacks = null
boardsConfig.lastModified = @getResponseHeader 'Last-Modified'
$.set 'boardsConfig', boardsConfig
(cb) ->
# Configs were already loaded previously, callback and stop.
if boardsConfig
cb boardsConfig
return
# Load configs, callback, check for updates.
if boardsConfig = $.get 'boardsConfig', null
cb boardsConfig
lastModified = boardsConfig.lastModified
else
return if callbacks.push(cb) > 1
lastModified = 0
$.ajax '//api.4chan.org/boards.json', onloadend: parseBoardsConfig,
headers: 'If-Modified-Since': lastModified
)()
postFromRoot: (root) -> postFromRoot: (root) ->
link = $ 'a[title="Highlight this post"]', root link = $ 'a[title="Highlight this post"]', root
board = link.pathname.split('/')[1] board = link.pathname.split('/')[1]