- cca085e60090ca21edf0dee6aa012fc4c949809a start of import/export - f816da146c32f010476872d15b58ec8301b9fdf2 start of changing stuff until I can get a bundle - c92adde147792356ff206107b2311590e8b2c054 first bundle without errors - e652dd2b785e355e0ac33566da7eaaaa19c7c539 Bundling works with ts files - 60fdb2539a757ca2f66258b21adf81246873893f meta info in compilation - 8ccae783cbf65ac186d5669dedd9f945f7608694 new build doesn't cause errors on page load as userscript - 6fa11c42a05572779870f94b7ef4ea8dac373450 work in progress: load userscript in browser and fix bugs - b15c557d483de544a38a28cb78f25139d1d8421f migrated yotsuba templates to plain js the old templates caused some variable be in a wrong scope after decaffeinate, causing them to be unreadable from the old template the old templates caused some variable be in a wrong scope after decaffeinate, causing them to be unreadable from the old template - 9d763e852fde74808ca14d5a8d6be45f51ae2765 update readme - 924eda8268bcfc4f1c0a83062ecd1d0d65bd92aa added more imports, and now the circular dependencies are haunting me - ddd2d23315d801c7deaa28313833e667698aadd3 jsx templates for escaped strings, more bug fixed from circular dependencies - fee484dd447820d908c77b1e9d31235ab95a481c some fixes, clarify jsx - e1d01d02eba5db2f604a5df786c525e95f32a2f9 Unpacked extension more fixes - 97d9090b712d20f7d851c82af84c65060f1a9c6e fixed class on post that caused catalog to appear empty - 96a2c7b4a1e69f5812d1e53b2e4c90f6d8447b02 A child class that's not supposed to run the parents constructor? That needs a workaround in es6 classes. - fc06b4e1b2769550d4c69377b84d3ccacdb2e013 changed jsx to make the tests pass - 7b317b2a0feabe8caa547c76baf0c908b21592f1 revert archive and banners to json
107 lines
2.9 KiB
JavaScript
107 lines
2.9 KiB
JavaScript
import Notice from "../classes/Notice";
|
|
import { g, Conf } from "../globals/globals";
|
|
import $ from "../platform/$";
|
|
import { dict, HOUR } from "../platform/helpers";
|
|
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS104: Avoid inline assignments
|
|
* DS205: Consider reworking code to avoid use of IIFEs
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
*/
|
|
var BoardConfig = {
|
|
cbs: [],
|
|
|
|
init() {
|
|
let middle;
|
|
if (g.SITE.software !== 'yotsuba') { return; }
|
|
const now = Date.now();
|
|
if (now - (2 * HOUR) >= ((middle = Conf['boardConfig'].lastChecked || 0)) || middle > now) {
|
|
return $.ajax(`${location.protocol}//a.4cdn.org/boards.json`,
|
|
{onloadend: this.load});
|
|
} else {
|
|
const {boards} = Conf['boardConfig'];
|
|
return this.set(boards);
|
|
}
|
|
},
|
|
|
|
load() {
|
|
let boards;
|
|
if ((this.status === 200) && this.response && this.response.boards) {
|
|
boards = dict();
|
|
for (var board of this.response.boards) {
|
|
boards[board.board] = board;
|
|
}
|
|
$.set('boardConfig', {boards, lastChecked: Date.now()});
|
|
} else {
|
|
({boards} = Conf['boardConfig']);
|
|
const err = (() => { switch (this.status) {
|
|
case 0: return 'Connection Error';
|
|
case 200: return 'Invalid Data';
|
|
default: return `Error ${this.statusText} (${this.status})`;
|
|
} })();
|
|
new Notice('warning', `Failed to load board configuration. ${err}`, 20);
|
|
}
|
|
return BoardConfig.set(boards);
|
|
},
|
|
|
|
set(boards) {
|
|
this.boards = boards;
|
|
for (var ID in g.boards) {
|
|
var board = g.boards[ID];
|
|
board.config = this.boards[ID] || {};
|
|
}
|
|
for (var cb of this.cbs) {
|
|
$.queueTask(cb);
|
|
}
|
|
},
|
|
|
|
ready(cb) {
|
|
if (this.boards) {
|
|
return cb();
|
|
} else {
|
|
return this.cbs.push(cb);
|
|
}
|
|
},
|
|
|
|
sfwBoards(sfw) {
|
|
return (() => {
|
|
const result = [];
|
|
const object = this.boards || Conf['boardConfig'].boards;
|
|
for (var board in object) {
|
|
var data = object[board];
|
|
if (!!data.ws_board === sfw) {
|
|
result.push(board);
|
|
}
|
|
}
|
|
return result;
|
|
})();
|
|
},
|
|
|
|
isSFW(board) {
|
|
return !!(this.boards || Conf['boardConfig'].boards)[board]?.ws_board;
|
|
},
|
|
|
|
domain(board) {
|
|
return `boards.${BoardConfig.isSFW(board) ? '4channel' : '4chan'}.org`;
|
|
},
|
|
|
|
isArchived(board) {
|
|
// assume archive exists if no data available to prevent cleaning of archived threads
|
|
const data = (this.boards || Conf['boardConfig'].boards)[board];
|
|
return !data || data.is_archived;
|
|
},
|
|
|
|
noAudio(boardID) {
|
|
if (g.SITE.software !== 'yotsuba') { return false; }
|
|
const boards = this.boards || Conf['boardConfig'].boards;
|
|
return boards && boards[boardID] && !boards[boardID].webm_audio;
|
|
},
|
|
|
|
title(boardID) {
|
|
return (this.boards || Conf['boardConfig'].boards)?.[boardID]?.title || '';
|
|
}
|
|
};
|
|
export default BoardConfig;
|