Skip to content

Commit

Permalink
Unpacked extension
Browse files Browse the repository at this point in the history
more fixes
  • Loading branch information
TuxedoTako committed Mar 3, 2023
1 parent fee484d commit e1d01d0
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 150 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ The 4chan XT project is a migration of 4chan X from coffeescript to TypeScript/J
- build script
- [x] userscript
- [ ] .crx extension
- [ ] beta
- [ ] noupdate
- [x] crx directory that can be loaded as an unpacked extension is created
- [x] beta
- [x] noupdate
- [ ] run and debug
- [ ] port updates made to 4chan-X made since this was forked

Expand Down
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"yotsuba"
],
"ignoreWords": [
"noupdate",
"tyme",
"werk"
],
Expand All @@ -48,4 +49,4 @@
"flagWords": [
"hte"
]
}
}
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"description": "4chan XT is a script that adds various features to anonymous imageboards.",
"meta": {
"name": "4chan XT",
"path": "4chan-xt",
"fork": "ccd0",
"page": "https://www.4chan-x.net/",
"downloads": "https://www.4chan-x.net/builds/",
"path": "4chan-XT",
"fork": "TuxedoTako",
"page": "https://github.com/TuxedoTako/4chan-xt",
"downloads": "https://github.com/TuxedoTako/4chan-xt/releases",
"oldVersions": "https://raw.githubusercontent.com/ccd0/4chan-x/",
"faq": "https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions",
"captchaFAQ": "https://github.com/ccd0/4chan-x/wiki/Captcha-FAQ",
"cssGuide": "https://github.com/ccd0/4chan-x/wiki/Styling-Guide",
"license": "https://github.com/ccd0/4chan-x/blob/master/LICENSE",
"changelog": "https://github.com/ccd0/4chan-x/blob/master/CHANGELOG.md",
"issues": "https://github.com/ccd0/4chan-x/issues",
"newIssue": "https://github.com/ccd0/4chan-x/issues",
"faq": "https://github.com/TuxedoTako/wiki/Frequently-Asked-Questions",
"captchaFAQ": "https://github.com/TuxedoTako/wiki/Captcha-FAQ",
"cssGuide": "https://github.com/TuxedoTako/wiki/Styling-Guide",
"license": "https://github.com/TuxedoTako/blob/master/LICENSE",
"changelog": "https://github.com/TuxedoTako/blob/master/CHANGELOG.md",
"issues": "https://github.com/TuxedoTako/issues",
"newIssue": "https://github.com/TuxedoTako/issues",
"newIssueMaxLength": 8181,
"alternatives": "https://www.4chan-x.net/4chan_alternatives.html",
"appid": "lacclbnghgdicfifcamcmcnilckjamag",
Expand Down Expand Up @@ -95,15 +95,16 @@
"GM.xmlHttpRequest"
],
"min": {
"chrome": "33",
"firefox": "26",
"chrome": "80",
"firefox": "74",
"greasemonkey": "1.14"
}
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@rollup/pluginutils": "^5.0.2",
"@types/chrome": "^0.0.217",
"@types/node": "^18.14.5",
"@violentmonkey/types": "^0.1.5",
"chrome-webstore-upload": "^0.4.4",
"esprima": "^4.0.1",
Expand Down Expand Up @@ -134,10 +135,12 @@
"license": "MIT",
"readmeFilename": "README.md",
"engines": {
"node": ">=14.0.0"
"node": ">=16.0.0"
},
"type": "module",
"scripts": {
"build": "node ./tools/rollup"
"build": "node ./tools/rollup",
"build:beta": "node ./tools/rollup -beta",
"build:noupdate": "node ./tools/rollup -noupdate"
}
}
1 change: 0 additions & 1 deletion src/Archive/Redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import archives from './archives.js';
*/

