Skip to content

Commit

Permalink
added more imports, and now the circular dependencies are haunting me
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxedoTako committed Feb 27, 2023
1 parent 9d763e8 commit 924eda8
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 55 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ The 4chan XT project is a migration of 4chan X from coffeescript to TypeScript/J

## Other notes

- A lot of files have circular dependencies, but rollup can handle that, but for some scripts that add to the same object I had to merge them, like Posting/QR and site/SW.yotsuba.js
- A lot of files have circular dependencies, but rollup can handle that
- but for some scripts that add to the same object I had to merge them, like Posting/QR and site/SW.yotsuba.js
- sometimes something might not be initialized before use
- tsconfig.json has `"checkJs": true,`, and a lot of js files report type errors when opened because of unknown properties on objects and reassigning variables with different types. These errors don't block the bundle at this moment.
- old files in the builds directory stay as reference until the new builds are functional, new files go in the builds/test directory
- old build scripts are also kept around for reference until the new build output is fully functional
Expand Down
3 changes: 1 addition & 2 deletions src/Filtering/Recursive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Callbacks from "../classes/Callbacks";
import { g } from "../globals/globals";
import $ from "../platform/$";

/*
* decaffeinate suggestions:
Expand All @@ -9,7 +8,7 @@ import $ from "../platform/$";
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const Recursive = {
recursives: $.dict(),
recursives: Object.create(null),
init() {
if (!['index', 'thread'].includes(g.VIEW)) { return; }
return Callbacks.Post.push({
Expand Down
24 changes: 12 additions & 12 deletions src/General/Index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* DS207: Consider shorter variations of null checks
Expand Down Expand Up @@ -30,6 +29,7 @@ import Menu from '../Menu/Menu';
import NavLinksPage from './Index/NavLinks.html';
import PageListPage from './Index/PageList.html';
import BoardConfig from './BoardConfig';
import Get from './Get';

const Index = {
showHiddenThreads: false,
Expand Down Expand Up @@ -316,7 +316,7 @@ const Index = {

cycleSortType() {
let i;
const types = [...Array.from(Index.selectSort.options)].filter(option => !option.disabled);
const types = Index.selectSort.options.filter(option => !option.disabled);
for (i = 0; i < types.length; i++) {
var type = types[i];
if (type.selected) { break; }
Expand Down Expand Up @@ -378,7 +378,7 @@ const Index = {
},

lastLongThresholds() {
const i = [...Array.from(this.parentNode.children)].indexOf(this);
const i = Array.from(this.parentNode.children).indexOf(this);
const value = +this.value;
if (!Number.isFinite(value)) {
this.value = Index.lastLongThresholds[i];
Expand Down Expand Up @@ -692,14 +692,14 @@ const Index = {
const pagesRoot = $('.pages', Index.pagelist);

// Previous/Next buttons
const prev = pagesRoot.previousSibling.firstChild;
const next = pagesRoot.nextSibling.firstChild;
const prev = pagesRoot.previousElementSibling.firstElementChild;
const next = pagesRoot.nextElementSibling.firstElementChild;
let href = Math.max(pageNum - 1, 1);
prev.href = href === 1 ? './' : href;
prev.firstChild.disabled = href === pageNum;
prev.firstElementChild.disabled = href === pageNum;
href = Math.min(pageNum + 1, maxPageNum);
next.href = href === 1 ? './' : href;
next.firstChild.disabled = href === pageNum;
next.firstElementChild.disabled = href === pageNum;

// <strong> current page
if (strong = $('strong', pagesRoot)) {
Expand Down Expand Up @@ -1065,15 +1065,15 @@ const Index = {
}
return [...Array.from(liveThreadData)].sort((a, b) => lastlongD[b.no] - lastlongD[a.no]).map(post => post.no);
case 'bump': return liveThreadIDs;
case 'birth': return [...Array.from(liveThreadIDs)].sort((a, b) => b - a);
case 'replycount': return [...Array.from(liveThreadData)].sort((a, b) => b.replies - a.replies).map(post => post.no);
case 'filecount': return [...Array.from(liveThreadData)].sort((a, b) => b.images - a.images).map(post => post.no);
case 'activity': return [...Array.from(liveThreadData)].sort((a, b) => ((tmp_time - a.time) / (a.replies + 1)) - ((tmp_time - b.time) / (b.replies + 1))).map(post => post.no);
case 'birth': return Array.from(liveThreadIDs).sort((a, b) => b - a);
case 'replycount': return Array.from(liveThreadData).sort((a, b) => b.replies - a.replies).map(post => post.no);
case 'filecount': return Array.from(liveThreadData).sort((a, b) => b.images - a.images).map(post => post.no);
case 'activity': return Array.from(liveThreadData).sort((a, b) => ((tmp_time - a.time) / (a.replies + 1)) - ((tmp_time - b.time) / (b.replies + 1))).map(post => post.no);
default: return liveThreadIDs;
}
})();
if (/-rev$/.test(Index.currentSort)) {
Index.sortedThreadIDs = [...Array.from(Index.sortedThreadIDs)].reverse();
Index.sortedThreadIDs = Array.from(Index.sortedThreadIDs).reverse();
}
if (Index.search && (threadIDs = Index.querySearch(Index.search))) {
Index.sortedThreadIDs = threadIDs;
Expand Down
1 change: 1 addition & 0 deletions src/Images/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Volume from './Volume';
import Header from '../General/Header';
import { Conf, g } from '../globals/globals';
import UI from '../General/UI';
import Get from '../General/Get';

const Gallery = {
init() {
Expand Down
2 changes: 1 addition & 1 deletion src/Miscellaneous/RelativeDates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import $ from "../platform/$";
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const RelativeDates = {
INTERVAL: $.MINUTE / 2,
INTERVAL: 30000,

init() {
if (
Expand Down
1 change: 1 addition & 0 deletions src/Posting/Captcha.t.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { g } from "../globals/globals";
import $ from "../platform/$";
import QR from "./QR";

Expand Down
2 changes: 2 additions & 0 deletions src/classes/Callbacks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Main from "../main/Main";

export default class Callbacks {
static Post = new Callbacks('Post');
static Thread = new Callbacks('Thread');
Expand Down
2 changes: 2 additions & 0 deletions src/classes/CatalogThread.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from "../platform/$";

export default class CatalogThread {
toString() { return this.ID; }

Expand Down
5 changes: 5 additions & 0 deletions src/classes/CatalogThreadNative.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { g } from "../globals/globals";
import $ from "../platform/$";
import Board from "./Board";
import Thread from "./Thread";

export default class CatalogThreadNative {
toString() { return this.ID; }

Expand Down
10 changes: 8 additions & 2 deletions src/classes/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import Callbacks from "./Callbacks";
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class Post {
// \u00A0 is nbsp
static deadMark = $.el('span', { textContent: '\u00A0(Dead)', className: 'qmark-dead' });
// because of a circular dependency $ might not be initialized, so we can't use $.el
static deadMark = (() => {
const el = document.createElement('span');
// \u00A0 is nbsp
el.textContent = '\u00A0(Dead)';
el.className = 'qmark-dead';
return el;
})();

toString() { return this.ID; }

Expand Down
2 changes: 1 addition & 1 deletion src/platform/$.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ $.ajax = (function () {
return req;
};
}
});
})();

// Status Code 304: Not modified
// With the `If-Modified-Since` header we only receive the HTTP headers and no body for 304 responses.
Expand Down
50 changes: 23 additions & 27 deletions src/platform/CrossOrigin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import QR from "../Posting/QR";
import $ from "./$";

/*
Expand All @@ -8,9 +9,9 @@ import $ from "./$";
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
let eventPageRequest;
if (globalThis.chrome?.extension) {
let Request;
const eventPageRequest = (function () {
eventPageRequest = (function () {
const callbacks = [];
chrome.runtime.onMessage.addListener(function (response) {
callbacks[response.id](response.data);
Expand Down Expand Up @@ -107,34 +108,29 @@ const CrossOrigin = {
});
},

Request: (Request = (function () {
Request = class Request {
static initClass() {
this.prototype.status = 0;
this.prototype.statusText = '';
this.prototype.response = null;
this.prototype.responseHeaderString = null;
}
getResponseHeader(headerName) {
if ((this.responseHeaders == null) && (this.responseHeaderString != null)) {
this.responseHeaders = $.dict();
for (var header of this.responseHeaderString.split('\r\n')) {
var i;
if ((i = header.indexOf(':')) >= 0) {
var key = header.slice(0, i).trim().toLowerCase();
var val = header.slice(i + 1).trim();
this.responseHeaders[key] = val;
}
Request: class Request {
static status = 0;
static statusText = '';
static response = null;
static responseHeaderString = null;

getResponseHeader(headerName) {
if ((this.responseHeaders == null) && (Request.responseHeaderString != null)) {
this.responseHeaders = $.dict();
for (var header of Request.responseHeaderString.split('\r\n')) {
var i;
if ((i = header.indexOf(':')) >= 0) {
var key = header.slice(0, i).trim().toLowerCase();
var val = header.slice(i + 1).trim();
this.responseHeaders[key] = val;
}
}
return this.responseHeaders?.[headerName.toLowerCase()] ?? null;
}
abort() { }
onloadend() { }
};
Request.initClass();
return Request;
})()),
return this.responseHeaders?.[headerName.toLowerCase()] ?? null;
}
abort() { }
onloadend() { }
},

// Attempts to fetch `url` using cross-origin privileges, if available.
// Interface is a subset of that of $.ajax.
Expand Down
10 changes: 4 additions & 6 deletions src/site/SW.yotsuba.Build/PostInfoHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default function generatePostInfoHtml(
output += `<input type="checkbox" name="${ID}" value="delete">`;

if (!o.isReply || boardID === "f" || subject) output += `<span class="subject">${E(subject || "")}</span>`;
output += `<span class="nameBlock${capcode ? ` capcode${capcode}` : ''}">`;
if (email) output += `<a href="mailto:${encodeURIComponent(email).replace(/%40/g, "@")}" class="useremail">`;
output += `<span class="nameBlock${capcode ? ` capcode${E(capcode)}` : ''}">`;
if (email) output += `<a href="mailto:${E(encodeURIComponent(email).replace(/%40/g, "@"))}" class="useremail">`;
output += `<span class="name ${capcode ? E(capcode) : ''}">${E(name)}</span>`;
if (tripcode) output += ` <span class="postertrip">${E(tripcode)}</span>`;
if (pass) output += ` <span title="Pass user since ${E(pass)}" class="n-pu"></span>`;
Expand All @@ -26,14 +26,14 @@ export default function generatePostInfoHtml(
output +=
` <img src="${staticPath}${capcodeLC}icon${gifIcon}" alt="${E(capcode)} Icon" title="This user is ${E(capcodeDescription)}." class="identityIcon retina">`;
}
if (!(uniqueID && !capcode)) {
if (uniqueID && !capcode) {
output +=
`<span class="posteruid id_${E(uniqueID)}">(ID: <span class="hand" title="Highlight posts by this ID">${E(uniqueID)}</span>)</span>`;
}
if (flagCode) output += ` <span title="${flag}" class="flag flag-${flagCode.toLowerCase()}"></span>`;
if (flagCodeTroll) output += ` <span title="${flag}" class="bfl bfl-${flagCodeTroll.toLowerCase()}"></span>`;
output += `</span>
<span class="dateTime" data-utc="${dateUTC}">${E(dateText)}</span>
<span class="dateTime" data-utc="${E(dateUTC)}">${E(dateText)}</span>
<span class="postNum${!(boardID === "f" && !o.isReply) ? ' desktop' : ''}">
<a href="${postLink}" title="Link to this post">No.</a>
<a href="${quoteLink}" title="Reply to this post">${ID}</a>`;
Expand All @@ -50,8 +50,6 @@ export default function generatePostInfoHtml(
if (o.isArchived) {
output +=
` <img src="${staticPath}archived${gifIcon}" alt="Archived" title="Archived" class="archivedIcon retina">`;
} else {
output += ` <img src="${staticPath}archived${gifIcon}" alt="Archived" title="Archived" class="archivedIcon retina">`;
}
if (!o.isReply && g.VIEW === "index") output += ` &nbsp; <span>[<a href="/${boardID}/thread/${threadID}" class="replylink">Reply</a>]</span>`;
output += '</span></div>';
Expand Down
7 changes: 4 additions & 3 deletions src/site/SW.yotsuba.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PostSuccessful from "../Posting/PostSuccessful";
import ImageHost from "../Images/ImageHost";
import { g, Conf } from "../globals/globals";
import BoardConfig from "../General/BoardConfig";
import CSS from "../css/CSS";

import generatePostInfoHtml from './SW.yotsuba.Build/PostInfoHtml';
import generateFileHtml from "./SW.yotsuba.Build/FileHtml";
Expand Down Expand Up @@ -366,7 +367,7 @@ $\
Build: {
staticPath: '//s.4cdn.org/image/',
gifIcon: window.devicePixelRatio >= 2 ? '@2x.gif' : '.gif',
spoilerRange: $.dict(),
spoilerRange: Object.create(null),

shortFilename(filename) {
const ext = filename.match(/\.?[^\.]*$/)[0];
Expand Down Expand Up @@ -443,7 +444,7 @@ $\
}
o.files = [];
if (data.ext) {
o.file = SWYotsuba.this.parseJSONFile(data, { siteID, boardID });
o.file = this.parseJSONFile(data, { siteID, boardID });
o.files.push(o.file);
}
// Temporary JSON properties for events such as April 1 / Halloween
Expand Down Expand Up @@ -511,7 +512,7 @@ $\
post(o) {
const { ID, threadID, boardID, file } = o;
const { subject, email, name, tripcode, capcode, pass, uniqueID, flagCode, flagCodeTroll, flag, dateUTC, dateText, commentHTML } = o.info;
const { staticPath, gifIcon } = Build;
const { staticPath, gifIcon } = this;

/* Post Info */

Expand Down
2 changes: 2 additions & 0 deletions src/types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const cloneInto: Function;
declare const XPCNativeWrapper: any;

0 comments on commit 924eda8

Please sign in to comment.