const Redirect = {
// TODO check
archives,

init() {
Expand Down
10 changes: 7 additions & 3 deletions src/General/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BoardConfig from "./BoardConfig";
import Get from "./Get";
import Settings from "./Settings";
import UI from "./UI";
import meta from '../../package.json';

/*
* decaffeinate suggestions:
Expand Down Expand Up @@ -670,9 +671,12 @@ var Header = {
break;
}

// TODO meta
const el = $.el('span',
{ innerHTML: "meta.name needs your permission to show desktop notifications. [<a href=\"meta.faq#why-is-4chan-x-asking-for-permission-to-show-desktop-notifications\" target=\"_blank\">FAQ</a>]<br><button>Authorize</button> or <button>Disable</button>" });
const el = $.el('span', {
innerHTML:
`${meta.name} needs your permission to show desktop notifications. ` +
`[<a href=\"${meta.faq}#why-is-4chan-x-asking-for-permission-to-show-desktop-notifications\" target=\"_blank\">FAQ</a>]` +
`<br><button>Authorize</button> or <button>Disable</button>`
});
const [authorize, disable] = Array.from($$('button', el));
$.on(authorize, 'click', () => Notification.requestPermission(function (status) {
Header.areNotificationsEnabled = status === 'granted';
Expand Down
10 changes: 6 additions & 4 deletions src/General/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,12 @@ const Index = {
// Optional notification for manual refreshes
if (!Index.notice) { Index.notice = new Notice('info', 'Refreshing index...'); }
if (!Index.nTimeout) {
Index.nTimeout = setTimeout(() => // TODO check if notice exists
Index.notice.el.lastElementChild.textContent += ' (disable JSON Index if this takes too long)'
, 3 * SECOND);
}
Index.nTimeout = setTimeout(() => {
if (Index.notice) {
Index.notice.el.lastElementChild.textContent += ' (disable JSON Index if this takes too long)';
}
}, 3 * SECOND);
};
} else {
// Also display notice if Index Refresh is taking too long
if (!Index.nTimeout) {
Expand Down
6 changes: 4 additions & 2 deletions src/General/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import meta from '../../package.json';
import { Conf, E, g } from '../globals/globals';
import Header from './Header';
import h, { hFragment } from '../globals/jsx';
import { dict } from '../platform/helpers';
import { dict, platform } from '../platform/helpers';

const Settings = {
dialog: undefined as HTMLDivElement | undefined,

init() {
// 4chan X settings link
const link = $.el('a', {
Expand Down Expand Up @@ -247,7 +249,7 @@ Enable it on boards.${location.hostname.split('.')[1]}.org in your browser's pri
if ($.perProtocolSettings || (location.protocol !== 'https:')) {
$('div[data-name="Redirect to HTTPS"]', section).hidden = true;
}
if ($.platform !== 'crx') {
if (platform !== 'crx') {
$('div[data-name="Work around CORB Bug"]', section).hidden = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Miscellaneous/Tinyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Tinyboard = {
let { boardID, threadID } = document.currentScript.dataset;
threadID = +threadID;
const form = document.querySelector('form[name="post"]');
window.$(document).ajaxComplete(function (event, request, settings) {
$(document).ajaxComplete(function (event, request, settings) {
let postID;
if (settings.url !== form.action) { return; }
if (!(postID = +request.responseJSON?.id)) { return; }
Expand Down
1 change: 0 additions & 1 deletion src/Monitoring/Favicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const Favicon = {

SFW: '//s.4cdn.org/image/favicon-ws.ico',
NSFW: '//s.4cdn.org/image/favicon.ico',
// TODO
dead: `data:image/gif;base64,${dead}`,
logo: `data:image/png;base64,${empty}`,
};
Expand Down
4 changes: 2 additions & 2 deletions src/Posting/QR.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ var QR = {
post.unlock();

if (err = this.response?.getElementById('errmsg')) { // error!
// TODO: check if exists
$('a', err).target = '_blank'; // duplicate image link
const el = $('a', err);
if (el) el.target = '_blank'; // duplicate image link
} else if (connErr = (!this.response || (this.response.title !== 'Post successful!'))) {
err = QR.connectionError();
if ((QR.captcha === Captcha.v2) && QR.currentCaptcha) { Captcha.cache.save(QR.currentCaptcha); }
Expand Down
3 changes: 3 additions & 0 deletions src/classes/Connection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import $ from "../platform/$";
import { g } from "../globals/globals";

export default class Connection {
constructor(target, origin, cb = {}) {
this.send = this.send.bind(this);
Expand Down
13 changes: 5 additions & 8 deletions src/classes/SimpleDict.js → src/classes/SimpleDict.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import $ from "../platform/$";

/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class SimpleDict {
export default class SimpleDict<T> {
keys: string[]

constructor() {
this.keys = [];
}

push(key, data) {
push(key, data: T) {
key = `${key}`;
if (!this[key]) { this.keys.push(key); }
return this[key] = data;
Expand All @@ -29,7 +26,7 @@ export default class SimpleDict {
for (var key of this.keys) fn(this[key]);
}

get(key) {
get(key): T {
if (key === 'keys') {
return undefined;
} else {
Expand Down
24 changes: 10 additions & 14 deletions src/globals/globals.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import version from "../../version.json";
import meta from "../../package.json";
import type SimpleDict from "../classes/SimpleDict";
import type Post from "../classes/Post";
import type Thread from "../classes/Thread";
import type SWTinyboard from "../site/SW.tinyboard";

// interfaces might be incomplete

export interface Site {
ID: string,
siteID: string,
properties: {
software: string,
},
software: string,
}

export interface BoardConfig {
board: string
bump_limit: number
Expand Down Expand Up @@ -41,18 +34,21 @@ export interface Board {
boardID: string,
siteID: string,
config: BoardConfig,
posts: SimpleDict,
threads: SimpleDict,
posts: SimpleDict<Post>,
threads: SimpleDict<Thread>,
}

export const Conf = Object.create(null);

export const g: {
VERSION: string,
NAMESPACE: string,
sites: Site[],
sites: (typeof SWTinyboard)[],
boards: Board[],
SITE?: Site,
posts?: SimpleDict<Post>,
threads?: SimpleDict<Thread>
THREADID?: number,
SITE?: typeof SWTinyboard,
BOARD?: Board,
VIEW?: string,
} = {
Expand Down
14 changes: 6 additions & 8 deletions src/main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import Menu from "../Menu/Menu";
import BoardConfig from "../General/BoardConfig";
import CaptchaReplace from "../Posting/Captcha.replace";
import Get from "../General/Get";
import { dict } from "../platform/helpers";
import { dict, platform } from "../platform/helpers";

/*
* decaffeinate suggestions:
Expand All @@ -106,7 +106,7 @@ const Main = {
let key;
try {
let w = window;
if ($.platform === 'crx') { w = (w.wrappedJSObject || w); }
if (platform === 'crx') { w = (w.wrappedJSObject || w); }
if (`${meta.name} antidup` in w) { return; }
w[`${meta.name} antidup`] = true;
} catch (error) { }
Expand Down Expand Up @@ -256,9 +256,8 @@ const Main = {
items.previousversion = (changes.previousversion = g.VERSION);
return $.set(changes, function () {
if (items['Show Updated Notifications'] ?? true) {
// TODO meta
const el = $.el('span',
{ innerHTML: `meta.name has been updated to <a href="${meta.changelog}" target="_blank">version ${g.VERSION}</a>.` });
{ innerHTML: `${meta.name} has been updated to <a href="${meta.changelog}" target="_blank">version ${g.VERSION}</a>.` });
return new Notice('info', el, 15);
}
});
Expand Down Expand Up @@ -811,7 +810,7 @@ const Main = {
{ textContent: `${data.error.name || 'Error'}: ${data.error.message || 'see console for details'}` });
const lines = data.error.stack?.match(/\d+(?=:\d+\)?$)/mg)?.join().replace(/^/, ' at ') || '';
const context = $.el('div',
{ textContent: `(${meta.name} ${meta.fork} v${g.VERSION} ${$.platform} on ${$.engine}${lines})` });
{ textContent: `(${meta.name} ${meta.fork} v${g.VERSION} ${platform} on ${$.engine}${lines})` });
return [message, error, context];
},

Expand All @@ -822,20 +821,19 @@ const Main = {
if (errors.length > 1) { title += ` (+${errors.length - 1} other errors)`; }
let details = '';
const addDetails = function (text) {
// TODO meta
if (encodeURIComponent(title + details + text + '\n').length <= "meta.newIssueMaxLength - meta.newIssue.replace(/%(title|details)/, '')".length) {
return details += text + '\n';
}
};
addDetails(`\
[Please describe the steps needed to reproduce this error.]
Script: ${meta.name} ${meta.fork} v${g.VERSION} ${$.platform}
Script: ${meta.name} ${meta.fork} v${g.VERSION} ${platform}
URL: ${location.href}
User agent: ${navigator.userAgent}\
`
);
if (($.platform === 'userscript') && (info = (() => {
if ((platform === 'userscript') && (info = (() => {
if (typeof GM !== 'undefined' && GM !== null) { return GM.info; } else {
if (typeof GM_info !== 'undefined' && GM_info !== null) { return GM_info; }
}
Expand Down
36 changes: 0 additions & 36 deletions src/meta/manifest.json

This file was deleted.

Loading

0 comments on commit e1d01d0

Please sign in to comment.